Sub topic 3
Anchor-free detection: FCOS and CenterNet
This chapter assumes you know basic Python and NumPy, how convolutional feature maps work, and how gradient descent minimizes a loss.
Anchor-free detection: FCOS and CenterNet
Anchor-based detectors need hand-tuned reference boxes. Anchor-free detectors skip them. FCOS treats every feature-map location inside a ground-truth box as a positive sample and predicts the distances from that point to the four box edges. CenterNet predicts a heatmap of object centers, then reads width and height at each peak. Neither method needs anchor sizes or anchor-to-box IoU matching, but both still use post-processing.
Evaluating detectors with AP and mAP
A detection counts as correct when its IoU with a ground-truth box meets a threshold, commonly 0.5. For one class, sort detections by confidence and compute precision and recall at each rank. Average precision (AP) is the area under the precision-recall curve. mAP is the mean AP over classes. COCO reports mAP averaged over IoU thresholds from 0.5 to 0.95. Compare detectors only on the same dataset and protocol.
Attention as the building block of DETR
Self-attention lets each element of a sequence weigh every other element. With queries Q, keys K, and values V, the output is softmax(QKᵀ / √d) V. Cross-attention takes its queries from one set and its keys and values from another, such as image features. DETR uses self-attention over image features in its encoder and cross-attention from object queries to those features in its decoder.
One-to-one matching with the Hungarian algorithm
DETR outputs a fixed set of predictions, for example 100, and most are "no object." During training, the Hungarian algorithm pairs predictions with ground-truth objects one-to-one at the lowest total cost. Unmatched predictions are trained to output the no-object class.
import numpy as np
from scipy.optimize import linear_sum_assignment
# Rows: 3 predictions. Columns: 2 ground-truth objects.
cost = np.array([
[0.9, 0.2],
[0.1, 0.8],
[0.5, 0.6],
])
rows, cols = linear_sum_assignment(cost)
print(list(zip(rows.tolist(), cols.tolist()))) # [(0, 1), (1, 0)]DETR: object queries and set prediction
DETR uses a fixed number of learned object queries. Each query becomes one box and one class, so the network predicts the whole set directly. At inference, it keeps predictions above a score threshold. It needs no anchors and no NMS, because the matching loss already discourages duplicate boxes.
Deformable DETR and other fixes for DETR's weaknesses
DETR converges slowly and struggles with small objects, because dense attention over every image position is costly. Deformable DETR attends to a few learned sampling points around each reference point instead, which speeds training and works better on multi-scale features.
Exercise
Why does DETR not need NMS after prediction?
Show answer
Hungarian matching assigns each ground-truth object to exactly one prediction during training. The other predictions learn to output "no object," so the model rarely produces duplicate boxes.