The greedy algorithm
- Drop boxes below the confidence threshold and sort the rest by score.
- Take the highest-scoring box and add it to the output.
- Remove every remaining box of the same class whose IoU with it exceeds the NMS threshold.
- Repeat from step 2 until no boxes are left.
A worked example
Three boxes of the class "person", with the NMS threshold at 0.5:
| Box | Score | IoU with A | Result |
|---|---|---|---|
| A | 0.92 | – | Kept: highest score |
| B | 0.85 | 0.71 | Removed: a duplicate of A |
| C | 0.60 | 0.10 | Kept: a different person |
Settings that change the result
A lower IoU threshold removes more boxes; a higher one leaves more duplicates, which count as false positives and lower precision. NMS can run per class or across classes, and most implementations cap the number of boxes kept per image. The confidence threshold applied before NMS often matters as much as the NMS threshold itself.
Where NMS hurts
In crowds, two real people standing close can overlap above the threshold, and greedy NMS deletes one of them. Soft-NMS lowers the scores of overlapping boxes instead of removing them, which keeps more of those true neighbours.
Detectors that skip it
Some recent models are trained so that each object yields one box. The README of the Supervisely YOLOv8 app describes YOLOv10 as using consistent dual assignments for NMS-free training, and the RT-DETRv2 app describes the model as eliminating the need for NMS in post-processing. Other YOLO versions and anchor-based detectors still rely on it; see anchor boxes.