Anchor-box matching

IoU, positive / negative / ignored anchors and forced best matches.

Switch to 3D

Presets

Playback

Feature map

The anchor grid: nine boxes at every cell centre.

Matching rule

Positive at or above, negative below, ignored in between.

Scene

Which toys are in the picture and where.

Actions

Layers

Model checks

The science

The model

A detector looks at a feature map with G x G cells. At every cell centre it places 9 anchor boxes: three sizes (1, 1.8 and 3 cell widths, times the base-scale slider) and three aspect ratios (w/h = 1:2, 1:1, 2:1) at equal area. The picture is the unit square; anchors are not clipped to it.

Intersection over Union

For two axis-aligned boxes, IoU(A, B) = area(A ∩ B) / area(A ∪ B), with area(A ∪ B) = area(A) + area(B) - area(A ∩ B) and area(A ∩ B) = max(0, min(x2) - max(x1)) * max(0, min(y2) - max(y1)). It is 1 for identical boxes and 0 for disjoint boxes.

The assignment rule

Every anchor is compared with every ground-truth box and keeps its best IoU. Positive if that best IoU is at least the positive threshold, negative if below the negative threshold, ignored in between (no training signal). On top of that each object's single best anchor is forced positive, otherwise a small or oddly shaped object could end up with no positive anchor at all (cyan dashed boxes). These labels are what a detector's classification and box-regression losses are computed against.

Why the grid and scale matter

A coarse grid or tiny anchors cannot reach a large object with IoU above 0.5; oversized anchors overshoot small objects. The graphs sweep the threshold and the anchor scale so you can see where recall collapses.

Simplifications

Real detectors (SSD, Faster R-CNN, RetinaNet, YOLO variants) use several feature maps, learned offsets and class scores, and their thresholds differ (RPN: 0.7 / 0.3, SSD: 0.5). Here there is one map, boxes never rotate and objects are exact bounding boxes. This is the matching step only; there is no network and no non-maximum suppression.

What to try
  1. Press "Strict rule" and watch positives vanish while the cyan forced anchors appear, then switch to "Loose rule".
  2. Drag a toy (or move object 1 with the sliders): positives hop from cell to cell as the IoU changes.
  3. Set the grid to 4 x 4 and then 8 x 8: how does the number of positives and the recall change?
  4. Press "Set anchor scale to best recall" and compare with the 0.5x and 1.6x presets in the last graph.
  5. Find a threshold where an object is reached by no anchor on its own (red bar in graph 3).
Best IoU of every anchor (colours = label)
Positives and recall against the positive threshold
IoU of the best anchor of each object
Mean best IoU and recall against anchor scale
Made with 🟠 Blender