ultralytics icon indicating copy to clipboard operation
ultralytics copied to clipboard

[Experiment] Adds Soft-NMS

Open Burhan-Q opened this issue 1 year ago • 3 comments

Soft-NMS option added as experiment see: https://arxiv.org/abs/1704.04503

[!CAUTION] This is experimental and not guaranteed to work, use at your own risk.

TODO

  • [ ] training performance
  • [ ] additional code optimizations/clean up
  • [ ] include argument (only if moving forward with addition)
    • NOTE Soft-NMS is currently hard-coded to be enabled for testing
  • [ ] verify functionality with all model tasks

Paper abstract

Non-maximum suppression is an integral part of the object detection pipeline. First, it sorts all detection boxes on the basis of their scores. The detection box M with the maximum score is selected and all other detection boxes with a significant overlap (using a pre-defined threshold) with M are suppressed. This process is recursively applied on the remaining boxes. As per the design of the algorithm, if an object lies within the predefined overlap threshold, it leads to a miss. To this end, we propose Soft-NMS, an algorithm which decays the detection scores of all other objects as a continuous function of their overlap with M. Hence, no object is eliminated in this process. Soft-NMS obtains consistent improvements for the coco-style mAP metric on standard datasets like PASCAL VOC 2007 (1.7% for both R-FCN and Faster-RCNN) and MS-COCO (1.3% for R-FCN and 1.1% for Faster-RCNN) by just changing the NMS algorithm without any additional hyper-parameters. Using Deformable-RFCN, Soft-NMS improves state-of-the-art in object detection from 39.8% to 40.9% with a single model. Further, the computational complexity of Soft-NMS is the same as traditional NMS and hence it can be efficiently implemented. Since Soft-NMS does not require any extra training and is simple to implement, it can be easily integrated into any object detection pipeline. Code for Soft-NMS is publicly available on GitHub https://github.com/bharatsingh430/soft-nms.

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

This PR introduces the Soft Non-Maximum Suppression (Soft-NMS) feature to the Ultralytics utility operations.

📊 Key Changes

  • Added a use_soft_nms boolean parameter to the non_max_suppression function.
  • Implemented the soft_nms function based on the Soft-NMS algorithm from the referenced research.
  • Modified the non_max_suppression function to optionally use Soft-NMS when the new parameter is set to True.
  • Updated the documentation to reflect the inclusion of Soft-NMS.

🎯 Purpose & Impact

  • Enhanced Precision: 📈 Soft-NMS can improve the accuracy of object detection by retaining more overlapping boxes with high scores compared to standard NMS.
  • Customizable Suppression: 🛠️ Offers users a choice between traditional and Soft-NMS methods, making the tool more flexible for different detection scenarios.
  • Documentation Update: 📝 Provides users with clear guidance on how to leverage the new Soft-NMS feature, ensuring they can make informed decisions about its use.

Burhan-Q avatar Sep 03 '24 23:09 Burhan-Q

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 35.99%. Comparing base (ba94983) to head (0a7bd6c).

:exclamation: There is a different number of reports uploaded between BASE (ba94983) and HEAD (0a7bd6c). Click for more details.

HEAD has 9 uploads less than BASE
Flag BASE (ba94983) HEAD (0a7bd6c)
Benchmarks 4 0
Tests 5 0
Additional details and impacted files
@@             Coverage Diff             @@
##             main   #15993       +/-   ##
===========================================
- Coverage   74.60%   35.99%   -38.61%     
===========================================
  Files         129      129               
  Lines       16997    17029       +32     
===========================================
- Hits        12680     6130     -6550     
- Misses       4317    10899     +6582     
Flag Coverage Δ
Benchmarks ?
GPU 35.99% <100.00%> (+0.10%) :arrow_up:
Tests ?

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Sep 03 '24 23:09 codecov[bot]

@Laughing-q my quick test (coco128, epochs=5) didn't seem to help at all, but I suspect that it could take longer for the benefits to come thru. Additionally there might be a better way to write this, so if you have an ideas, I'm certainly open to suggestions/ideas.

Burhan-Q avatar Sep 03 '24 23:09 Burhan-Q

Tested with COCO validation

yolo val model=yolov8s.pt data=coco.yaml

The mAP50-95 for Soft-NMS (all classes) was ~0.10 compared to normal NMS which was ~0.44. Made an attempt to reorder the output to have highest confidence at the top and ensured that the indices at the start of the soft_nms function also get reordered with other values. Not sure if this is an inherit issue with soft_nms or if it's my implementation that has the issue.

Burhan-Q avatar Sep 04 '24 23:09 Burhan-Q

👋 Hello there! We wanted to let you know that we've decided to close this pull request due to inactivity. We appreciate the effort you put into contributing to our project, but unfortunately, not all contributions are suitable or aligned with our product roadmap.

We hope you understand our decision, and please don't let it discourage you from contributing to open source projects in the future. We value all of our community members and their contributions, and we encourage you to keep exploring new projects and ways to get involved.

For additional resources and information, please see the links below:

  • Docs: https://docs.ultralytics.com
  • HUB: https://hub.ultralytics.com
  • Community: https://community.ultralytics.com

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

github-actions[bot] avatar Mar 12 '25 00:03 github-actions[bot]