# When yolov5 is integrated into Android, the tflite task library cannot be loaded

**URL:** <https://discuss.ai.google.dev/t/when-yolov5-is-integrated-into-android-the-tflite-task-library-cannot-be-loaded/31555>\
**Category:** General Discussion\
**Tags:** android, library, tflite\
**Created:** [January 18, 2024, 3:19am UTC](https://discuss.ai.google.dev/t/when-yolov5-is-integrated-into-android-the-tflite-task-library-cannot-be-loaded/31555 "2024-01-18T03:19:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuqi\_peng](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/yuqi_peng/32/16256_2.png) [@yuqi\_peng](https://discuss.ai.google.dev/u/yuqi_peng)\
**Post date:** [January 18, 2024, 3:19am UTC](https://discuss.ai.google.dev/t/when-yolov5-is-integrated-into-android-the-tflite-task-library-cannot-be-loaded/31555/1 "2024-01-18T03:19:28Z")

</div>

java.lang.IllegalArgumentException: Error occurred when initializing ImageClassifier: Unexpected number of dimensions for output index 0: got 3D, expected either 2D (BxN with B=1) or 4D (BxHxWxN with B=1, W=1, H=1).

---

<div class="post-metadata">

**Author:** ![Tim\_Wolfe](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@Tim\_Wolfe](https://discuss.ai.google.dev/u/Tim_Wolfe)\
**Post date:** [January 27, 2024, 3:39am UTC](https://discuss.ai.google.dev/t/when-yolov5-is-integrated-into-android-the-tflite-task-library-cannot-be-loaded/31555/3 "2024-01-27T03:39:40Z")

</div>

You’re experiencing an issue where the TensorFlow Lite task library on Android is not able to load a YOLOv5 model due to an unexpected output dimension. To resolve this:

1. **Verify Model Output** : Ensure the YOLOv5 model’s output dimensions match what the TensorFlow Lite task library expects, typically either 2D or 4D.
2. **Check Model Conversion** : During the conversion of YOLOv5 to TFLite, confirm that the output tensors are correctly configured for the expected dimensions.
3. **Use Compatible TFLite Library** : Make sure you’re using a TensorFlow Lite task library version that supports the model’s output format. If not, you might need to customize the inference code.
4. **Adjust Model or Inference Code** : If necessary, modify the Android inference code to handle the 3D output tensor of YOLOv5.
5. **Inspect TFLite Model** : Use tools like Netron to examine the TFLite model and confirm its input and output formats.
6. **Error Handling** : Improve error handling in your Android code to get more detailed diagnostics.
7. **Test with Standard Model** : Try using a known, working TFLite model to ensure the issue is specific to YOLOv5.
8. **Consult Documentation and Community** : Refer to TensorFlow documentation and community forums for additional insights and common solutions.

These steps should help identify and fix the mismatch between the model output and the library’s expectations.
