Start studying
Module 3 · Computer Vision Module contents
Module 3  ·  Card 16 / 22beginner

Non-Maximum Suppression

A detector fires many times around the same object, leaving a pile of overlapping boxes.

Non-maximum suppression keeps the most confident box and deletes its near-duplicates.

Near-duplicate means an intersection over union above a threshold, commonly around one half.

It runs per class, so an overlapping person and bicycle both survive as separate detections.

Set the threshold too low and touching objects merge; too high and every duplicate stays.

Learn in depth ↓
Module 03 · Computer Vision · 22 concepts
In depth  /  15 lines

Non-Maximum Suppression, in more detail

A detector does not politely produce one box per object.

It scores thousands of candidate regions, and every region that roughly covers a dog scores well.

The raw output is therefore a cloud of overlapping boxes stacked around each real object.

Non-maximum suppression is the cleanup step that turns that cloud back into a list of detections.

The algorithm is short: sort every box by confidence and take the highest-scoring one.

Compare it against every remaining box using intersection over union.

Any box whose overlap exceeds a threshold is treated as another vote for the same object and discarded.

Repeat with the next surviving box until nothing is left to consider.

The threshold is the only real knob, and half is the conventional starting point.

Lower it and two genuinely adjacent objects, such as people in a crowd, get merged into one.

Raise it and duplicate boxes survive, inflating the count and hurting precision.

Suppression runs independently per class, so a person standing beside a bicycle keeps both boxes.

Soft variants decay the score of an overlapping box instead of deleting it, which helps in crowds.

Because it is sequential, it was long a bottleneck in otherwise fast detectors such as YOLO.

Newer transformer detectors predict a fixed set of boxes directly and remove the step altogether.

Deep dive

What is underneath Non-Maximum Suppression

The problem it solves

A detector predicts a box at many positions, so one object produces a cluster of overlapping boxes rather than a single answer.

{(bi,si)}i=1N⟶{(bj,sj)}j=1M,M≪N\{(b_i, s_i)\}_{i=1}^{N} \longrightarrow \{(b_j, s_j)\}_{j=1}^{M}, \quad M \ll N
  • bib_i: a predicted box.
  • sis_i: its confidence score.

Non-maximum suppression keeps the most confident box in each cluster and deletes the rest, using overlap as the definition of a cluster.

IoU(bi,bmax⁡)>τ  ⟹  delete bi\mathrm{IoU}(b_i, b_{\max}) > \tau \implies \text{delete } b_i

The algorithm, in order

  1. Discard every box scoring below a confidence floor.
  2. Sort what is left by score, highest first.
  3. Take the top box and move it to the output.
  4. Delete every remaining box whose IoU with it exceeds τ\tau.
  5. Repeat from step three until nothing remains.

It runs per class, not across classes, because a person standing in front of a car should produce both boxes rather than the more confident one.

O(N2)O(N^2)

The cost is quadratic in the number of surviving boxes, which is why the confidence floor in step one matters as much for speed as for precision.

The threshold is a direct trade

τ=0.5\tau = 0.5

Low τ\tau suppresses aggressively, which removes duplicates and also removes genuinely distinct objects that happen to overlap.

High τ\tau keeps more, which preserves crowded scenes and leaves duplicate boxes on single objects.

A crowd of people is the case that breaks it. Two pedestrians standing together can overlap at 0.6, so any threshold below that erases one of them and that error is unrecoverable.

Soft suppression

si←si⋅exp⁡(−IoU(bi,bmax⁡)2σ)s_i \leftarrow s_i \cdot \exp\left( -\frac{\mathrm{IoU}(b_i, b_{\max})^2}{\sigma} \right)

Soft-NMS decays a neighbour's score in proportion to its overlap instead of deleting it outright.

A box overlapping at 0.9 is almost erased. A box overlapping at 0.55 is reduced but survives to be judged on its own merit.

That single change recovers most of the crowded-scene loss and costs one line, which is why it is the usual first fix when recall is low in dense images.

Why detectors are now built to avoid it

NMS is not differentiable, so it sits outside the model as a fixed post-processing rule that no gradient ever reaches.

It also has to run before any output can be returned, and its quadratic cost is a real share of a real time detector's latency.

LHungarian\mathcal{L}_{\mathrm{Hungarian}}

DETR and its successors remove it entirely by training with a bipartite matching loss, where each object may be claimed by exactly one prediction.

Duplicates are then penalised during training rather than deleted afterwards.

The model then emits one box per object directly, and the pipeline has one fewer threshold nobody can tune from data.

Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
What does non-maximum suppression remove from a detector's output?
Computer Vision

22 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close