Foundations to Frontier
Tests
E. Deep Learning › E9 Object Detection Architectures

YOLO v2/v3

YOLOv2 (Redmon and Farhadi, 2017) fixed YOLO's weaknesses with a list of improvements: batch normalisation, a high-resolution classifier, anchor boxes whose shapes come from k-means clustering of training boxes, sigmoid-bounded centre predictions, a 13 × 13 grid with a passthrough layer, and multi-scale training. It reached 78.6% mAP on VOC 2007. YOLOv3 (2018) added the Darknet-53 backbone, predictions at three scales and independent logistic class scores. This page covers each improvement and its measured effect. In the exercises you decode YOLO predictions and count YOLOv3's 10,647 boxes, then reproduce the dimension-cluster experiment: 5 anchors from k-means with distance 1 − IoU fit boxes better (mean IoU 0.60) than 9 hand-picked anchors (0.55).

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Better, faster, stronger

YOLOv2 took the original YOLO and fixed its weak spots one at a time:

  • normalisation in every layer;
  • a finer grid;
  • preset box shapes learned from the data;
  • predictions that cannot wander outside their cell;
  • training on images of many sizes.

YOLOv3 then added a deeper backbone and detection at three scales, so small objects are found on a fine grid and large ones on a coarse grid. Each step was simple, and together they made YOLO accurate as well as fast.

Detection lab
216 anchors; 0 positive (IoU ≥ 0.5); best IoU with the ground truth 0.46 — no positive anchor, so the best one is also assigned (highlighted)
Why engineers care

YOLOv3 became a workhorse of real-time robotics and drone vision. Its tricks, data-driven anchors and multi-scale heads, are standard in deployed detectors.

📝 Quick check (Level 0)
0/3 answered
  1. 1. YOLOv2's anchor shapes come from…
  2. 2. YOLOv3 detects at…
  3. 3. Multi-scale training uses…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Direct location prediction:
    • b_x = σ(t_x) + c_x and b_y = σ(t_y) + c_y, in grid cells; b_w = p_w·e^(t_w) and b_h = p_h·e^(t_h).
    • The centre stays inside its cell.
    • With t = (0, 0, 0, log 2), cell (6, 6), anchor 100 × 50 and stride 32: centre (208, 208), size 100 × 100.
  • Dimension clusters:
    • k-means on box widths and heights with distance d = 1 − IoU(box, centroid), for boxes placed at the same centre;
    • IoU of 1 × 1 and 2 × 2 is 0.25; IoU of 2 × 1 and 1 × 2 is 1/3.
  • YOLOv3 heads:
    • strides 32, 16 and 8 at 416 × 416 give grids of 13, 26 and 52;
    • each cell has 3 anchors with 4 + 1 + 80 values, so 255 channels;
    • 3·(13² + 26² + 52²) = 10,647 predictions in total.
  • Multi-scale training: every 10 batches, choose an input size from 320 to 608 in steps of 32.
📝 Quick check (Level 1)
0/3 answered
  1. 1. YOLOv3 predictions at 416:
  2. 2. YOLOv3 head channels for 80 classes:
  3. 3. Why σ(t_x)?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

YOLOv2/v3 in code

Exercise 1.

  • Decoding gave centre (208, 208) and size 100 × 100 for the sample prediction.
  • An extreme t_x kept the centre inside its cell.
  • YOLOv3 at 416 makes 10,647 predictions, with 255 head channels.

Practice.

  • YOLOv2’s measured gains on VOC 2007:
    • batch normalisation, +2% mAP (and dropout removed);
    • high-resolution classifier fine-tuning at 448, +4%;
    • dimension clusters with direct location prediction, +5% over plain anchors;
    • passthrough layer from a 26 × 26 map, +1%.
  • Anchors alone raised recall from 81% to 88% at a slight mAP cost.
  • YOLOv3:
    • independent logistic (sigmoid) class scores with binary cross-entropy, so labels can overlap (“woman” and “person”);
    • objectness predicted by logistic regression;
    • Darknet-53 backbone with residual connections.
  • Modern implementations of YOLOv3 exist in many frameworks; Ultralytics’ code made it widely used.
