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.
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.
- 1. YOLO v1 divides the image into…
- 2. The cell responsible for an object contains…
- 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.
- 1. YOLO v1 output size:
- 2. λ_coord =
- 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- 1. YOLO v1's input size:
- 2. Fast YOLO has…
- 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.
- 1. YOLO's background errors vs Fast R-CNN:
- 2. λ_noobj down-weights…
- 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.
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
- J. Redmon, S. Divvala, R. Girshick, A. Farhadi (2016). “You only look once: unified, real-time object detection.” Proc. CVPR.
- J. Redmon, A. Farhadi (2017). “YOLO9000: better, faster, stronger.” Proc. CVPR.
- W. Liu et al. (2016). “SSD: single shot MultiBox detector.” Proc. ECCV.