non-maximum suppression
After a detector runs, a single real object usually triggers many overlapping boxes — neighboring anchors and grid cells all fire on the same dog. Non-maximum suppression is the cleanup step that collapses each cluster of near-duplicate boxes down to one. The intuition is a simple committee rule: among boxes that clearly describe the same thing, keep the most confident one and discard the rest.
The classic greedy algorithm, run per class: sort all boxes by confidence; take the top box and accept it; remove every remaining box whose IoU with that accepted box exceeds a threshold (commonly 0.5); repeat on what's left until no boxes remain. The accepted boxes are the final detections. The IoU threshold is the key knob — too high and two genuinely different but close objects both survive (false positives); too low and a real second object gets erased (missed detection).
Greedy NMS has a known failure: in crowds, two distinct objects can legitimately overlap a lot, and hard suppression deletes one of them. Soft-NMS addresses this by, instead of deleting overlapping boxes, decaying their scores in proportion to overlap, so a strongly-overlapping neighbor is demoted but can still survive if it was very confident. Other variants include weighted box fusion (averaging overlapping boxes) and class-agnostic NMS (suppressing across classes when a region can only be one object).
NMS is a non-differentiable, hand-built post-processing step with its own threshold to tune, and it runs after the network rather than being learned. This is philosophically unsatisfying and a real bottleneck in dense scenes — which is precisely why DETR and other set-prediction detectors are celebrated for removing NMS entirely: they train with a bipartite matching loss that forces each object to be claimed by exactly one prediction, so duplicates never arise.
Three 'dog' boxes with scores 0.95, 0.90, 0.40 all overlap (pairwise IoU > 0.6). Greedy NMS keeps 0.95, then drops 0.90 and 0.40 because each overlaps the 0.95 box above threshold — final output: one box.
NMS is per-class by default: a box labeled 'person' never suppresses a box labeled 'car', even if they overlap heavily, because both labels can be correct for overlapping regions (a person inside a car). Use class-agnostic NMS only when one region truly cannot host two classes.