Why is my application unable to find the TFLite file?

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

Hi @Richard_Neiman

Have you uploaded somewhere the project to take a look?

1 Like

Hello @George_Soloupis !

No, I do not have the project uploaded anywhere just yet, considering I’m not yet finished with it. Would it be necessary in diagnosing the problem? If it’s possible, I can provide you with any information you require.

I should probably also include the fact that this Google ML documentation is what I used as reference in developing the application. The CameraX preview is using CameraX documentation, which can be found using this.

Upload what you have done by now and provide here a link. It will be helpful. I will build and tell you.

2 Likes

Sure thing! I’ve just shared it to Github. Here’s the link; GitHub - RunMildew/ObjectDetection

It seems that the page is not available

My apologies, I’ve just now made the page public. It was on private before. Here’s the link again! GitHub - RunMildew/ObjectDetection

Hi @Richard_Neiman

You had configured all wrong the CameraX implementation. Everything else is fine and the model too.

Check the approach here

1 Like

@George_Soloupis

First off, thank you so much for taking your time out to write all this out for me. Truly, user’s like you remind us all why we stand on the shoulders of others. The application finally returns a list size.

However, I’ve also taken the time out to attempt to make it a more visual experience by adding boundingBoxes to attempt to highlight the detected object. I’ve made some changes to the activity_main.xml, the MainActivity.java, as well as the gradle files, as well as adding a new class to draw a graphic overlay above the UI.

Now, here’s where I hit my problem. I’ve encountered the most annoying error; the NullPointerException. Would you happen to know why I’m getting the following error? It’s the final obstacle in completing this application! Here’s what the error states.;

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.objectdetection, PID: 1789
java.lang.NullPointerException: Attempt to read from field ‘android.widget.FrameLayout com.example.objectdetection.databinding.ActivityMainBinding.parentlayout’ on a null object reference
at com.example.objectdetection.MainActivity.getObjectResults(MainActivity.java:165)
at com.example.objectdetection.MainActivity.lambda$null$0$MainActivity(MainActivity.java:123)
at com.example.objectdetection.-$$Lambda$MainActivity$Ncy1QJiDr5mBgoxw6Tmi2VyNiCU.onSuccess(Unknown Source:4)
at com.google.android.gms.tasks.zzn.run(com.google.android.gms:play-services-tasks@@17.2.0:4)

Also, my updated Github file has been pasted on my previously linked Github. I would paste it but it currently says that I am unable to. A community user had flagged my posts, my previous posts seem to be unavailable for the general public to read at this moment.

@George_Soloupis Thank you so much for your help so far and I apologize for any inconvenience my current predicament is causing in resolving our issue.

I am happy that you have moved forward and made great progress. Unfortunately I did not save the link of your project. It seems that the error is databinding related and not TFLite. It is a nice opportunity to use Debugger an get some experience on that.

I wish you the best!

2 Likes