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

**URL:** <https://discuss.ai.google.dev/t/trouble-using-tensorflow-and-tflite-for-android-seeking-solution-to-dimensional-error/31798>\
**Category:** General Discussion\
**Tags:** tflite\
**Created:** [May 5, 2023, 11:50am UTC](https://discuss.ai.google.dev/t/trouble-using-tensorflow-and-tflite-for-android-seeking-solution-to-dimensional-error/31798 "2023-05-05T11:50:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sidath\_GUEYE](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/sidath_gueye/32/18158_2.png) [@Sidath\_GUEYE](https://discuss.ai.google.dev/u/Sidath_GUEYE)\
**Post date:** [May 5, 2023, 11:50am UTC](https://discuss.ai.google.dev/t/trouble-using-tensorflow-and-tflite-for-android-seeking-solution-to-dimensional-error/31798/1 "2023-05-05T11:50:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chunduriv](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@chunduriv](https://discuss.ai.google.dev/u/chunduriv)\
**Post date:** [May 11, 2023, 9:25am UTC](https://discuss.ai.google.dev/t/trouble-using-tensorflow-and-tflite-for-android-seeking-solution-to-dimensional-error/31798/3 "2023-05-11T09:25:35Z")

</div>

@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:

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

```

To:

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

```

Thank you!

---

<div class="post-metadata">

**Author:** ![Sidath\_GUEYE](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/sidath_gueye/32/18158_2.png) [@Sidath\_GUEYE](https://discuss.ai.google.dev/u/Sidath_GUEYE)\
**Post date:** [May 11, 2023, 9:28am UTC](https://discuss.ai.google.dev/t/trouble-using-tensorflow-and-tflite-for-android-seeking-solution-to-dimensional-error/31798/4 "2023-05-11T09:28:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chunduriv](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@chunduriv](https://discuss.ai.google.dev/u/chunduriv)\
**Post date:** [May 11, 2023, 9:32am UTC](https://discuss.ai.google.dev/t/trouble-using-tensorflow-and-tflite-for-android-seeking-solution-to-dimensional-error/31798/5 "2023-05-11T09:32:40Z")

</div>

@Sidath_GUEYE,

Glad it is resolved.

Thank you!
