Deep Learning · Topic 1 · Learn Yolo from scratch A-Z · Interactive sheet · Intermediate

The Learn Yolo from scratch A-Z Blueprint

Theory and Practical · Year 1

YOLO looks at the whole image once and predicts every box and every class in a single forward pass of one network. It cuts the image into an S × S grid and makes the cell that holds an object's centre responsible for finding it. Every number on this page is clickable. Every underlined term has a definition.

Before you start: what a convolution is (CNN), how a deep stack of convolutions is built (AlexNet & VGG-16), and what it means to minimise a squared-error loss (Linear Regression).

448 → 7
shape path
7 × 7 × 30
output grid
…
weights
…
MACs per image
63.4
mAP · VOC 2007
45 fps
real time
01

Object detection, and the race to do it in real time

Object detection means finding every object in an image, drawing a bounding box around it and naming its class, and in 2015 the most accurate detectors needed far too long per image for live video.

Scoring one detection: is the box good enough?

shift x20
shift y10
box scale100 %
threshold
20
PASCAL VOC classes
7 fps
Faster R-CNN, 73.2 mAP
0.05 fps
R-CNN, 2014
45 fps
YOLOv1, 63.4 mAP

Why the result mattered

Video runs at 25–30 frames per second. A detector that needs seconds per frame can only work offline; one that needs 22 ms can steer a robot, count cars at a junction or follow a ball. YOLO showed that detection can be framed as one regression problem solved by one network, and that idea now runs on phones and drones.

timeline · click a chip
2001 Viola–Jones 2005 HOG 2010 DPM 2014 R-CNN 2015 Fast R-CNN 2015 Faster R-CNN 2016 YOLO 2016 SSD
02

Walk an image through YOLOv1

Each bead is one layer drawn to scale (width is the spatial size, height the number of channels); scrub, press play or click a bead to see the live shape, the weights and the multiply-adds.
conv + leaky ReLU max-pool dense (FC) grid output
YOLOv1100%
layer scrubberinput
input
weights so far
0
MACs so far
0

Worked example: YOLOv1 shapes, step by step

conv1: 64 filters of 7 × 7, stride 2, padding 3, on a 448 × 448 × 3 image
(448 − 7 + 6) ÷ 2 + 1 = ⌊223.5⌋ + 1 = 224 → 224 × 224 × 64
2 × 2 max-pool, then conv2 (192 filters, 3 × 3, same padding), then pool again
(224 − 2) ÷ 2 + 1 = 112 → 112 × 112 × 192 → (112 − 2) ÷ 2 + 1 = 56
1 × 1 and 3 × 3 convs keep the size; each pool halves it
56 × 56 × 512 → pool → 28 × 28 × 1024 → pool → 14 × 14 × 1024
conv22: 3 × 3, stride 2, padding 1 replaces a pool
(14 − 3 + 2) ÷ 2 + 1 = ⌊6.5⌋ + 1 = 7 → 7 × 7 × 1024
Flatten, two dense layers, then reshape into the grid
7 · 7 · 1024 = 50,176 → 4,096 → 1,470 = 7 · 7 · 30 → 7 × 7 × 30

Same formula every time: O = ⌊(N − K + 2P) ÷ S⌋ + 1. Practise it in section 05.

The walker shows 14 × 14 × 1024 entering conv22 (3 × 3 kernel, stride 2, padding 1, 1,024 filters). What comes out?
(14 − 3 + 2) ÷ 2 + 1 = 6.5 → floor 6 → + 1 = 7. The number of filters (1,024) sets the depth, so the result is 7 × 7 × 1024.
03

Three ideas that make one look enough

YOLO rests on a grid that makes one cell responsible for each object, a confidence score that mixes "is there an object?" with "how good is the box?", and non-maximum suppression to delete duplicates.

Idea 1 · Grid responsibility

grid size S7

Click the image to move the selected object's centre.

Idea 2 · Confidence × class

Pr(Object)0.90
IoU of the box with the truth0.80
Pr(dog | Object)0.70
score threshold0.20

Idea 3 · Non-maximum suppression

IoU threshold0.50
Two boxes for the same dog have IoU 0.7 with each other, scores 0.9 and 0.6. The NMS IoU threshold is 0.5. What happens?
NMS keeps the highest-scoring box, then deletes every remaining box whose IoU with it exceeds the threshold. 0.7 > 0.5, so the 0.6 box is a duplicate.
04

