-
-
Notifications
You must be signed in to change notification settings - Fork 16.4k
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
How to read yolo11 tflite output tensor #13396
Comments
👋 Hello @francesco-clementi-92, thank you for reaching out about your YOLOv5 inquiry 🚀! We appreciate your interest and your detailed description of the issue you're facing. For your current situation working with the YOLO model outputs in a React Native environment, it can indeed be tricky to manually decode the TFLite output tensors. Since the output tensor you are referring to seems to be producing unexpected values, such as confidence scores greater than 1, this could be due to the tensor's interpretation or values being misaligned or improperly scaled. If this is a 🐛 Bug Report, could you please provide a minimum reproducible example? This will help us to understand and potentially replicate the issue. If this is related to your custom training setup or inference ❓ Question, including additional information like your model configuration, sample inputs, and any logs or errors you're encountering can be very helpful. Also, ensure you have followed best practices for dataset preparation and training. RequirementsTo ensure everything is set up correctly, please use Python>=3.8.0 with all dependencies installed. You can follow these basic steps to set up your environment: git clone the repository
cd into the directory
pip install dependencies EnvironmentsPlease verify that your environment is up-to-date and configured correctly. YOLOv5 can be run in various environments, including local machines with required packages, or cloud-based solutions where everything is pre-configured. StatusEnsure that you have the latest updates from the repository, and if you need more assistance, our community and contributors are here to help! Lastly, we're excited about our latest development, YOLOv8, which might bring significant improvements and added features to your workflow, so consider exploring it as well! This is an automated response to guide you while an Ultralytics engineer will also assist soon. Feel free to continue providing any additional information that might help us assist you better. 😊 |
Just to give an example, these are the first values of the output: |
@francesco-clementi-92 it looks like the output values you're seeing might be due to incorrect scaling or normalization. Ensure that your model's output is being interpreted correctly, particularly the confidence scores, which should be between 0 and 1. You might need to apply a sigmoid function to the confidence values if they aren't already scaled. If the issue persists, please verify with the latest version of the YOLOv5 package. |
@pderrenger the biggest problem is that this is the raw output of the model without any post processing:
react-native-fast-tflite seems to use c++ to run tensorflow and the output is a onedimensional array. If I use ultralytics package to run the same model it works really well, so I'm having an hard time understanding how to decode the output. It's a yolo11n trained on a custom dataset exported with: Any idea? |
It seems like the issue might be related to the lack of post-processing on the raw model output. YOLO models typically require non-max suppression (NMS) to filter out overlapping boxes and extract meaningful detections. Since you're using a custom setup, you might need to implement NMS manually in your React Native environment. If the issue persists, try verifying with the latest version of the YOLOv5 package to ensure compatibility. |
Apply manually NMS is not a problem, but the first step is to understand the output structure |
To understand the output structure, you should interpret the output tensor as a series of detection candidates, each consisting of bounding box coordinates and confidence scores. Typically, the format is |
I can try to reshape the array, but I think that looping the one-dimensional array with
Should be the same as reshaping the array, or am I missing something? Also if you can notice from the output, the values are incremental, is it normal? In the meantime thanks for your time :) |
Looping through the array as you've shown is correct for extracting the values, but ensure you're interpreting them correctly. The incremental values might indicate an issue with the model's output or input preprocessing. Verify your input data is correctly normalized and matches the model's expected input format. |
Hi Francesco, |
Hi, to convert the raw YOLO output into a usable format, you should first reshape or loop through the tensor to extract |
Hello! I'm facing the same issues. I tried processing the raw output of the tflite model as you described but even with covered camera sensor I get a lot of confidence scores above 0.5 and even higher than 1. I use exactly the same setup as Francesco. If I run the model in Python it works fine and also the React Native environment works well with another tflite model. |
Yolo11 didn't work for me at all. I ended up using yolo5 with int8 quantization and convert the raw output on android. This is the code I use to perform inference on a frame processor:
The code is still ongoing and needs to be optimized |
Thank you for sharing your detailed workflow! It seems like you’ve got a well-structured approach to handling YOLOv5 with INT8 quantization and processing the output manually in Android. For those looking to decode YOLO TFLite outputs, your implementation provides a great starting point. As you've highlighted, applying quantization scales and handling post-processing steps (e.g., NMS) are critical. If you encounter any specific issues or optimizations around TensorFlow Lite, feel free to consult Ultralytics documentation or discuss here. Great work adapting the model to your needs—credit to the community and Ultralytics for enabling versatile solutions! |
I managed the solve the issue. Since we have this model output: float32[1,5,2100] this method will not work: for (let i = 0; i < numDetections; i++) { |
Thank you for sharing your solution! You're absolutely correct—when the output format is |
This explain also why the values are incremental! Thanks, makes definitely sense! |
Thank you for sharing your findings and implementation! Your explanation about handling the transposed output structure of |
Search before asking
Question
Hello, I read every online post on how to decode yolo tflite output tensor data.
My current setup is react-native + react-native-vision-camera + vision-camera-resize-plugin + react-native-fast-tflite.
I have done the training of a yolo11n models on a custom dataset and generated first an int8 with nms tflite model, then only an int8, then a simple tflite, but with each one of them my life is getting harder and harder. I cannot use ultralytics on javascript so I need to decode manually the output.
Currenlty I'm trying to run my model which as:
input: tensor: float32[1,320,320,3]
output: tensor: float32[1,5,2100]
So no quantization applied.
Resizing the frame is as easy as doing:
Then I run the tflite model:
const outputTensor = model.runSync([data]);
Now the hardest part.
My model has only one class.
From the output, I understand that there is one input batch (1), 5 detection attributes
[x, y, width, height, confidence]
and 2100 detection candidates.I don't know why, but it seems that the output is a one dimensional array.
If I only focus on the confidence with this code:
I get confidence score bigger than 1, so it's not possible.
Any help would be appreciated :)
Additional
No response
The text was updated successfully, but these errors were encountered: