← Lessons

quiz vs the machine

Platinum1740

Machine Learning

Non Max Suppression

Pruning duplicate boxes down to one per object.

5 min read · advanced · beat Platinum to climb

Non Max Suppression

Detectors often fire many overlapping boxes on the same object. Non max suppression, or NMS, is the cleanup step that keeps the best box and removes its near duplicates.

The algorithm

NMS works greedily, one class at a time.

  • Sort all boxes by their confidence score, highest first.
  • Take the top box and add it to the kept list.
  • Remove every remaining box whose IoU with it exceeds a threshold.
  • Repeat with the next highest surviving box until none remain.

The IoU threshold controls how aggressive the pruning is. A high threshold keeps more boxes, while a low one removes more, risking the loss of nearby distinct objects.

Why it is needed

Without NMS a single object would be reported several times, inflating the count and confusing any downstream use. NMS turns a noisy field of candidates into a clean set of one box per object.

A softer variant

Plain NMS deletes overlapping boxes outright, which can drop a real object hidden behind another. Soft NMS instead lowers their scores in proportion to overlap, letting strong but overlapping detections survive. The choice depends on how crowded the scenes are.

Key idea

Non max suppression greedily keeps the highest scoring box and removes overlapping duplicates by IoU, leaving one box per object.

Check yourself

Answer to earn rating on the learn ladder.

1. What does NMS remove?

2. How does soft NMS differ from plain NMS?

3. What controls how aggressively NMS prunes?