Notes

Non-Maximum Suppression (NMS)

Object detectors do not return one neat box per object. They usually produce many overlapping guesses around the same car, face, or defect, each with a confidence score. Non-Maximum Suppression (NMS) is the cleanup step that keeps the strongest guess and removes redundant nearby ones.

How it works

NMS is a greedy filtering procedure applied after a detector predicts bounding boxes, class labels, and confidence scores. It ranks boxes from highest to lowest confidence, accepts the current highest-scoring box, then compares it with the remaining boxes using Intersection over Union (IoU). IoU measures overlap: it is the shared area of two boxes divided by their combined covered area. Boxes whose IoU with the accepted box exceeds a chosen threshold, such as 0.5, are suppressed. The process repeats with the best remaining box.

  • A detector predicts five highly overlapping boxes for one pedestrian.
  • NMS retains the box scored 0.96.
  • It discards the other boxes if their overlap with that retained box is too large.
Why the threshold matters

A low IoU threshold removes boxes aggressively, which can accidentally erase detections of two people standing close together. A high threshold preserves more boxes, but can leave duplicate detections. Standard NMS is usually run separately for each class, so an overlapping “person” and “bicycle” box can both survive. In crowded scenes, Soft-NMS provides a useful alternative: rather than deleting overlapping boxes outright, it lowers their scores.

Where it appears in practice

NMS makes detection outputs usable: a traffic system needs one box per vehicle, a face-recognition pipeline needs one crop per face, and a production-line inspector needs one alert per flawed item. Without it, duplicate boxes inflate false positives and make downstream tracking or counting unreliable. In PyTorch, the commonly encountered function is torchvision.ops.nms, which receives boxes, scores, and an IoU threshold.

Non-Maximum Suppression (NMS) is a post-processing algorithm that removes redundant overlapping bounding-box predictions for the same object. It retains the highest-confidence detection and suppresses lower-scoring boxes whose overlap, measured by intersection over union (IoU), exceeds a threshold. NMS converts dense detector outputs into one clear prediction per object, preventing duplicate detections and improving usable detection results.

Imagine several people all pointing at the same dog in a photo, each drawing a slightly different rectangle around it. You do not want to report “dog” five times—you want the best single rectangle. Non-Maximum Suppression (NMS) is the cleanup step that does this.

An object-detection AI often finds many overlapping boxes for one object, each with a confidence score. NMS keeps the strongest, most confident box and removes nearby boxes that appear to describe the same thing. It then repeats this for other objects.

This matters because it turns a cluttered set of guesses into a clear result: one box per car, person, cat, or bicycle, making the AI’s view of the image easier to trust and use.