Problem converting Yolov5n .pt to .tflite #13444
Replies: 5 comments
-
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
I ran new tests, now converting the Yolov5n model to the .ncnn format. In these new tests, the yolov5n-obr.tflite model manipulation algorithm, using the Any help is welcome. |
Beta Was this translation helpful? Give feedback.
-
I have been checking the model's output tensor in .tflite format. From the research I have done on the internet, in the documentation and in the examples I have found, the output tensor format does not seem strange. 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 Discussion with huge results, I think it is better to continue maintaining large results on Kaggle. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
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!
Beta Was this translation helpful? Give feedback.
All reactions