Skip to content
mlmentorship

Anchor boxes and non-maximum suppression

Decode reference-box offsets, trace exact score-ordered suppression and separate training, inference and evaluation overlap rules.

Published · 7 min read ·Specialist ·Intermediate
Reading depth

Summary

Decode boxes from a declared reference, then suppress overlaps against selected score leaders. NMS removes predictions; it does not cluster object identities.

Problem

An anchor has center , size and predicted deltas . Decode its center and size.

Separately, three same-class detections use corner coordinates :

BoxCoordinatesScore
A[0,0,10,10]0.94
B[2,0,12,10]0.82
C[20,0,30,10]0.76

Use continuous-coordinate area and strict suppression at . Which original indices survive?

Encoding the offsets

The decoder transforms anchor box and predicted deltas into a final box:

The decoded center is and size . Exponentiation gives positive sizes mathematically; implementations still need scale/clamp, overflow and invalid-box policies.

NMS

After score filtering, process the declared class groups:

  1. Sort descending by score; break ties by original input index in this example.
  2. Keep the leader; suppress remaining boxes whose IoU with it exceeds .
  3. Repeat using only remaining candidates.
  4. Stop at exhaustion or the declared output limit.

A/B intersection is and union is . Thus : keep A, suppress B, then keep disjoint C.

Learning objective

A suppressed box cannot suppress its neighbours

A removed box cannot suppress its neighborScores order A before B before C. The equal-height boxes have adjacent IoU 1/3, above the illustrative 0.30 threshold. A removes B; removed B cannot suppress C, so A and C survive.A suppresses B; removed B cannotsuppress CABCAB outCAdjacent IoU 1/3 > 0.30. A and Csurvive.
Derivation
Three scored candidate boxes before NMS A scores 0.94, B 0.82 and C 0.76. Drawn A and B each have area 6400, with intersection 5120 and union 7680, so IoU is exactly two-thirds. C is disjoint. Drawing coordinates are x equals 20 plus eight times image x, and y equals 65 plus eight times image y. Suppression uses strict IoU greater than 0.50. CANDIDATES · sorted A → B → C A · 0.94 B · 0.82 · dashed C · 0.76 A ∩ B IoU = 2/3
Boxes retained after greedy NMS A is selected first. B is crossed out because its IoU with A is two-thirds, strictly above 0.50. Disjoint C remains and is selected next. Original coordinates and indices A and C are retained, not averaged. RESULT · keep A, suppress B, keep C A · KEEP FIRST B · SUPPRESS C · KEEP NEXT retained indices, descending score: [A, C]
A connected overlap chain can retain both endpoints For this separate chain check only, move C to image coordinates 4,0,14,10. A-B and B-C each have IoU two-thirds; A-C has IoU three-sevenths. Lines denote overlap above 0.50. Selecting A suppresses B, but C survives even though the three nodes share a connected component. Akeep Bdrop Ckeep chain check: C moves to [4,0,14,10]
keep A, suppress B at IoU 2/3, then keep C. In the separate chain, A and C also survive; NMS is not one survivor per connected component.
Check: Why does C survive the chain even though B overlaps both A and C?
Read it this way: Scores order A before B before C. The equal-height boxes have adjacent IoU 1/3, above the illustrative 0.30 threshold. A removes B; removed B cannot suppress C, so A and C survive.
Does B’s overlap with C matter after A has already removed B?

Change 1: Different Objects Overlap

New task. Crowded scenes lose true objects.

Picture and change. Compare class-aware suppression, Soft-NMS or another justified duplicate policy using recall and false positives.

Check. Overlap is not proof of one object.

Use when. Crowding causes suppression errors.

Change 2: Default Anchor Sizes Miss the Data

New task. Object scales differ from reference shapes.

Picture and change. Choose training-only shapes/matching or an anchor-free head; recheck decode and small-object coverage.

Check. Anchor-free need not mean NMS-free.

Use when. Reference geometry mismatches the task.

Failure: Three Thresholds Are Treated as One

Training matches label examples; inference NMS filters predictions; evaluation matches predictions to truth. Their IoU thresholds have different meanings and require separate decisions.

Transfer Check

Does NMS average retained and suppressed boxes?

Reasoned Answer

No. Greedy NMS retains original selected boxes. Weighted fusion is another operation.

Anchors

references can emit four offsets, class outputs and, in some heads, objectness. Then is a specific output convention, not universal. Specify logits/probabilities, score combination, coordinate transforms and area policy.

Anchor matching at training time

Illustrative matches: IoU above 0.7 positive, below 0.3 background, intermediate ignored. Specify boundaries, forced matches and ties for the actual detector. Hard-negative mining selects difficult negatives; focal loss reduces easy-example weight under its definition.

Variants

MethodChange
Soft-NMSDecay/reorder scores rather than hard removal; evaluate crowded scenes
Class-awareSeparate classes; shared-object/category policy still matters
Weighted fusionCombine coordinates under explicit ensemble/grouping assumptions

Naive pairwise NMS costs worst-case; sorting/top-K costs are separate. Lower thresholds suppress more against a fixed leader, not necessarily fewer total greedy survivors. For a separate counterexample, use descending scores A, B, C, D:

BoxCoordinates
A[0,0,10,10]
B[4,0,14,10]
C[4,-3,14,7]
D[4,3,14,13]
ThresholdSurvivors
0.50A, B
0.30A, C, D

What replaced anchors and NMS

Set-prediction designs such as DETR use training-time one-to-one matching and a specified slot budget. Learned references and duplicate policies differ across versions; do not infer production prevalence or universal quality.

Common pitfalls

Define empty/invalid boxes, ties, strict inequalities, class mode, filtering and output limits before comparing implementations.

Sources