Anchor boxes

Anchor boxes are a fixed set of reference boxes of chosen sizes and aspect ratios, tiled over the image, that an anchor-based detector refines: for each anchor it predicts an offset to the nearest object and a class score instead of drawing a box from scratch.

Tasks and training

How an anchor-based detector uses them

  1. At every cell of a feature map, place k anchors, for example three sizes times three aspect ratios.
  2. During training, match each anchor to ground-truth boxes by IoU: anchors above an upper threshold become positives, those below a lower one become background.
  3. The network learns to predict, for each positive anchor, the offsets that turn it into the ground-truth box.
  4. At inference, decode the offsets into boxes, drop low scores and run non-maximum suppression.
tx = (x − xa) / wa ty = (y − ya) / hatw = log(w / wa) th = log(h / ha)
x, y, w, h are the centre and size of the target box; xa, ya, wa, ha those of the anchor. This is the parameterization of Faster R-CNN; other detectors vary it.

Anchor-free detectors

Later designs drop the predefined boxes. FCOS and CenterNet predict a box directly from points on the feature map, and the README of the Supervisely YOLOv8 app notes that, unlike YOLOv5, YOLOv8 uses an anchor-free head. Transformer detectors replace anchors with learned object queries. Fewer hand-set sizes means fewer settings to tune for a new dataset.

Pitfalls

  • Anchor shapes that do not fit the data. Very long, thin or tiny objects match no anchor well, so few positives are assigned and recall drops.
  • Changing the input resolution, which changes how large objects are relative to the anchors the model was tuned for.
  • Reading low recall on small objects as a labeling problem when the anchor sizes are the cause.

Comparing both kinds in Supervisely

The MMDetection 3.0 training app covers anchor-based architectures such as Faster R-CNN and RetinaNet alongside anchor-free ones such as FCOS and CenterNet. Training two of them on the same project and opening a side-by-side report on the model evaluation page shows which suits your object shapes.

Frequently asked questions.

What are anchor boxes in object detection?

Predefined boxes of several sizes and aspect ratios placed across the image; the detector predicts offsets from them and a class for each. Faster R-CNN and YOLOv5 use anchors.

What is an anchor-free detector?

A detector that predicts boxes directly, for example from object centers, without predefined anchors. YOLOv8 and later YOLO versions and the DETR family, such as RT-DETR, are anchor-free.