Skip to content
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

BUGFIX: Adjust IOU threshold to compute ConfusionMatrix in validation step of YOLO detection #10254

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bavo96
Copy link

@bavo96 bavo96 commented Apr 23, 2024

1. Check for Existing Contributions: I have explored existing PRs and haven't found a solution yet.
2. Elaborate Your Changes: When running model validation, for yolo detection, I found out that the ConfusionMatrix doesn't change the IOU threshold (iou_thres=0.45). Below is my code to run the validation process:

from ultralytics import YOLO

test_conf = {
            "data": "./data.yaml",
            "project": "./yolov8",
            "name": "my_project/test",
            "split": "test",
            "verbose": True,
            "plots": True,
            "exist_ok": True,
            "save_json": True,
            "conf": 0.3,
            "iou": 0.5,
        }

model_path = "./my_project/train/weights/best.pt"  # load a trained model (for validation)
model = YOLO(model_path)
metrics = model.val(**test_conf)
print(metrics.confusion_matrix.iou_thres)

When I traceback to the val.py file, I find this:

self.confusion_matrix = ConfusionMatrix(nc=self.nc, conf=self.args.conf) 

I have added the self.arg.iou to the iou_thres in the ConfusionMatrix. I think my PR will help users adjust the iou_thres using configuration.

3. Ultralytics Contributor License Agreement (CLA): I have read the CLA Document and I sign the CLA

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Enhanced accuracy in model validation by incorporating IoU threshold in Confusion Matrix calculation.

📊 Key Changes

  • Modified the creation of the Confusion Matrix within the validation process to include an IoU (Intersection over Union) threshold as a parameter.

🎯 Purpose & Impact

  • Purpose: To refine the precision of the model's validation step by considering the IoU threshold when computing the Confusion Matrix. This aligns the evaluation metrics more closely with real-world expectations of object detection models.
  • Impact: Users can expect more accurate and meaningful insights from model validation. This change has the potential to improve how models are fine-tuned and evaluated, leading to better overall performance and reliability. 🚀

Copy link

github-actions bot commented Apr 23, 2024

CLA Assistant Lite bot All Contributors have signed the CLA. ✅

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Hello @bavo96, thank you for submitting an Ultralytics YOLOv8 🚀 PR! To allow your work to be integrated as seamlessly as possible, we advise you to:

  • ✅ Verify your PR is up-to-date with ultralytics/ultralytics main branch. If your PR is behind you can update your code by clicking the 'Update branch' button or by running git pull and git merge main locally.
  • ✅ Verify all YOLOv8 Continuous Integration (CI) checks are passing.
  • ✅ Update YOLOv8 Docs for any new or updated features.
  • ✅ Reduce changes to the absolute minimum required for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

See our Contributing Guide for details and let us know if you have any questions!

@bavo96 bavo96 changed the title Adjust IOU threshold to compute ConfusionMatrix in validation step of YOLO detection BUGFIX: Adjust IOU threshold to compute ConfusionMatrix in validation step of YOLO detection Apr 23, 2024
Copy link

codecov bot commented Apr 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.12%. Comparing base (c47eec8) to head (db70b44).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10254      +/-   ##
==========================================
- Coverage   78.95%   75.12%   -3.84%     
==========================================
  Files         121      121              
  Lines       15351    15351              
==========================================
- Hits        12120    11532     -588     
- Misses       3231     3819     +588     
Flag Coverage Δ
Benchmarks 35.79% <100.00%> (-0.24%) ⬇️
GPU 37.94% <100.00%> (+0.01%) ⬆️
Tests 70.54% <100.00%> (-4.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bavo96
Copy link
Author

bavo96 commented Apr 23, 2024

I have read the CLA Document and I sign the CLA

@bavo96
Copy link
Author

bavo96 commented Apr 23, 2024

Can you do a quick check on this @glenn-jocher?

@glenn-jocher
Copy link
Member

@bavo96 absolutely! I'll look into this right away and circle back with any findings or necessary actions. Thanks for bringing this to my attention! 😊 If any specific details or examples come up in the meantime that could help investigate, please feel free to share!

@bavo96
Copy link
Author

bavo96 commented Apr 24, 2024

Many thanks for your help @glenn-jocher I'll recheck the code for any new issues while you prepare for your next action.

@glenn-jocher
Copy link
Member

You're welcome! 😊 Glad I could assist. Please do keep me updated if you come across anything else; happy to help further. Enjoy coding and good luck with your project!

@Burhan-Q Burhan-Q added the enhancement New feature or request label Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants