One object per cell

YOLOv1 cuts an image into a 7×7 grid and asks each cell to describe at most one object. When two objects share a cell, the network is never taught about one of them.

7.1 % of the objects in Pascal VOC 2007 fall in a cell that is already taken.

target kept no target: its cell is taken
Nassim Arifette, PhD student at École polytechnique
Master MVA, ENS Paris-Saclay
Redmon et al., YOLOv1, CVPR 2016

In short

This is a from-scratch reimplementation of YOLOv1 on Pascal VOC 2007, rebuilt so that its numbers can be trusted. The loss follows the paper, evaluation reads every annotation, and train, validation and test never mix.

I wanted to answer two questions. First, how much does the one-object-per-cell grid cost? On VOC 2007, 1,745 of 24,640 objects cannot become a training target, and for bottles the share reaches 15.8 %. Second, does it matter whether the confidence score learns the box’s IoU, as in the paper, or a constant one? That experiment is running, so this page reports no new mAP yet.

What a cell has to say

YOLOv1 reads a 448×448 image once and outputs a 7×7×30 tensor. Each of the 49 cells gives 20 class probabilities and two candidate boxes, each box a centre (relative to the cell), a width and height (relative to the image) and a confidence [1].

During training, each object goes to the cell that contains its centre, and only that cell learns to find it. Hover a cell to see the target it receives.

Figure 1. Real VOC 2007 test annotations, encoded with the training target code of this repository. The first object in annotation order takes the cell. The others get no target, but evaluation still counts them.

The grid’s blind spot, measured

The paper admits this limitation: the model struggles with small objects that appear in groups. With the encoder, it can be counted. Over the official train, validation and test lists, 1,141 of 9,963 images contain at least one object that loses its cell.

Some classes are hit much harder than others. Bottles, people and chairs come in clusters and lose their cell far more often than trains or cats, which tend to be large and alone.

Split
Figure 2. Share of non-difficult objects that receive no training target, per class, from the repository’s grid audit of every VOC 2007 annotation. It is not a hard recall ceiling, because a cell has two boxes and at test time they can still land on different objects.

What should confidence learn?

Each box also predicts a confidence. In the paper, its target is the IoU between the predicted box and the object it is responsible for, so a sloppy box should learn to be unsure. A simpler alternative trains it towards 1 wherever there is an object. The experiment keeps that one as a control.

This shows up at test time. Detections are ranked by class probability times confidence, and average precision rewards putting good boxes above bad ones. Drag the box and compare the two targets.

Drag the box to move it; drag its corner to resize.

Figure 3. The ground truth is a real VOC annotation; the predicted box is yours. IoU uses VOC’s inclusive pixel convention, as in the evaluation code.

Cleaning up: non-maximum suppression

With two boxes in each of 49 cells, it is common for several cells to fire on the same object. Non-maximum suppression keeps the highest-scoring box and removes any other box that overlaps it by more than a threshold. Because it runs per class, a rider never suppresses her horse.

Figure 4. The candidates are not model outputs. They are illustrative boxes, jittered around the real annotations. Suppression follows the same class-specific rule as the evaluation code, which uses a threshold of 0.5 tuned on validation only.

The experiment

I froze the protocol before training. The four conditions differ only in the confidence target and the augmentation; architecture, optimiser, schedule and image order are the same. Each one runs with three seeds.

Confidence target: 1Confidence target: IoU
No augmentationA pendingB pending
Flips and colour changesC pendingD pending

The confidence target effect is read from B − A and D − C, the augmentation effect from C − A and D − B. Each is reported with its seeds, even if it comes out zero or negative. Checkpoints are picked on validation mAP, and the test set is evaluated once, with VOC 2007’s 11-point interpolated AP at IoU 0.5 [2].

Status: training. Results will go here, along with per-class AP, seeds, selected checkpoints and raw detections.

What this does not claim

The original course project

The first version of this project trained a YOLOv1 and compared it with newer YOLO releases on videos. Its curves are kept below as training diagnostics. They were produced by code that had several bugs, since fixed, and they are measured on training data, so they say nothing about generalisation.

Historical training loss curve
Historical training loss.
Historical training mAP curve
Historical mAP on training images.

Run it yourself

Everything below runs on a CPU except training. The download script checks the official archives against MD5 and SHA-256 hashes, then writes the grid audit shown in Figure 2.

python -m pip install -r requirements-test.txt
python -m pytest tests -q
python download_voc.py --data-dir data
python train.py --voc-root data/VOCdevkit --out outputs/iou_aug_seed123
python evaluate.py --checkpoint outputs/iou_aug_seed123/best.pt --manifest data/manifests/test.json --voc-root data/VOCdevkit --out outputs/iou_aug_seed123_test

References

  1. Joseph Redmon, Santosh Divvala, Ross Girshick, Ali Farhadi. You Only Look Once: Unified, Real-Time Object Detection. CVPR 2016.
  2. Mark Everingham, Luc Van Gool, Christopher K. I. Williams, John Winn, Andrew Zisserman. The PASCAL Visual Object Classes (VOC) Challenge. IJCV, 2010.