bx = (torch.sigmoid(tx) + cx) * stride;  by = (torch.sigmoid(ty) + cy) * stride
bw = anchor_w * torch.exp(tw);           bh = anchor_h * torch.exp(th)
cls = torch.sigmoid(class_logits)        # YOLOv3: independent per-class scores
🐍 Exercise 1: decoding YOLO predictions
Decode a YOLOv2/v3 prediction, and count YOLOv3's predictions and head channels.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Batch norm in YOLOv2 gave about…
  2. 2. YOLOv3's class scores are…
  3. 3. YOLOv3's backbone:

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why cluster with IoU. Anchors should start close to typical object shapes so that the regressor’s corrections are small. With Euclidean distance on (w, h), large boxes produce large errors and dominate the clustering. The 1 − IoU distance is scale-free: a 10% size error counts the same for a small and a large box. YOLOv2 found 5 IoU clusters matched 9 hand-picked anchors (average IoU 61.0 against 60.9), and 9 clusters reached 67.2.

Why bound the centre. Faster R-CNN-style offsets (x = x_a + t_x·w_a) are unconstrained: early in training, predictions can jump anywhere, which made YOLO training unstable with anchors. The sigmoid keeps each prediction in its cell, so the cell’s responsibility is respected and training converges faster.

Multi-scale. The network is fully convolutional, so it accepts any multiple of 32. Training on random sizes makes one model work across resolutions, a speed–accuracy dial at test time:

  • 288 × 288 gave 69.0% mAP at more than 90 frames per second;
  • 544 × 544 gave 78.6% at 40.

YOLOv3’s three scales add FPN-style top-down features (E9-5), which greatly improved small objects. On COCO it reached 57.9 AP at IoU 0.5 in 51 ms (608 × 608), comparable to RetinaNet at about three times the speed, though weaker at strict IoU thresholds.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Euclidean clustering is dominated by…
  2. 2. Unbounded offsets made early training…
  3. 3. YOLOv2 at 544 × 544:

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Do clustered anchors fit better?

History.

  • J. Redmon and A. Farhadi (2017) introduced YOLOv2 and YOLO9000, which detected over 9,000 categories by jointly training on detection and classification data organised in a WordTree.
  • J. Redmon and A. Farhadi (2018) published the YOLOv3 tech report.
  • Later YOLO versions (E9-9) came from other groups.

Exercise 2. This is a calculation, not a training run. Box shapes are drawn from a COCO-like distribution: log-normal sizes, mostly small, with spread aspect ratios. Anchor sets are compared by the mean IoU between held-out boxes and their best anchor, all placed at the same centre:

anchor shapes mean best IoU
hand-picked 3 scales × 3 ratios 0.553
k-means, Euclidean, k = 5 0.570
k-means, 1 − IoU, k = 5 0.603
k-means, 1 − IoU, k = 9 0.678
  • Five data-driven anchors beat nine hand-picked ones, as YOLOv2 found (paper: 61.0 against 60.9).
  • Nine clusters reach 0.68 (paper: 67.2), giving the regressor smaller corrections.
  • The IoU distance beats Euclidean for the same k, because Euclidean clustering is pulled towards large boxes. A second seed gave the same order (0.547, 0.594, 0.605, 0.673).
🐍 Exercise 2 (research): do clustered anchors fit better?
Cluster box shapes with the 1 − IoU distance and compare mean best IoU against Euclidean clusters and hand-picked anchors.

YOLOv2/v3 in AI, robotics and aerospace

  • Custom anchors: clustering the training set’s boxes is standard practice for drone, satellite and industrial datasets whose object shapes differ from COCO’s.
  • Speed–accuracy dial: multi-scale models let a robot switch input resolution to meet a latency budget.
  • Multi-label classes: independent sigmoid class scores handle overlapping categories in real data.

References

  1. J. Redmon, A. Farhadi (2017). “YOLO9000: better, faster, stronger.” Proc. CVPR.
  2. J. Redmon, A. Farhadi (2018). “YOLOv3: an incremental improvement.” arXiv:1804.02767.
  3. T.-Y. Lin et al. (2017). “Feature pyramid networks for object detection.” Proc. CVPR.