"Trouble using TensorFlow and TFLite for Android: Seeking Solution to Dimensional Error"

Hello everyone,

I am currently facing a persistent issue with using TensorFlow 2.8.4 , tflite-model-maker and Python 3.8.16 to train my TFLite models. While I have been able to train my models successfully and obtain TFLite models, I have encountered an error when attempting to use them on Android. Specifically, I receive the error message "java.lang.AssertionError: Error occurred when initializing ObjectDetector: Output tensor at index 0 is expected to have 3 dimensions, found 2."
This error is related to the version of TensorFlow and TFLite that I am using.

Therefore, I am searching for a solution that will allow me to use the latest versions of TensorFlow and TFLite_Model_Maker while avoiding these version-related errors. My ultimate goal is to use TFLite models on Android without encountering these issues.

Thank you in advance for any assistance you can provide.

@Sidath_GUEYE,

There is an issue with ObjectDetector API in preserving the order of outputs.

In meanwhile can you try to change the order of the indices in the “TFLiteObjectDetectionAPIModel.java” file inside lib_interpreter.

Change the order from:

outputMap.put(0, outputLocations);
outputMap.put(1, outputClasses);
outputMap.put(2, outputScores);
outputMap.put(3, numDetections);

To:

outputMap.put(0, outputScores);
outputMap.put(1, outputLocations);
outputMap.put(2, numDetections);
outputMap.put(3, outputClasses);

Thank you!

1 Like

Thank you very much. I was able to resolve it by using the latest version of the Android app example for TensorFlow.

1 Like

@Sidath_GUEYE,

Glad it is resolved.

Thank you!

1 Like