-
-
Notifications
You must be signed in to change notification settings - Fork 16.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem converting Yolov5n .pt to .tflite #13445
Comments
👋 Hello @juliermeSilva, thank you for your interest in YOLOv5 🚀! This is an automated response to help guide you, and an Ultralytics engineer will assist you further shortly. If this is a 🐛 Bug Report, it would be helpful to provide a minimum reproducible example (MRE). In this case, please ensure that any custom code, dataset details, or additional information impacting the For general issues with custom training and inference ❓, please make sure:
Regarding your Python environment:
If you're utilizing a custom inference pipeline (like Lastly, if the Let us know if further clarification is needed, and thank you for sharing your detailed report! 😊 |
Hello everyone.
The result remained the same as reported in previous posts, that is, only the first class was detected by the models. The others were ignored. I don't know why this is happening when I use the tflite_runtime library to perform inferences. I then used the Ultralytics library to load the yolov5n-obr.tflite model and test inferences, describing the results in the terminal. Note that the model behaves as expected, making correct inferences for all test images. Code used:
Example result (for img1.jpg):
I hope this information helps in the process of figuring out why the tflite_runtime library is not able to correctly infer all the classes in which the model was trained. I am available if any further information is needed to find the solution to this problem. |
@juliermeSilva thank you for your detailed testing and additional information. Based on your results, it appears the issue lies with how the Here are some potential areas to explore within the
For further diagnosis, consider logging and comparing the raw output tensors from both Let me know if you need help debugging the raw TFLite outputs! |
Hello pderrenger, I appreciate your attention and your initiative to help me solve this problem regarding the use of In these new tests, the yolov5n-obr.tflite model manipulation algorithm, using the Any help is welcome. |
Thank you for the detailed update and extensive testing. Based on your findings, it does seem that the issue lies in post-processing the TFLite model outputs using the To address this, double-check how the outputs are parsed and interpreted in your Let me know if you need further guidance! |
Hello, pderrenger. I obtain the tensor with the inference data from information in the output_details, for example, the value 476 is the reference index for the tensor containing the inference data and has the following format [1, 6, 8400]. Once you know the index for the output tensor, getting it is simple, just run this command:
The format for the output tensor is exactly as described in output_detalis:
There are 8400 columns, containing 6 rows. Each column corresponds to the 6 values inferred by the model, that is,
I have already checked the official documentation and did not notice any anomalies. I do not believe that the problem could be in the reading of the data structures. Perhaps related to some scale adjustment that I am not able to visualize (my speculation). If there is something wrong, I still cannot see it. I inserted a new test in the Kaggle notebook, this time related to reading images using the PIL library. I thought it could be something related to the input data. I also tried to simplify the code of this test as much as possible to focus on the format of the data structure. In order not to pollute this issue with huge results, I think it is better to continue maintaining large results on Kaggle. |
Thank you for sharing your findings and detailed explanation! Your discovery regarding the structure of the TFLite output tensor is correct and aligns with how YOLO models export outputs in TFLite format. The last rows of the tensor correspond to class-specific confidence scores, rather than a single "class ID" row. This difference in format compared to PyTorch outputs is a common source of confusion. It's great to see that you've resolved the issue by correctly interpreting the output tensor, and the results now match your expectations. For others encountering similar issues, referring to the TFLite model's output details (e.g., shape and structure) is essential for correctly parsing the results. If you need further assistance or have additional questions, feel free to ask. Kudos to you for the thorough debugging and sharing your solution with the community—it’s invaluable for others working on similar tasks! |
Hello everyone.
I converted a Yolov5 nano network from .pt format to .tflite format. The network only has two classes (Black Ball and Silver Ball). When using the .tflite file, the network stopped detecting Silver Ball. It only detects Black Ball. This behavior does not occur when I use the .pt format.
The code used for training is this:
My file data.yaml:
The yolov5n.pt and yolov5n.onnx formats worked perfectly on a more robust computer (e.g. a university laptop).
I now need to embed the Yolov5n network on a Raspberry Pi 3B.
I then converted the network from the .pt format to the .tflite format.
The conversion code used was this:
Validation results:
The training code and the conversion code were all run on the Kaggle platform.
Everything was going perfectly until I tried to detect silver balls.
This is my test image (img1.jpg):
This is the code I am using to perform inferences using the yolov5n-obr_float32_v2.tflite network (tflite_black_silver_test_3.py):
The resulting image from running the tflite_black_silver_test_3.py code is the one below. Note that the silver balls are not being detected, only the black ball.
Kaggle settings for conversion:
ultralytics-8.3.43
Installed dependencies:
Settings on the Raspberry PI 3B:
Python: 3.11.2
tflite-runtime 2.14.0
What could I be doing wrong?
Why does the network work perfectly in the .pt format but this problem occurs in the .tflite format?
I appreciate any help!
Originally posted by @juliermeSilva in #13444
The text was updated successfully, but these errors were encountered: