Kumita← Open visual lesson

YOLO: from features to detections

The math behind the picture

One picture can contain several objects, and a one-stage detector proposes boxes for all of them at once. The challenge is to predict candidates from shared features and then decide which of them describe the same object.

Connection 1 of 4

Decode one prediction

Box A decoded: (2 + σ(0.00)) × 32 = 80.0 and (2 + σ(0.45)) × 32 = 83.5 place the centre inside cell (2, 2); 48 × e^0.12 = 54.1 and 48 × e^0.06 = 51.0 stretch the anchor, so the box reaches beyond its cell.
From guided stage 4 · Static lesson frame

Box A decoded: (2 + σ(0.00)) × 32 = 80.0 and (2 + σ(0.45)) × 32 = 83.5 place the centre inside cell (2, 2); 48 × e^0.12 = 54.1 and 48 × e^0.06 = 51.0 stretch the anchor, so the box reaches beyond its cell.

In the simplified YOLOv3 head used here, every cell of a 10 × 7 grid (stride 32) makes one prediction per anchor shape, 140 in all, each of eight numbers. The raw numbers in the lesson are written by hand; the decoding is computed.

Box A comes from the square 48 × 48 anchor at column 2, row 2, with tx = 0.00, ty = 0.45, tw = 0.12, th = 0.06. Its centre is (2 + σ(0.00)) × 32 = 80.0 and (2 + σ(0.45)) × 32 = 83.5; its size is 48 × e^0.12 = 54.1 by 48 × e^0.06 = 51.0, so the box reaches beyond its 32 × 32 cell on every side.

bx = (col + σ(tx))·32,  by = (row + σ(ty))·32,  bw = pw·e^tw,  bh = ph·e^th

Read it as: The sigmoid keeps the centre inside its cell; the exponential stretches the anchor, so the size is not limited by the cell.

Connection 2 of 4

Score it, then collect the duplicates

Nine candidates A–I from one pass, lettered by score; F and H cover the large watermelon again and G the wide slice, while 131 background predictions score 0.003 each.
From guided stage 6 · Static lesson frame

Nine candidates A–I from one pass, lettered by score; F and H cover the large watermelon again and G the wide slice, while 131 background predictions score 0.003 each.

In YOLOv3 each class has an independent sigmoid, not a softmax, and a class score is objectness × class probability. For A: σ(2.50) = 0.924 and σ(3.0) = 0.953, so the watermelon score is 0.880. The three class probabilities add up to 1.018: they need not sum to one. Other YOLO versions score differently.

Nearby predictions respond to the same object: F, from the wide anchor in A's own cell, overlaps A with IoU 0.88. IoU here compares two predictions; no reference annotation is involved.

score(k) = σ(to) · σ(tc_k)    IoU(A, B) = shared area / union area

Read it as: A score is confidence, not a measure of how well the box fits.

Connection 3 of 4

Threshold, then suppress greedily by class

Class-aware greedy suppression: A suppresses F (IoU 0.88 > 0.45), C keeps E (0.19) and suppresses G (0.57); the mug B is never compared with a watermelon. Kept: A, B, C, D, E.
From guided stage 8 · Static lesson frame

Class-aware greedy suppression: A suppresses F (IoU 0.88 > 0.45), C keeps E (0.19) and suppresses G (0.57); the mug B is never compared with a watermelon. Kept: A, B, C, D, E.

Keep candidates with score ≥ 0.50: A–G remain, H (0.37) and I (0.17) and 131 background predictions are removed. Then class-aware greedy NMS: keep the highest-scoring waiting box, suppress later boxes of the same class with IoU > 0.45, and repeat. Ties go to the earlier prediction.

A suppresses F (0.88); B, a mug, is never compared with a watermelon; C keeps E (0.19) and suppresses G (0.57). The detections are A, B, C, D and E.

keep best → suppress same-class IoU > 0.45 → repeat

Read it as: “Greedy” means each step commits to the current highest score rather than optimising every possible set jointly.

Connection 4 of 4

Know what the cutoff cannot resolve

A high-overlap pair may be a duplicate or two real objects close together. In the lesson, the small watermelon (E) stands in front of the wide slice (C) with IoU 0.19: a stricter cutoff of 0.15 would suppress E and miss a real object, while a loose cutoff of 0.80 would keep the duplicate G. A hand-written example shows how this happens, not how often.

Some detectors are trained to avoid duplicates and do not use NMS; the YOLOv3-style head here does. Detection Thresholds then judges accepted boxes against separate reference boxes.

Connect it back to the picture

One pass computes shared features and many candidates at once. Score filtering and class-aware overlap suppression, both post-processing, turn them into a smaller set of detections, and the suppression cutoff trades duplicates against nearby objects.

Full notation and technical reference

The expressions below collect the operations discussed above. You can return here when you want the compact notation.

bx = (col + σ(tx))·s,  by = (row + σ(ty))·s,  bw = pw·e^tw,  bh = ph·e^th
score(k) = σ(to) · σ(tc_k)
keep ⇔ score ≥ 0.50;  suppress ⇔ same class and IoU > 0.45 with a kept box
  • This is a simplified YOLOv3 head: one scale (stride s = 32, a 10 × 7 grid), two hand-chosen anchors (48 × 48 and 64 × 40), three classes with independent sigmoids rather than a softmax.
  • Non-maximum suppression is class-aware and greedy: highest score first, ties by prediction index. It uses predicted boxes, classes and scores, never reference boxes.

Numerical reference

Box A: (2 + σ(0.00)) × 32 = 80.0, (2 + σ(0.45)) × 32 = 83.5, 48 × e^0.12 = 54.1, 48 × e^0.06 = 51.0; score σ(2.50) × σ(3.0) = 0.924 × 0.953 = 0.880. A suppresses F (IoU 0.88) and C suppresses G (IoU 0.57), leaving A, B, C, D and E.

Where this explanation stops

The raw head outputs are written by hand; no trained network or installed YOLO model runs. Other YOLO versions decode and score differently (YOLOv2 used a softmax; anchor-free heads drop anchors and objectness), and some detectors do not use NMS. A stricter cutoff of 0.15 would also suppress E, a real nearby object.

Follow the same idea in the Python or JavaScript notebook →