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

YOLO v1

YOLO, You Only Look Once (Redmon, Divvala, Girshick and Farhadi, 2016), framed detection as a single regression from the whole image to a 7 × 7 grid of predictions. Each cell predicts 2 boxes with confidences and one set of 20 class probabilities: a 7 × 7 × 30 tensor from one network pass. It ran at 45 frames per second (Fast YOLO at 155) with 63.4% mAP on VOC 2007, made far fewer background mistakes than Fast R-CNN, but localised less precisely and struggled with small, crowded objects. This page covers the grid, the loss and its weights, and the limits. In the exercises you build the output and loss, then simulate the grid's capacity: crowded scenes lose over half their objects on a 7 × 7 grid when there are twenty, scattered ones 17%.

Level 0: Foundation

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

One look, one answer

Instead of proposing regions and checking each, YOLO divides the image into a 7 × 7 grid. Each cell answers at once:

  • whether an object’s centre is inside it;
  • where that object’s box is;
  • what kind of object it is.

The whole picture is processed in a single pass, so YOLO runs in real time and sees the global context, which helps it avoid mistaking background for objects. The price: each cell can report only a couple of objects of one class, so tight crowds are hard.

Detection lab
kept 7 of 14 boxes above the score threshold (3 objects). Too high an IoU threshold keeps duplicates; too low merges neighbouring objects.
Why engineers care

YOLO’s speed made real-time detection practical on robots, drones and cars, and its descendants (E9-8, E9-9) are among the most deployed detectors in robotics today.

📝 Quick check (Level 0)
0/3 answered
  1. 1. YOLO v1 divides the image into…
  2. 2. The cell responsible for an object contains…
  3. 3. YOLO's main weakness:

Level 1: Beginner

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

By hand

  • Output: S × S × (B·5 + C) = 7 × 7 × 30 = 1,470 numbers.

    • Each cell has B = 2 boxes (x, y, w, h, confidence) and C = 20 class probabilities.
    • x and y are offsets within the cell; w and h are relative to the image.
  • Responsible cell: an object centred at (0.5, 0.95) falls in cell (row 6, column 3). Within that cell, the box predictor with the highest IoU is responsible for it.

  • Loss:

    • λ_coord = 5 times the coordinate errors, with √w and √h;
    • plus the confidence error for object boxes;
    • plus λ_noobj = 0.5 times the confidence error for empty boxes;
    • plus the class-probability error for cells containing objects.

    Everything is a squared error.

  • Why √w: a 0.02 error on a box 0.04 wide costs about 12 times more than on a box 0.6 wide, because the error matters more for small boxes.

  • Test score: Pr(class | object)·confidence, e.g. 0.5·0.8 = 0.4.

  • Capacity: at most 7·7·2 = 98 boxes per image, and one class per cell.

📝 Quick check (Level 1)
0/3 answered
  1. 1. YOLO v1 output size:
  2. 2. λ_coord =
  3. 3. Max detections per image:

Level 2: Intermediate

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

YOLO v1 in code

Exercise 1.

  • The output size was 1,470.
  • The responsible cell was found from the centre.
  • The square-root coordinate loss penalised a small box’s size error about 12 times more than a large one’s.
  • The class score multiplied confidence and class probability.

Practice.

  • Network: 24 convolutional layers plus 2 fully connected layers on 448 × 448 input. Fast YOLO uses 9 conv layers.
  • Training:
    • pretrain the first 20 conv layers on ImageNet at 224;
    • then train detection at 448 for about 135 epochs on VOC;
    • leaky ReLU, dropout 0.5 after the first fully connected layer, and strong augmentation (scaling, translation, HSV jitter).
  • Inference: threshold the class scores, then apply NMS.
  • Combining YOLO’s scores with Fast R-CNN’s raised Fast R-CNN’s mAP from 71.8% to 75.0%, because YOLO’s errors are different (fewer background false positives).
