I am currently working on an Android application (written in Java) using Google ML and TensorFlow. The application is centered around object detection during a live camera stream using the device camera, and uses a TensorFlow Lite model as a custom library to source file lists from. The TensorFlow Lite model specifically is called mobilenet_v1_0.75_192_quantized_1_metadata_1.tflite
which I got here. My issue is that I ran the application to see if it would print the list size, and the application launches just fine; camera preview works, app doesn’t crash. However, when looking for the list size in the logcat, only these following errors are printed in my Logcat;
2021-07-30 12:19:33.343 15790-15790/? E/objectdetectio: Unknown bits set in runtime_flags: 0x8000
2021-07-30 12:19:33.754 15790-15828/com.example.objectdetection E/Perf: Fail to get file list com.example.objectdetection
2021-07-30 12:19:33.754 15790-15828/com.example.objectdetection E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2021-07-30 12:19:33.754 15790-15828/com.example.objectdetection E/Perf: Fail to get file list com.example.objectdetection
2021-07-30 12:19:33.754 15790-15828/com.example.objectdetection E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2021-07-30 12:19:33.992 15790-15835/com.example.objectdetection E/libc: Access denied finding property "persist.vendor.camera.privapp.list"
According to my research, some results state that that the file path or root is flawed in some capacity. However, I have the .tflite
model placed within my asset folder, which leads me to wonder why exactly I’m receiving these errors and how I can work on resolving them. My Log.d("TAG", "onSuccess" + detectedObjects.size());
in my code below is supposed to print the object list size, but is clearly not. Here is my MainActivity.java;
public class MainActivity extends AppCompatActivity {
private class YourAnalyzer implements ImageAnalysis.Analyzer {
@Override
@ExperimentalGetImage
public void analyze(ImageProxy imageProxy) {
Image mediaImage = imageProxy.getImage();
if (mediaImage != null) {
InputImage image =
InputImage.fromMediaImage(mediaImage, imageProxy.getImageInfo().getRotationDegrees());
//Pass image to an ML Kit Vision API
//...
LocalModel localModel =
new LocalModel.Builder()
.setAssetFilePath("mobilenet_v1_0.75_192_quantized_1_metadata_1.tflite")
.build();
CustomObjectDetectorOptions customObjectDetectorOptions =
new CustomObjectDetectorOptions.Builder(localModel)
.setDetectorMode(CustomObjectDetectorOptions.STREAM_MODE)
.enableClassification()
.setClassificationConfidenceThreshold(0.5f)
.setMaxPerObjectLabelCount(3)
.build();
ObjectDetector objectDetector =
ObjectDetection.getClient(customObjectDetectorOptions);
objectDetector.process(image)
.addOnSuccessListener(detectedObjects -> {
Log.d("TAG", "onSuccess" + detectedObjects.size());
})
.addOnFailureListener(e -> Log.e("TAG", e.getLocalizedMessage()))
.addOnCompleteListener(result -> imageProxy.close());
}
}
}
private ListenableFuture<ProcessCameraProvider> cameraProviderFuture;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cameraProviderFuture = ProcessCameraProvider.getInstance(this);
cameraProviderFuture.addListener(() -> {
try {
ProcessCameraProvider cameraProvider = cameraProviderFuture.get();
bindPreview(cameraProvider);
} catch (ExecutionException | InterruptedException e) {
}
}, ContextCompat.getMainExecutor(this));
}
void bindPreview(@NonNull ProcessCameraProvider cameraProvider) {
PreviewView previewView = findViewById(R.id.previewView);
Preview preview = new Preview.Builder()
.build();
CameraSelector cameraSelector = new CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_BACK)
.build();
preview.setSurfaceProvider(previewView.getSurfaceProvider());
Camera camera = cameraProvider.bindToLifecycle((LifecycleOwner)this, cameraSelector, preview);
}
}
Also, just for clarification, my application name is ObjectDetection and the IDE that I’m working on is Android Studio. This is how the .tflite
model is placed within my asset folder; ObjectDetection > app > src > main > assets > ClassifierModel.tflite