Real-Time & Anchor-Free Detectors
The YOLO family, keypoint and center-based detectors, and the speed–accuracy frontier.
The first YOLO looked at an image once and returned its boxes at 45 frames per second. Since then real-time detectors have taken on anchors, shed them again and finally shed non-maximum suppression, and much of the accuracy they gained came from a question that sounds like bookkeeping: during training, which predictions are told that they are responsible for which object?
What you’ll learn
- Describe YOLO's grid formulation and loss, and derive how regressing , or weighs the errors of large and small boxes.
- Follow YOLOv2 and YOLOv3's priors, scales and parametrizations, and sort out who built the later YOLO versions.
- Prove when an anchor grid leaves an object with no anchor above an IoU threshold, and connect it to the measured best possible recall of real detectors.
- Explain detection from corners (CornerNet), center heatmaps (CenterNet) and points with centerness (FCOS), and decode a heatmap without IoU-based NMS.
- Weigh the evidence that label assignment, not anchors, separates detectors; explain NMS-free training; and measure detector speed honestly.
The YOLO family
YOLO (Redmon, Divvala, Girshick & Farhadi, 2016) treats detection as one regression from pixels to a fixed tensor. The image is divided into an grid, and the cell that contains an object's center is responsible for it. Each cell predicts boxes , each with a confidence trained toward , and one set of class probabilities shared by its boxes. With , and the output is : 98 boxes per image, each scored at test time by .
The loss is a sum of squared errors with two weights: on box coordinates and on the confidences of boxes that contain no object, which would otherwise pull most confidences to zero and swamp the few cells with objects. Of the predictors in a cell, the one whose current box has the highest IoU with the object is made responsible, so predictors specialize in sizes and shapes. Widths and heights enter through their square roots, a choice the paper says "partially" addresses the fact that the same error matters more for a small box. How partially is a short calculation.
Let the true width be and the predicted width , a relative error , with center and height exact. The IoU then depends on alone, the same for a 10-pixel box as for a 300-pixel one:
A plain squared error charges the same relative error in proportion to the square of the box size, so large boxes dominate the loss:
Square roots reduce the dependence to the first power of the size:
Log-space targets, as in Faster R-CNN and in YOLOv2's , remove it, matching the scale invariance of IoU itself. Losses built on IoU, such as GIoU, go one step further and optimize the overlap directly.
YOLO ran at 45 frames per second (a smaller Fast YOLO at 155) with 63.4% mAP on PASCAL VOC 2007, against 70.0% at 0.5 frames per second for Fast R-CNN. Its errors differed in kind: localization errors outnumbered all others combined, while Fast R-CNN was almost three times as likely to fire on background. With two boxes and one class per cell, YOLO struggled with small objects in groups, such as flocks of birds.
YOLOv2 (Redmon & Farhadi, 2017) kept the single pass and adopted anchors. It dropped the fully connected layers and shrank the input to , so the stride-32 output is , an odd size with a single center cell for the many large objects centered in photos. Instead of hand-picking anchor shapes it ran k-means on the training boxes with the distance , because Euclidean distance on lets large boxes dominate: 5 centroids matched the average IoU of 9 hand-picked anchors (61.0 vs. 60.9). Box centers stay inside their cell through a sigmoid, , which stabilized early training. Anchors alone lowered mAP slightly, from 69.5 to 69.2, but raised recall from 81% to 88%; with all its changes YOLOv2 reached 76.8% mAP at 67 frames per second.
How many boxes does YOLOv2 predict for a image, with 5 priors at every cell of its stride-32 output?
Show the answer
845
, so boxes, almost nine times YOLOv1's 98. YOLOv3 at the same size predicts at strides 32, 16 and 8 with 3 priors each: boxes, every one of which NMS must consider.
YOLOv3 (Redmon & Farhadi, 2018) predicted at three scales through an FPN-like upsampling path, with 3 of 9 k-means priors per scale, and replaced the softmax by independent logistic classifiers, since labels such as "woman" and "person" overlap. It also shows why the metric matters: at it reached 57.9 AP on COCO, close to the 59.1 of RetinaNet with a ResNet-101 FPN, but 33.0 AP averaged over IoU thresholds 0.50–0.95, against 39.1. Its boxes found the objects but were not tightly aligned. YOLOv3 was the last version by Redmon and Farhadi; the name passed to other groups:
| Version | Authors | What changed |
|---|---|---|
| YOLOv4 (2020) | Bochkovskiy, Wang & Liao | a systematic test of training-only "freebies" and cheap inference-time "specials": CSPDarknet53 backbone, Mosaic augmentation, CIoU box loss; 43.5% COCO AP at about 65 frames per second on a V100 |
| YOLOv5 (2020), YOLOv8 (2023) | Ultralytics | software releases without accompanying papers; YOLOv8 has an anchor-free head |
| YOLOX (2021) | Ge, Liu, Wang, Li & Sun | anchor-free, separate classification and regression heads, SimOTA label assignment |
| YOLOv7 (CVPR 2023) | Wang, Bochkovskiy & Liao | architecture changes and "trainable" freebies, trained on COCO from scratch |
| YOLOv10 (NeurIPS 2024) | Wang et al. | NMS-free training with consistent dual label assignments |
Where anchors leave gaps
An anchor-based detector can only learn to find an object if some anchor is labeled positive for it, which requires an IoU above a threshold (0.5 in RetinaNet, 0.7 in Faster R-CNN's proposal network). Anchors sit on a grid of stride at a few discrete sizes, so some objects fall between them. How far between can be computed exactly.
Two squares of side whose centers differ by , with , intersect in an rectangle. Since increases with the intersection , the IoU decreases in both offsets:
The nearest anchor center is at most away in each coordinate, with equality at a cell corner. Put and solve :
For (b), a square of side centered inside one of side gives IoU , which falls as the ratio grows. Between anchor sides and the best ratio is worst at the geometric midpoint , where it equals on both sides:
Position and scale errors compound, and real objects are not square, so the true worst cases are worse. Two consequences follow. Small objects need fine strides: on RetinaNet's finest level (, smallest anchor 32 pixels, so ) a same-size object is safe at any position (worst IoU 0.62), but a 16-pixel object reaches only even when perfectly centered, and nothing below about 22.6 pixels can reach 0.5 with a 32-pixel anchor. And coarse scale spacing alone can push objects to the threshold, which is why RetinaNet places three scales per octave, , times three aspect ratios: in its ablation, 9 anchors per location reached 34.0 AP against 30.3 for one square anchor, with no gain beyond 6–9.
The gaps are measurable. Tian et al. (2019) counted the best possible recall, the fraction of COCO objects assigned to at least one anchor or location during training. RetinaNet's anchors with IoU alone cover 86.8% of objects; adding "low-quality" matches down to IoU 0.4 gives 90.9%, and assigning every object its best anchor whatever the IoU gives 99.2%. Faster R-CNN's proposal network uses the same remedy: each object's best-overlapping anchor is positive even below 0.7. An anchor-free detector that assigns every location inside a box covered 95.6% from one stride-16 level and 98.4% with a feature pyramid.
Corners, centers and points
Anchor-free detectors replace box templates with keypoints, or with every location of a feature map.
CornerNet (Law & Deng, 2018) detects a box as a pair of keypoints. For each class one heatmap marks top-left corners and another bottom-right corners; each detected corner also outputs an embedding, trained so that the two corners of one object have similar embeddings (a "pull" loss) and corners of different objects dissimilar ones (a "push" loss), and corners are paired by their embeddings. A corner often lies outside the object (think of a ball), so a corner pooling layer takes, at each location, the maximum of one feature map over everything to its right plus the maximum of another over everything below, the directions in which the object's top and left edges appear. As the authors note, corner positions encode possible boxes. CornerNet reached 42.2% COCO AP.
CenterNet, "Objects as Points" (Zhou, Wang & Krähenbühl, 2019), keeps only the center. At output stride the network predicts one heatmap per class, in which each object is a Gaussian around its downsampled center with a size-adaptive , and at every location a width and height and a sub-cell offset: output channels. The heatmap is trained against these targets with a variant of the focal loss, the size and offset with losses at the centers only:
import torch
import torch.nn.functional as F
def decode_centers(heat, size, offset, k=100):
"""heat: (C, H, W) center heatmap in [0, 1]; size, offset: (2, H, W). Boxes in output-grid units."""
C, H, W = heat.shape
is_peak = heat == F.max_pool2d(heat[None], kernel_size=3, stride=1, padding=1)[0]
scores, idx = (heat * is_peak).flatten().topk(k) # local maxima only: no IoU-based NMS
cls, pos = idx // (H * W), idx % (H * W)
y, x = pos // W, pos % W
cx, cy = x + offset[0, y, x], y + offset[1, y, x] # sub-cell offsets undo the stride's rounding
w, h = size[0, y, x], size[1, y, x]
boxes = torch.stack([cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2], dim=1)
return boxes, scores, cls # multiply boxes by the stride R for pixelsA peak is any heatmap value at least as large as its 8 neighbors, found with one max pooling, and the 100 highest are kept (a score threshold then drops weak ones). Each object's target is a single Gaussian bump, so a trained heatmap usually has one peak per object: the authors call peak extraction a sufficient alternative to NMS, although a plateau of equal values or a second bump can still yield a duplicate. CenterNet ran at 142 frames per second with 28.1% COCO AP on a ResNet-18 and at 52 with 37.4% on DLA-34. (Its best result, 45.1% with an Hourglass-104 network, used flipped and multi-scale testing, whose results are merged with NMS. A keypoint-triplet detector by Duan et al., from the same month, is also called CenterNet.)
FCOS (Tian et al., 2019) predicts at every location of a feature pyramid. A location inside a true box is positive and regresses the four distances from itself to the box's sides. Each level to (strides 8 to 128) handles one range of sizes: a location on level stays positive only if , with , and a location still inside two boxes takes the smaller. Locations far from an object's center produce poor boxes, so a one-layer branch predicts the centerness:
Is the anchor what matters, then? ATSS (Zhang et al., 2020) took RetinaNet with one square anchor per location, which scored 32.5 AP on COCO minival against FCOS's 37.8, and gave it FCOS's general improvements one at a time: group normalization in the heads, a GIoU loss, positives restricted to locations inside the box, the centerness branch and a learnable scale per level. That reached 37.0. Two differences remained, and crossing them shows which one matters:
| Positives chosen by | Regress from the anchor box | Regress from the point |
|---|---|---|
| IoU with the anchor (RetinaNet's rule) | 37.0 | 36.9 |
| inside the box and in the level's size range (FCOS's rule) | 37.8 | 37.8 |
ATSS then made the definition adaptive. For each object it takes the anchors whose centers are closest to the object's center on each of the pyramid levels, computes their IoUs with the object, and makes positive the candidates whose IoU is at least the mean plus one standard deviation of these values and whose centers lie inside the box. Were the IoUs normally distributed, of candidates would pass; the authors measured about positives per object whatever its size, where fixed IoU or size rules give large objects many more. At no inference cost it lifted RetinaNet to 39.3 AP and FCOS to 39.2.
NMS-free training and honest speed
Later rules let the network's own predictions decide. OTA (Ge et al., 2021) treats assignment as optimal transport over the whole image: objects supply labels, predictions demand them, the unit cost of a pair is a weighted sum of its classification and regression losses, and the cheapest transport plan, found with Sinkhorn–Knopp iterations, is the assignment. Its approximation in YOLOX, SimOTA, gives each object its lowest-cost predictions within a central region, with estimated per object. YOLOX's roadmap measured every change on COCO with one backbone (Darknet-53, ):
| Change | AP | Gain |
|---|---|---|
| YOLOv3 baseline | 38.5 | — |
| separate classification and regression heads | 39.6 | +1.1 |
| strong augmentation (Mosaic, MixUp) | 42.0 | +2.4 |
| anchor-free, one positive per object | 42.9 | +0.9 |
| multiple positives (the central locations) | 45.0 | +2.1 |
| SimOTA assignment | 47.3 | +2.3 |
| end-to-end, NMS-free (optional) | 46.5 | −0.8 |
Every rule so far is one-to-many: several predictions per object are trained as positives, which gives rich supervision and, at test time, duplicates that NMS must remove. A one-to-one rule, such as DETR's Hungarian matching, trains a single positive per object, so a well-trained model emits no duplicates, but each object supplies only one positive training signal. YOLOv10 (Wang et al., 2024) trains two heads on the same features, one with each kind of assignment, and keeps only the one-to-one head at inference. Both rank predictions by a matching metric , where is the class score and says whether the prediction's location lies inside the object, and one line of algebra keeps the two heads consistent:
DETR-style detectors were NMS-free from the start but slow. RT-DETR (Zhao et al., 2024) made them real-time: its hybrid encoder applies attention only within the coarsest feature level and fuses scales with convolutions, and an uncertainty-minimal query selection initializes the decoder from the encoder features most likely to be objects. It reached 53.1% COCO AP at 108 frames per second (ResNet-50 backbone, T4 GPU, TensorRT at FP16), and its speed can be tuned by running fewer decoder layers, without retraining. By the YOLOv10 authors' end-to-end measurements, YOLOv10-S was 1.8 times faster than RT-DETR-R18 at similar AP.
Every such number describes a whole system: model, input resolution, batch size, numerical precision, software runtime, hardware, and the processing around the network. Three findings show how much that matters:
- Resolution and proposals. Re-implementing Faster R-CNN, R-FCN and SSD with many backbones in one framework, Huang et al. (2017) found that halving the input resolution cut inference time by 27.4% on average and accuracy by 15.88% (relative), mostly on small objects, and that Faster R-CNN with an Inception-ResNet backbone kept 96% of its accuracy with 50 proposals instead of 300, at a third of the running time.
- Post-processing. On a T4 GPU, Zhao et al. (2024) timed NMS for YOLOv8 at 1.06 to 2.46 ms depending on its two thresholds, and the setting with the best AP (confidence 0.001, IoU 0.7) was among the slowest; in their tests anchor-based YOLOs produced about three times as many boxes as anchor-free ones and paid more for NMS. Many real-time papers report model latency without NMS, and YOLOX's tables say so.
- Fixed costs. A fixed saving matters more at high frame rates: removing 10 ms from a pipeline running at 5 frames per second gains 0.26 frames per second, from one at 30 frames per second 12.9 (Bolya et al., 2019).
Fast NMS (Bolya et al., 2019) parallelizes NMS: it computes all pairwise IoUs of the score-sorted boxes and discards every box that overlaps any higher-scoring box above the threshold, whether or not that box was itself discarded. Take the boxes of Detection, Segmentation & Video: scores 0.9, 0.8, 0.7, 0.6 for , , , , with , and apart. What does Fast NMS keep at threshold 0.5?
- , and , exactly like greedy NMS
- and
- only
- All four boxes
Show the answer
B. and
overlaps the higher-scoring , and overlaps the higher-scoring , so both go, although greedy NMS would keep because had already been removed. In general a box that greedy NMS removes overlaps a kept higher-scoring box, hence also some higher-scoring box, so Fast NMS keeps a subset of what greedy NMS keeps. Its authors measured a loss of 0.1 to 0.3 mAP for 12 to 15 ms saved per image.
An honest speed claim therefore states the hardware and software runtime, the batch size (1 for latency), the precision (FP32, FP16 or INT8), the input resolution, what is included (preprocessing, NMS, data transfer), and the accuracy measured under exactly those settings, as the median of many runs after a warm-up. Efficient ConvNets explains why FLOP counts cannot stand in for any of this.
Key takeaways
- YOLO casts detection as one regression on an grid ( outputs, 45 frames per second); YOLOv2 added k-means priors under the distance , sigmoid-bounded centers and log-space sizes (845 boxes at ); YOLOv3 predicted at three scales. Later YOLO versions come from different groups.
- For a fixed relative error, a squared-error loss grows like , YOLOv1's square-root loss like , and a log-space loss not at all, matching the scale invariance of IoU.
- Anchors leave provable gaps: a same-size object at a cell corner needs anchors of at least to reach IoU 0.5, and one anchor scale per octave can leave IoU at exactly 0.5; on COCO, IoU matching alone covers only 86.8% of objects.
- Anchor-free detectors pair corner keypoints by embeddings (CornerNet), take the peaks of a Gaussian center heatmap with a max pooling instead of IoU-based NMS (CenterNet), or regress side distances at every location weighted by centerness (FCOS). ATSS showed that the definition of positive samples, not the anchor, separates detectors.
- Adaptive and prediction-aware assignment (ATSS, SimOTA) gained more AP than removing anchors; one-to-one assignment makes detectors NMS-free (DETR, RT-DETR, YOLOv10's consistent dual assignments). Speed must be reported end to end, with hardware, batch size, precision, resolution and NMS stated.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
A detector makes the same relative error in the width of every box. How does each loss grow with the true width , to leading order in ?
- grows like , like , and like
- All three grow like ; only the constants differ
- grows like , like , and not at all
- None depends on , since IoU does not
Show the answer
C. grows like , like , and not at all
With : , then , then . IoU depends on alone, so only the log-space loss treats a 10-pixel and a 300-pixel box alike; YOLOv1's square roots reduced the bias toward large boxes without removing it.
A detector places square anchors whose sides double from one size to the next (one scale per octave). An object, perfectly centered on an anchor position, has a side halfway (geometrically) between two anchor sides. What is the best IoU any anchor achieves?
- 0.71
- 0.25
- 0.79
- 0.50
Show the answer
D. 0.50
The object's side is times the smaller anchor's and times the larger one's, so either concentric pair has IoU : exactly RetinaNet's threshold, before any position error. Three scales per octave raise the worst case to .
What did ATSS's controlled comparison of RetinaNet (one anchor per location) and FCOS show?
- Anchor boxes themselves cost about 5 AP
- Once general improvements were shared, the remaining gap came from how positive and negative samples are defined; regressing from an anchor box or from a point made no difference
- FCOS's centerness branch alone explained the whole gap
- Anchor-free detectors are faster at equal accuracy
Show the answer
B. Once general improvements were shared, the remaining gap came from how positive and negative samples are defined; regressing from an anchor box or from a point made no difference
Group normalization, the GIoU loss, positives inside the box, centerness and per-level scales took RetinaNet from 32.5 to 37.0 AP. With the sample definition crossed between the two detectors, a box start and a point start gave 37.0 and 36.9 under the IoU rule and 37.8 and 37.8 under FCOS's rule.
Two detectors on the same GPU report model latencies of 4.0 ms and 4.5 ms, measured without post-processing. The faster one is anchor-based and outputs about three times as many boxes before NMS. What follows about their end-to-end speed?
- The anchor-based detector is faster end to end, since NMS is negligible
- The anchor-free detector is faster in every setting
- Nothing yet: NMS must be timed too, and its cost grows with the number of candidate boxes and depends on the thresholds
- Only their FLOP counts can settle it
Show the answer
C. Nothing yet: NMS must be timed too, and its cost grows with the number of candidate boxes and depends on the thresholds
On a T4 GPU, NMS alone took 1.06 to 2.46 ms for one YOLO model depending on its thresholds, more than the 0.5 ms gap here, and it grows with the number of boxes. End-to-end latency at the operating thresholds, on the target hardware, decides.
Further reading
- J. Redmon, S. Divvala, R. Girshick & A. Farhadi, "You only look once: Unified, real-time object detection," CVPR (2016).
- J. Redmon & A. Farhadi, "YOLO9000: Better, faster, stronger," CVPR (2017).
- Z. Tian, C. Shen, H. Chen & T. He, "FCOS: Fully convolutional one-stage object detection," ICCV (2019).
- S. Zhang, C. Chi, Y. Yao, Z. Lei & S. Z. Li, "Bridging the gap between anchor-based and anchor-free detection via adaptive training sample selection," CVPR (2020).
- Y. Zhao, W. Lv, S. Xu, J. Wei, G. Wang, Q. Dang, Y. Liu & J. Chen, "DETRs beat YOLOs on real-time object detection," CVPR (2024).