out = net(img).view(7, 7, 30)                      # one pass
boxes, conf, probs = out[..., :8].view(7, 7, 2, 4), out[..., 8:10], out[..., 10:]
scores = conf[..., :, None] * probs[..., None, :]  # 7 x 7 x 2 x 20 class-specific scores
🐍 Exercise 1: YOLO's output and loss
Compute the output size, the responsible cell, the square-root coordinate loss and the class score.
📝 Quick check (Level 2)
0/3 answered
  1. 1. YOLO v1's input size:
  2. 2. Fast YOLO has…
  3. 3. YOLO + Fast R-CNN mAP:

Level 3: Advanced

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

Theory

Detection as regression. YOLO reasons globally: every prediction sees the whole image through the fully connected layers. That is why it made fewer background errors than region-based methods, which see only crops:

  • background accounted for 4.75% of its top detections against 13.6% for Fast R-CNN;
  • it also generalised better from natural images to artwork.

Loss design.

  • Most cells contain no object. Without down-weighting (λ_noobj = 0.5), their confidence errors would overwhelm the gradient and push all confidences towards 0.
  • Coordinates are up-weighted (λ_coord = 5) to make localisation matter.
  • Square roots partly equalise the cost of errors across box sizes.

Limits.

  • Each cell predicts two boxes and one class, so nearby objects compete (exercise 2).
  • Coarse 7 × 7 features and direct box regression give imprecise localisation: localisation errors were 19.0% of top detections against 8.6% for Fast R-CNN.
  • Unusual aspect ratios are hard without anchors.

YOLOv2 (E9-8) added anchors, a finer 13 × 13 grid and batch normalisation.

📝 Quick check (Level 3)
0/3 answered
  1. 1. YOLO's background errors vs Fast R-CNN:
  2. 2. λ_noobj down-weights…
  3. 3. YOLO's dominant error type:

Level 4: Expert

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

How many objects does the grid drop?

History.

  • J. Redmon, S. Divvala, R. Girshick and A. Farhadi (2016) introduced YOLO at CVPR. It ran at 45 frames per second with 63.4% mAP on VOC 2007; Fast YOLO at 155 frames per second with 52.7%.
  • W. Liu et al. (2016) introduced SSD (E9-6) the same year.
  • J. Redmon and A. Farhadi (2017, 2018) followed with YOLOv2 (YOLO9000) and YOLOv3 (E9-8).

Exercise 2. This is a simulation, not a training run. Objects with random centres and one of 20 random classes are placed either scattered uniformly or crowded around one point. Each grid cell keeps at most B = 2 objects of its majority class; the rest are lost. Over 2,000 images per setting:

grid placement lost with 2 objects 5 10 20
7 × 7 scattered 0.011 0.038 0.082 0.165
7 × 7 crowded 0.056 0.212 0.376 0.535
13 × 13 scattered 0.004 0.011 0.025 0.052
13 × 13 crowded 0.025 0.081 0.167 0.289
  • Sparse scenes are fine: with a few scattered objects, under 4% are lost.
  • Crowds are not: with twenty crowded objects (birds, cars in a car park, a flock of sheep) over half cannot be predicted at all on the 7 × 7 grid.
  • A finer grid helps, roughly threefold for scattered objects. That is one reason YOLOv2 moved to 13 × 13 with 5 anchors per cell, each with its own class prediction.
  • This counts a structural upper limit, not trained accuracy. Real YOLO also loses objects through imprecise localisation.
🐍 Exercise 2 (research): how many objects does the grid drop?
Simulate how many objects YOLO v1's grid cannot represent, for scattered and crowded scenes and two grid sizes.

YOLO in AI, robotics and aerospace

  • Real-time robotics: YOLO-family detectors run on embedded GPUs for obstacle, person and object detection in mobile robots and drones.
  • Global context: fewer background false positives matter for automated systems that act on detections.
  • Crowds: dense scenes (crowds, livestock, parked vehicles from above) need finer grids, anchors or dense detectors.

References

  1. J. Redmon, S. Divvala, R. Girshick, A. Farhadi (2016). “You only look once: unified, real-time object detection.” Proc. CVPR.
  2. J. Redmon, A. Farhadi (2017). “YOLO9000: better, faster, stronger.” Proc. CVPR.
  3. W. Liu et al. (2016). “SSD: single shot MultiBox detector.” Proc. ECCV.