The YOLO rule: S × S × (B · 5 + C), in one pass

Every prediction lives in one fixed-size tensor (for each of the S × S cells, B boxes of five numbers plus C class probabilities); compare that single pass with running a classifier on every region proposal.
grid size S7
boxes per cell B2
classes C20
region proposals for a two-stage detector2000
output = S × S × (B · 5 + C) = 7 × 7 × 30 = 1,470
one cell's vector · hover or click a square
x, y, w, hbox confidenceclass probabilities
YOLO
1
vs
R-CNN style
2,000
CNN passes per image
boxes = S² · B · class sets = S² · values = S² (5B + C)

Why it is fast. Two-stage detectors first guess where objects might be, then classify each guess. YOLO regresses boxes and classes together from the whole image, so it also sees context: it makes fewer background mistakes than Fast R-CNN, which only sees each crop.

You set S = 13, B = 3 and C = 10 using the YOLOv1 layout. How many numbers does the network output per image?
Per cell: 3 boxes × 5 numbers + 10 classes = 25. Times 169 cells = 4,225. The output size is fixed by S, B and C, never by the content of the image.
05

Shapes by hand and by eye

One formula, O = ⌊(N − K + 2P) ÷ S⌋ + 1, gives the size after every convolution and pooling layer in YOLO; work it once by hand with tiny numbers, then on the real layers.

Worked example by hand: a 4 × 4 input and one 3 × 3 filter

input 4 × 4
filter 3 × 3
output 2 × 2

Do it on paper

Multiply each input number under the window by the filter number on top of it, add the nine products, and write the sum in the output. Stride 1 moves the window one column; at the end of a row it drops one row. This filter (+1 left, −1 right) responds to vertical edges where the right side is brighter or darker than the left.

O = ⌊(N − K + 2P) ÷ S⌋ + 1 ⌊⌋
input N448
kernel K7
padding P3
stride S2
output size
224 × 224
kernel sliding over the padded input → output map · click to pause100%
Input 16, kernel 3, no padding, stride 2. What is the output size?
(16 − 3 + 0) ÷ 2 = 6.5 → floor 6 → + 1 = 7. Sizes are whole numbers: the last half step does not fit and is dropped.
06

Where the weights live

Most of YOLOv1's … weights sit in one dense layer, while almost all of the multiply-adds happen in the 24 convolutions; click a bar for its arithmetic.
100%
convdensepool layers have no weights
click a bar

The arithmetic for that layer appears here.

Weights

Compute (MACs)

per 448 × 448 image, forward pass

Worked example: counting YOLOv1's weights

conv1: 64 filters of 7 × 7 over 3 colour channels, plus one bias each
(7 · 7 · 3 + 1) × 64 = 148 × 64 = 9,472
A 3 × 3 conv from 1,024 to 1,024 channels (conv21–24 are all like this)
(3 · 3 · 1024 + 1) × 1024 = 9,217 × 1,024 = 9,438,208
All 24 conv layers together
sum from the layer specification = …
fc1: flatten 7 × 7 × 1024 = 50,176 inputs into 4,096 neurons
50,176 × 4,096 + 4,096 = 205,524,992
fc2 outputs the grid, then the total
4,096 × 1,470 + 1,470 = 6,022,590 · total …

The Darknet release of YOLOv1 used a locally connected layer before fc1; this page follows the plain dense head described in the paper's figure, so treat the total as the dense-head version.

Why does fc1 hold more weights than all 24 conv layers together, yet do far fewer multiply-adds?
Conv MACs = Hout · Wout · (weights without biases): the same small kernel runs at every position. A dense layer's MACs equal its weight count, so it is "heavy but cheap".
07

The YOLO family and its variants

From one 7 × 7 grid to anchors, predictions at several scales and anchor-free heads: compare depth, size and score, and load the two original models into the walker.
modelyearbackbone / depthoutputweightsscorespeed
later versions · click a chip
v5 · 2020 v6 / v7 · 2022 v8 · 2023 v9 / v10 · 2024 v11 and later
variant

Click a row of the table.

Same idea, new parts. v2 added batch normalisation and anchors; v3 predicted at three scales with a feature pyramid; v4 collected training tricks; v8 dropped anchors. All still output a dense grid of boxes in a single pass.

