Exercises — Object detection (R-CNN, YOLO, SSD)
This page is your self-testing gym for Object Detection. Every problem is graded by cognitive level (L1 → L5). Read the problem, try it yourself, THEN open the solution. Every number here is machine-verified.
Before we start, one shared picture of the vocabulary so no symbol sneaks up on you.
The figure below turns those two box formats into one picture: the black box on the left is drawn in corner format (top-left and bottom-right dots), and the red box on the right is the same idea in center format (center dot plus the width and height arrows). Keep it in mind — every exercise below picks one of these two formats, and mixing them up is the fastest way to a wrong answer.

Level 1 — Recognition
Exercise 1.1 — Which paradigm?
For each, name the detector family: (a) generates ~2000 region proposals with Selective Search, then classifies each; (b) divides the image into an grid and predicts everything in one forward pass; (c) uses default boxes on several feature maps of different resolution.
Recall Solution
(a) R-CNN (two-stage, region-based). (b) YOLO (single-stage, grid regression). (c) SSD (single-shot, multi-scale default boxes).
Exercise 1.2 — Output tensor size
YOLO v1 uses grid , boxes per cell, classes. What is the shape of the output tensor?
Recall Solution
Each cell outputs numbers (5 = per box). Shape numbers total.
Level 2 — Application
Exercise 2.1 — Compute an IoU
Box A (corner format) . Box B . Compute the IoU.
Recall Solution
Step 1 — intersection rectangle. Take the inner edges (see red box in figure): Width , height , so intersection area .
Step 2 — each area. , .
Step 3 — union. Union = sum minus the double-counted overlap:
Step 4 — divide.

Exercise 2.2 — Disjoint boxes
Box A , Box B . What is their IoU?
Recall Solution
Intersection edges: , . Width . A negative width means the boxes do not touch, so we clamp the area to .
Exercise 2.3 — Bounding-box regression targets
Proposal . Ground truth . Compute the regression targets .
Recall Solution
Why divide the center offset by and ? Picture two proposals hunting the same object: a tiny px-wide box and a huge px-wide box. Suppose both need to shift right by px to reach the target. For the tiny box, px is a huge move (twice its own width!); for the huge box, px is a tiny nudge (4% of its width). If the network had to output the raw , it would need to know the box size to judge whether that's a big or small correction. Dividing by converts the shift into "how many box-widths do I move?" — a scale-free number ( for the tiny box, for the huge one). Now the same predicted means the same relative adjustment no matter how big the proposal is, so one set of weights works for all box sizes. That's the same reason use a ratio inside the log rather than a raw pixel difference.
Why the log? Width/height are always positive; learning of a ratio lets the network predict any real number and exponentiate back to a guaranteed-positive size.
Level 3 — Analysis
Exercise 3.1 — Why in YOLO's size loss?
Recall the hat convention: is the true width and is the network's predicted width. Box P has true width px, box Q has true width px. Both are predicted px too large ( and ). Compare the raw squared error against the square-root error for each box.
Recall Solution
Raw error — identical for both: Raw loss says a 10px slip on a tiny box is just as bad as on a giant box — wrong intuition.
Square-root error: Now the small box is penalized harder. That's the point: a 10px error swallows half a 10px object but is negligible on a 200px object. The compresses large values so equal absolute slips produce smaller loss on big boxes.
Exercise 3.2 — Proposal counting
Faster R-CNN: image , backbone stride , anchors per position. How many raw proposals? After NMS keeps the top 300, what fraction survives?
Recall Solution
Rule for non-integer feature sizes: a strided/padded convolution reports output cells (you cannot have half a cell), so we floor. Feature map width , height . Positions . Surviving fraction Over 98% of proposals are discarded — most anchors are background or redundant overlaps, exactly what NMS + objectness filtering are for.
Level 4 — Synthesis
Exercise 4.1 — Run NMS by hand
Three "dog" boxes with confidences: conf , conf , conf . IoUs: , , . Run NMS with threshold . Which boxes survive?
Recall Solution
Step 1. Sort by confidence: . Step 2. Pick highest, → keep it. Remove any box overlapping above :
- → suppress .
- → keep for now. Step 3. Next survivor is → keep it. No boxes left to compare. Survivors: . was a near-duplicate of the stronger .
Exercise 4.2 — Full YOLO class-specific confidence
Cell (3,4) box 1 predicts confidence . The cell predicts and . Compute the final class-specific score for dog and for cat. Which class label does this box emit if the decision threshold is ?
Recall Solution
Final score : Dog → emit "dog". Cat → suppressed. The confidence ("is something here + does my box fit") multiplies the per-class belief ("given something, it's a dog"), giving one honest number.
Level 5 — Mastery
Exercise 5.1 — Design an SSD anchor budget
An SSD head attaches to feature maps of sizes , , , , , . The number of default boxes per cell for these layers is respectively. Compute the total number of default boxes. Then explain why the map uses fewer boxes per cell yet contributes the most boxes overall — and which object sizes it targets.
Recall Solution
Multiply cells × boxes-per-cell for each layer: Total: Why the interpretation: the map is high resolution / early → each cell sees a small receptive patch → it detects small objects, and there are cells, so even at only 4 boxes/cell it dominates the count. The map is low resolution / deep → one cell sees the whole image → detects large objects, needing just 4 boxes. This resolution ladder is exactly why SSD (unlike single-scale YOLO v1) handles a wide range of object sizes. See Anchor Boxes.
The figure below draws that resolution ladder: read it left-to-right as "deeper in the network". The leftmost red box is the map — biggest grid, smallest receptive patch per cell, so it hunts small objects; the rightmost map is a single cell seeing the whole image, so it hunts large objects. This is the picture behind the count you just computed.

Exercise 5.2 — Weighted no-object confidence loss
A YOLO cell has predicted boxes but no object. Their confidence predictions are , (targets ). With , compute this cell's no-object confidence loss. Then argue why is necessary.
Recall Solution
No-object confidence loss Why down-weight: in a grid almost every cell is background. If each contributed full-weight confidence loss, the gradient would be swamped by "push confidence to 0" signals, and the handful of object cells would be drowned out. rebalances so the rare positive cells still steer learning — the mirror image of which boosts the rare localization signal.
Recall Self-check (cloze)
IoU intersection uses on the ::: top-left / start edges and on the bottom-right / end edges. Width or height of the intersection must be ::: clamped to zero (negative → no overlap). YOLO uses so that equal absolute errors hurt ::: small boxes more than large boxes. NMS is run ::: per class, keeping the highest-confidence box and suppressing overlaps above the IoU threshold. SSD detects small objects on ::: high-resolution (early) feature maps and large objects on deep low-resolution maps.
See also: Non-Maximum Suppression · Intersection over Union (IoU) · Anchor Boxes · Image Classification · Semantic Segmentation · Instance Segmentation