ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.86k stars 16.37k forks source link

How to print/save all the IoU values for each image after running detect.py? #12444

Closed dudas-tamas closed 11 months ago

dudas-tamas commented 11 months ago

Search before asking

Question

Hi guys!

I need some help with the IoU values in YOLOv5. I got a good performer model based on statistics/metrics and I would really like to know the IoU values of each image after running detect.py. I see all the images and bboxes at runs/detect/expX but I'd like to make a statistics based on the IoUs. Can someone help and show me where I have to search for it in the code please? :)

Side info: I run detect.py like this: python /.../.../code/yolov5/detect.py --source /.../.../.../.../.../GT_test/ --line-thickness 1 --weights /.../.../.../yolov5/runs/train/exp156/weights/best.pt --max-det 1 --device 1 --imgsz 400

Thanks in advance!

Additional

No response

github-actions[bot] commented 11 months ago

👋 Hello @dudas-tamas, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics
glenn-jocher commented 11 months ago

@dudas-tamas hi there! 👋 Currently, YOLOv5 doesn't print or save IoU values after running detect.py. If you're interested in computing IoU for each detection, I recommend modifying the source code in detect.py to include this feature. You might find helpful functions for this in models/experimental and utils directories. Good luck and thank you for your support! 🚀

dudas-tamas commented 11 months ago

Understood, thanks!

glenn-jocher commented 11 months ago

@dudas-tamas you're welcome! If you have any more questions or need further assistance, feel free to ask. 👍 We're here to help!

dudas-tamas commented 11 months ago

Is there any other way in YOLOv5 to find out the IoU values of the predictions? I was thinking that then it doesn't display the IoU values of the predictions, e.g. on the test set, even if I don't use detect.py? :)

glenn-jocher commented 11 months ago

@dudas-tamas Yes, you can calculate IoU values by accessing the bounding box coordinates and confidence scores from the model outputs (inference.py) and comparing them with the ground truth annotations. The inference.py file contains the post-processing logic where predictions are produced, making it a good place to start customizing IoU computation. You might also find the Ultralytics Docs useful for insights on model outputs and how to work with them. Good luck! 📦

dudas-tamas commented 11 months ago

Cool, thanks!

dudas-tamas commented 11 months ago

I did it!

if others are also interested in the details of the IoU, it should look something like this :) This is just one of many solutions, it could certainly be made nicer, but it worked for me :)

image

glenn-jocher commented 11 months ago

@dudas-tamas great work! It's fantastic to see you've found a solution. Your code snippet can definitely be helpful for others interested in IoU details. Keep up the good work and thanks for sharing your approach with the community! 🌟

gameboy777x commented 11 months ago

@dudas-tamas hi there! I also annotated the test-set with labelimg. I wonder how can I use your code to save the data results in batches? Thank you very much