What did YOLOv2 add so that the boxes of one cell can start from typical object shapes and carry their own class scores?
YOLOv2 predicts offsets relative to anchor boxes (5 per cell on a 13 × 13 grid) found by k-means on the training boxes, and each anchor gets its own class probabilities.
08

The cost of one look

Count the multiply-adds of one 448 × 448 image from the layer specification, then set a GPU's throughput, its utilisation and the batch size to estimate one image, one epoch and the original training run.
model
GPU throughput (TFLOPS)10
utilisation (share of peak reached)40 %
batch size64
time = 2 · MACs ÷ (TFLOPS · 10¹² · utilisation) · training ≈ 3 × forward
MACs per image
one image (inference)
one training epoch
original run · 135 epochs
activation memory for one batch (float32)
A network needs 20 G MACs per image. Your GPU sustains 10 TFLOPS in practice. Roughly how many images per second can it process?
20 G MACs ≈ 40 G FLOPs. 10 × 10¹² ÷ (40 × 10⁹) = 250 images per second, or 4 ms per image.
09

Reuse YOLO instead of retraining it

Keep the pretrained convolution layers, swap the output head for your own classes, and train only what your data can support: this is transfer learning for detection.
classes in your dataset C3

Which recipe?

Your dataset is
Looks like everyday photos?

        

What changes, what stays

Only the last layer's size depends on C. The labels change too: every training image needs boxes (x, y, w, h) and a class, not just one label per image. Keep the paper's augmentation (random scaling and shifts up to 20 %, exposure and saturation up to 1.5 ×) and report mAP at IoU 0.5 on a held-out set that looks like deployment.

You retrain YOLOv1 (S = 7, B = 2) for 3 classes. How many numbers does each cell now predict?
B · 5 + C = 2 · 5 + 3 = 13 per cell, so the output becomes 7 × 7 × 13 = 637. Only the last layer changes size; everything before it can be reused.
10

From slow and accurate to fast and accurate

PASCAL VOC 2007 mAP of landmark detectors by year, with their speed: YOLO is the first to reach real time with useful accuracy, and its successors won the accuracy back.
VOC 2007 test mAP (%) · dot size grows with frames per second100%
click a point
Faster R-CNN scored 73.2 mAP and YOLOv1 63.4. Why was YOLOv1 still a landmark?
Real-time DPM reached 26.1 mAP at 30 fps; YOLOv1 more than doubled that accuracy at 45 fps. Speed and accuracy together opened up video, robots and embedded use.
11

Where YOLO is used today

Anything that must find objects in live video on modest hardware tends to run a YOLO-style one-stage detector; tap a card to see how it is used and what came after.
A shelf camera must count about 200 small, tightly packed products in each image. Which YOLOv1 property is the main risk?
7 · 7 · 2 = 98 candidate boxes in total, and two product centres in one cell compete. Later versions with finer grids, several scales and anchors (or anchor-free heads) handle dense scenes much better.
12

Key takeaways

Seven sentences to remember; click each one for the evidence and the section that shows it.
Two-stage detectors propose regions and classify each one; YOLO regresses boxes and classes for the whole image at once. Sections 01 and 04.
Per cell: B boxes of (x, y, w, h, confidence) plus C class probabilities. The size does not depend on how many objects are in the image. Section 04.
x, y are offsets inside that cell; w, h are fractions of the image. Of the cell's B boxes, the one with the highest IoU with the truth is trained on that object. Section 03.
Boxes under the score threshold are dropped; among overlapping boxes of one class only the best survives. Section 03.
448 → 224 → 112 → 56 → 28 → 14 → 7 for YOLOv1. Section 05.
fc1 alone is 205.5 M weights; a 1 × 1 conv head (as in later versions) removes almost all of them without changing the conv compute. Sections 06 and 08.
Freeze the backbone for small datasets, fine-tune with a small learning rate for unusual images, and compare scores only on the same dataset and metric. Sections 07 and 09.
13

Check your understanding

Five questions with instant feedback and every answer explained; score 4 or more and the stamp is yours.
0 / 5
■ STAMPED · YOLO BLUEPRINT · APPROVED
14

Glossary

Every term used on this page; type to filter and click a term to open its definition.