Settings

Theme
Lite Mode (saves mobile data)

In Lite Mode, animations and videos don't play until you tap them, and their size is shown first. Interactive widgets still work.

Text size

Back up or move your progress →

Part 5: Computer Vision and CNNs

Detection architectures

P5.1240 min●●● AdvancedReviewed Dec 3, 2026

Why this matters for machine learning

Many detectors in use are one of a few designs, or a small change to one. Knowing what each design does about proposals, anchors and duplicates tells you what to expect from it, and what to change when it fails.

  • Instance segmentation (Mask R-CNN) is Faster R-CNN with one more branch, so its masks are only as good as the boxes and the RoI features of this lesson. (P5.13: Semantic and instance segmentation)
  • Open-vocabulary detectors reuse these designs, a backbone with box heads, and replace the fixed class list with text. (P5.14: Foundation models for vision)
  • DETR is an early example of a Transformer used outside text, and its object queries use the cross-attention of the original Transformer. (P7.9: Encoder, decoder and cross-attention, coming soon)

Before this: Object detection basics, The CNN architecture tour, Pooling and receptive fields

After this lesson you can

  • Describe the pipeline of R-CNN, Fast R-CNN and Faster R-CNN, and say what each one fixed in the one before
  • Decode a YOLO-style grid output into boxes, and count the default boxes of an SSD
  • Compute the focal loss for a given probability and say what the focusing parameter does
  • Match predictions to ground-truth boxes by minimising a cost, as DETR does, and say why this removes the need for NMS
  • Read the output of a pretrained detector from torchvision

P5.11 gave you the parts: boxes, IoU, anchors, offsets (tx,ty,tw,th)(t_x,t_y,t_w,t_h), non-maximum suppression (NMS) and average precision. This lesson shows how those parts are put into networks, in the order in which the ideas arrived. Each design mostly fixes a problem of the one before it, so the history is also the easiest way to learn it.

Three questions every detector answers

Whatever its name, a detector has to decide three things:

  1. Where to look. Which candidate boxes will be examined? A list of proposals, a grid, a set of anchors, or a set of learned queries.
  2. What is there, and how to correct the box? A class score and four offsets for each candidate.
  3. How to remove duplicates. Several candidates land on one object (P5.11). NMS removes them, or the training makes them unnecessary.

A detector with a separate first step that proposes regions, and a second step that classifies them, is called two-stage. A detector that goes from the image to the final boxes in one pass, with no proposal step, is one-stage. Which is faster or more accurate is not a rule: the SSD section and the first common mistake below look at it.

Numbers below come from the original papers or the torchvision documentation, with the metric and the hardware the source names. Speeds measured by different groups on different machines are not a fair contest, so use them for the order of magnitude only.

See it: six pipelines on one scene

Pick a detector and step through its stages. Each stage is a box with the shape of its output, and the picture shows what the stage works on. The second view lists all six pipelines side by side.

R-CNN, 2014

Girshick, Donahue, Darrell and Malik. Rich feature hierarchies for accurate object detection and semantic segmentation. CVPR 2014.

Stage 1 of 6, Input image. One image of any size. In this widget the scene has a car and a person.

Where it looks
Selective search, about 2,000 boxes per image
Feature sharing
None: one CNN pass per region
Duplicates
NMS per class
Six detectors on one synthetic scene (a car and a person). Pick a detector, then step through its stages with the buttons or by tapping a stage. White dashed boxes are candidates, blue boxes are the focus of the stage, pink boxes are duplicates before NMS, green boxes are the final detections. Most shapes are (channels, height, width) for one image. The second view shows the stages of all six detectors in one list.

Notice where the duplicates appear: five of the pipelines end with NMS, and DETR is the one that does not.

R-CNN (2014): a CNN for every region

Problem. CNNs had just won image classification (P5.9). How do you use one for detection?

Idea. Girshick, Donahue, Darrell and Malik (CVPR 2014) used a CNN as a feature extractor for a list of region proposals:

  1. Selective search proposes about 2,000 boxes per image. It is a classical method, not a neural network.
  2. Each box is cut out and warped to 227×227227\times227 pixels, the input size of the CNN, whatever its shape.
  3. The CNN gives a 4,096-number feature vector per region.
  4. One linear SVM per class scores each vector, and a linear regressor refines the box with the offsets of P5.11.
  5. NMS per class (P5.11) cleans up the result.

The paper reports a mean average precision (P5.11) of 53.3% on PASCAL VOC 2012 with an AlexNet-style CNN, a relative improvement of more than 30% over the previous best result.

What was wrong. The CNN runs 2,000 times per image, with no sharing of work between overlapping regions. The Fast R-CNN paper reports 47 seconds per image for R-CNN with VGG16 on a K40 GPU. Training was also a pipeline of three separate stages: fine-tune the CNN, fit the SVMs, fit the box regressors.

Fast R-CNN (2015): one pass, then pool

Idea. Girshick (ICCV 2015) ran the CNN once on the whole image and took each region from the shared feature map. A region of interest (RoI) has a different size every time, but the layers after it need a fixed size. The RoI pooling layer solves that: it divides the RoI on the feature map into a fixed grid, 7×77\times7 for VGG16, and takes the maximum of each bin. For example, if an RoI covers 4×64\times6 cells and the output grid is 2×32\times3, each bin holds 2×22\times2 cells, and a bin with the values 2, 6, 3 and 1 becomes 6. Whatever the RoI size, the output has the same size (7×77\times7 for each of the 512 channels in the real network), so one fully connected head can read every region. When the RoI is not a multiple of the grid, the bins differ slightly in size.

Fast R-CNN also trains classification and box regression together with one loss. For one RoI with true class uu (u=0u=0 is background) and a predicted class distribution pp:

L=−log⁡pu+λ [u≥1] Lloc.L=-\log p_u+\lambda\,[u\ge1]\,L_{\text{loc}}.

The bracket is 1 when the RoI is not background and 0 otherwise, so background RoIs have no box loss, as in P5.11. LlocL_{\text{loc}} is the sum over the four offsets of the smooth L1 function, 12x2\tfrac12x^2 when ∣x∣<1|x|<1 and ∣x∣−12|x|-\tfrac12 otherwise, and the paper uses λ=1\lambda=1. It is quadratic near zero, so small errors give small gradients, and linear far away, so one large error cannot dominate.

On a K40 GPU the paper reports training VGG16 9 times faster than R-CNN (84 hours to 9.5 hours) and testing 146 times faster (213 times with truncated SVD), not counting the selective-search proposals (about 1.5 seconds per image on a CPU, from Table 5 of the Faster R-CNN paper). On PASCAL VOC 2012 test with VGG16 it reports 65.7% mAP against 62.4% for R-CNN.

What was wrong. The proposals still come from selective search, which is not part of the network. It is now the slowest step.

Faster R-CNN (2015): the network proposes

Idea. Ren, He, Girshick and Sun (NIPS 2015) added a Region Proposal Network (RPN) that works on the shared feature map. A 3×33\times3 convolution slides over the map, and two 1×11\times1 convolutions on its output give, at every cell, for each of kk anchors, two scores (object or not) and four offsets. With the k=9k=9 anchors of P5.11 and a 40×6040\times60 map, the outputs have shapes (18,40,60)(18,40,60) and (36,40,60)(36,40,60), for 21,60021{,}600 anchors. The anchor labelling of P5.11 (positive above IoU 0.7, negative below 0.3) trains the RPN. The best anchors, moved by their offsets and cleaned by NMS, become the proposals, 300 in the paper. From there on it is Fast R-CNN: RoI pooling, then two heads.

Proposals and detection share one backbone, so the two parts form one unified network. The paper’s main results used a four-step alternating training, and training both parts jointly is also possible, as in torchvision. The paper reports a frame rate of 5 fps, including all steps, for VGG-16 on a K40 GPU.

Faster R-CNN is the design that later two-stage detectors build on. The version in the torchvision library, fasterrcnn_resnet50_fpn, uses a ResNet-50 backbone with a feature pyramid (below), anchors of areas 32232^2 to 5122512^2 with the three ratios of P5.11, RoIAlign, and keeps 1,000 proposals at test time.

RoI pooling and RoIAlign

RoI pooling rounds the coordinates of the RoI to whole feature cells. Rounding moves a coordinate by up to half a cell, which at stride 16 is up to 8 pixels of the image. For a classifier that does not matter much, but a pixel-accurate mask does notice. RoIAlign, introduced in Mask R-CNN (He, Gkioxari, Dollár and Girshick, ICCV 2017), does not round. It samples the feature map at regularly spaced points inside each bin, reads each value by bilinear interpolation from the four nearest cells, and then takes the maximum or the average. The torchvision Faster R-CNN uses it. P5.13 covers Mask R-CNN.

Feature pyramids: one map for every size

A single feature map at stride 16 is a poor fit for both a tiny and a huge object: deep maps have strong meaning but little detail, and early maps the opposite. The Feature Pyramid Network (FPN; Lin, Dollár, Girshick, He, Hariharan and Belongie, CVPR 2017) builds a pyramid of maps from one backbone. A top-down path upsamples the deepest map by 2 and adds it to a 1×11\times1-convolved earlier map (a lateral connection), at each scale, with 256 channels at every level. Every level then has detail and meaning, and each level handles objects of its own size: small objects on the fine maps and large ones on the coarse maps. In torchvision’s Faster R-CNN the pyramid levels have strides 4, 8, 16, 32 and 64 (the last is a max-pool of the one before), with one anchor area per level.

YOLO (2016): look once

Idea. Redmon, Divvala, Girshick and Farhadi (CVPR 2016) turned detection into one regression from the image to a grid of numbers. The image, resized to 448×448448\times448, goes through a network of 24 convolutional layers and 2 fully connected layers, and the output is a 7×77\times7 grid. The cell that holds the centre of an object is responsible for detecting it. Each cell predicts B=2B=2 boxes with five numbers each, (x,y,w,h)(x,y,w,h) and a confidence, and one set of C=20C=20 class probabilities (the 20 classes of PASCAL VOC). The size of the output is S×S×(B⋅5+C)S\times S\times(B\cdot5+C), which is 7×7×307\times7\times30.

  • (x,y)(x,y) is the centre of the box inside its cell, from 0 to 1. (w,h)(w,h) is the size as a fraction of the whole image.
  • The confidence is meant to be Pr⁡(object)×IoU\Pr(\text{object})\times\text{IoU} between the predicted box and the true box.
  • The class probabilities are conditional on there being an object in the cell. The score of a box for a class is confidence times class probability.

Decoding by hand: a cell in row 3 and column 4 (counting from 0) of a 7×77\times7 grid over a 448×448448\times448 image, with box (x,y,w,h)=(0.5,0.5,0.25,0.40)(x,y,w,h)=(0.5,0.5,0.25,0.40), confidence 0.9 and class probability 0.8 for “car”. Each cell is 64×6464\times64 pixels, so the centre is at x=(4+0.5)⋅64=288x=(4+0.5)\cdot64=288 and y=(3+0.5)⋅64=224y=(3+0.5)\cdot64=224, the width is 0.25⋅448=1120.25\cdot448=112 pixels, the height is 0.40⋅448=179.20.40\cdot448=179.2 pixels, and the score is 0.9⋅0.8=0.720.9\cdot0.8=0.72.

The paper’s loss is a sum of squared errors, with λcoord=5\lambda_{\text{coord}}=5 to weight the box coordinates more and λnoobj=0.5\lambda_{\text{noobj}}=0.5 to weight the confidence of empty cells less (most cells are empty), and with the square roots of ww and hh so that an error counts for a small box more than for a large box.

On PASCAL VOC 2007 test (trained on VOC 2007 and 2012) the paper reports 63.4% mAP at 45 frames per second on a Titan X GPU for the base model, and 52.7% mAP at 155 frames per second for the smaller Fast YOLO. The paper lists its limits itself: each cell has only two boxes and one set of class probabilities, which limits the number of nearby objects, and the model struggles with small objects that appear in groups and with unusual aspect ratios.

What “YOLO” means today

Redmon and Farhadi published YOLO9000 (also called YOLOv2; CVPR 2017), which added anchor boxes, and YOLOv3 (a technical report, 2018). Later versions were written by several groups, so check which group made a “YOLO” model, which version, and how it was measured.

SSD (2016): predictions from many map sizes

Idea. Liu, Anguelov, Erhan, Szegedy, Reed, Fu and Berg (ECCV 2016) kept the one-pass idea of YOLO, and predicted from several feature maps of different sizes, with default boxes (the SSD name for anchors) on every cell of every map. For the 300×300300\times300 model the six maps are 38×3838\times38, 19×1919\times19, 10×1010\times10, 5×55\times5, 3×33\times3 and 1×11\times1, and the numbers of default boxes per cell are 4, 6, 6, 6, 4 and 4. The total is

382⋅4+192⋅6+102⋅6+52⋅6+32⋅4+12⋅4=8,732.\begin{aligned} &38^2\cdot4+19^2\cdot6+10^2\cdot6\\ &\quad+5^2\cdot6+3^2\cdot4+1^2\cdot4=8{,}732. \end{aligned}

The scale of the default boxes grows from one map to the next, as sk=0.2+0.9−0.2m−1(k−1)s_k=0.2+\frac{0.9-0.2}{m-1}(k-1) for m=6m=6 maps, a fraction of the image: 0.2, 0.34, 0.48, 0.62, 0.76, 0.9. On a 300×300300\times300 image, the first map looks for boxes of about 60 pixels and the last for about 270. A default box is matched to a ground-truth box when their IoU is above 0.5 (P5.11), and its class scores and offsets are predicted by small 3×33\times3 convolutions on the map. Because almost all of the 8,732 boxes are negative, SSD uses hard negative mining: it keeps only the negatives with the highest loss, at most 3 for each positive.

For 300×300300\times300 input the paper reports 74.3% mAP on VOC 2007 test at 59 FPS (with a batch of 8; 46 FPS with a batch of 1) on a Titan X. Its comparison table lists Faster R-CNN with VGG16 at 73.2% mAP and 7 FPS (batch of 1), so 59 against 7 is not a like-for-like comparison. That table supports the speed half of the rule “one-stage is faster, two-stage is more accurate”, but SSD also has the higher mAP, so it does not show the accuracy half.

Class imbalance and the focal loss

Count the candidates. A dense detector such as RetinaNet looks at about 10510^5 anchors per image, and a handful hold an object. Each easy negative has a small loss, but there are so many that their sum can swamp the few positives. RetinaNet (Lin, Goyal, Girshick, He and Dollár, ICCV 2017) fixed this inside the loss, with the focal loss.

Write ptp_t for the probability the model gives to the true class of an example (pt=pp_t=p for a positive and 1−p1-p for a negative). Cross-entropy is −log⁡pt-\log p_t. The focal loss multiplies it by a factor that is small when the example is easy:

FL(pt)=−(1−pt)γlog⁡pt.\text{FL}(p_t)=-(1-p_t)^{\gamma}\log p_t .

With γ=0\gamma=0 it is the cross-entropy, and the paper found γ=2\gamma=2 to work best. The paper also puts a weight αt\alpha_t in front (0.25 for positives and 0.75 for negatives, with γ=2\gamma=2).

ptp_tcross-entropyfocal loss, γ=2\gamma=2smaller by
0.50.6930.1734 times
0.90.1050.00105100 times

Take 99,990 easy negatives with pt=0.99p_t=0.99 and 10 positives with pt=0.1p_t=0.1 (numbers chosen for the example). With cross-entropy the easy negatives add up to about 1005 and the positives to about 23. With the focal loss they add up to about 0.10 and 18.7, so the few hard examples now decide the loss.

RetinaNet is a one-stage detector with an FPN backbone (levels P3P_3 to P7P_7) and 9 anchors per location, trained with this loss. The paper’s claim was that the extreme class imbalance during training, and not the one-stage design itself, was the central cause of the accuracy gap of dense detectors.

Anchor-free detectors

Anchors have to be designed: sizes, ratios, thresholds. Anchor-free detectors drop them.

  • FCOS (Tian, Shen, Chen and He, ICCV 2019) treats each location of the feature map as a training sample. At every location inside a ground-truth box it predicts the four distances (l,t,r,b)(l,t,r,b) from the location to the left, top, right and bottom sides of the box, a class, and a “center-ness” score that lowers the confidence of locations far from the centre of the box.
  • CenterNet, in the paper “Objects as Points” (Zhou, Wang and Krähenbühl, arXiv 2019), models an object as one point, the centre of its box. A heatmap gives the probability of a centre at each location, the peaks are the objects, and the size is predicted at each peak. The peaks are found with a local maximum search, which replaces NMS.

Another detector is also called CenterNet, by different authors (Duan et al., ICCV 2019, “Keypoint Triplets for Object Detection”). When you see the name, check which one is meant.

DETR (2020): predict a set

Problem. All of the above produce many candidates and rely on hand-designed pieces (anchors, NMS) to turn them into a set of objects. Can a network predict the set directly?

Idea. Carion, Massa, Synnaeve, Usunier, Kirillov and Zagoruyko (ECCV 2020) wrote detection as direct set prediction. A ResNet backbone gives a feature map with 2,048 channels at 1/321/32 of the image size. A 1×11\times1 convolution reduces the channels to d=256d=256 and each map cell becomes one token, with a position encoding added. A Transformer encoder (self-attention among the tokens) and a decoder follow. The decoder takes N=100N=100 learned vectors, the object queries, and each attends to the encoder output and ends as one candidate. A small feed-forward network turns each into a class (or no object, written ∅\varnothing) and a box, given directly as the normalised centre, height and width, with no anchors. The Transformer itself is taught in Part 7: self-attention in P7.2, and the encoder, the decoder and cross-attention in P7.9.

How training works. The network always outputs 100 predictions, and an image has few objects. The ground truth is padded with ∅\varnothing up to 100. Hungarian matching finds the one-to-one assignment between predictions and ground truths with the smallest total cost. In the paper the cost of giving a ground truth (ci,bi)(c_i,b_i) the prediction jj is

−p^j(ci)+Lbox(bi,b^j),-\hat p_j(c_i)+L_{\text{box}}(b_i,\hat b_j),

where LboxL_{\text{box}} combines the L1 distance of the boxes and the generalised IoU loss, weighted 5 and 2 in the paper’s experiments. Then the loss is computed for the matched pairs: the negative log-probability of the class and the box loss for real objects, and the negative log-probability of ∅\varnothing for the unmatched predictions (down-weighted by a factor of 10 for class imbalance, as the paper says).

A worked example. To keep it small, take 3 predictions and 2 ground truths, and a simplified cost: −p^(class)+5⋅∥box error∥1-\hat p(\text{class})+5\cdot\lVert\text{box error}\rVert_1 (no generalised IoU). Boxes are (cx,cy,w,h)(c_x,c_y,w,h) as fractions of the image. Ground truth A is a dog at (0.30,0.40,0.20,0.30)(0.30,0.40,0.20,0.30) and B is a cat at (0.70,0.60,0.30,0.40)(0.70,0.60,0.30,0.40). Predictions 1 and 2 are both near the dog (probabilities 0.80 and 0.60 for dog) and prediction 3 is near the cat (0.70 for cat). The cost matrix, with ground truths in columns, is

A (dog)B (cat)pred 1−0.703.80pred 2−0.203.30pred 33.95−0.50\begin{array}{c|cc} & \text{A (dog)} & \text{B (cat)}\\\hline \text{pred 1}&-0.70&3.80\\ \text{pred 2}&-0.20&3.30\\ \text{pred 3}&3.95&-0.50 \end{array}

There are 6 ways to give each ground truth its own prediction. The cheapest is dog with prediction 1 and cat with prediction 3, with total cost −0.70−0.50=−1.20-0.70-0.50=-1.20. The next, dog with prediction 2 and cat with prediction 3, costs −0.70-0.70. Prediction 2 gets no ground truth, so its target is ∅\varnothing. It is a duplicate of prediction 1, and training teaches it to say “no object”. That is how DETR learns not to produce duplicates, and why it needs no NMS: one object, one prediction, enforced by the loss. The Python cell below runs all six assignments.

For a ResNet-50 backbone on COCO val, the paper’s Table 1 gives DETR 42.0 AP, equal to its tuned Faster R-CNN-FPN baseline (42.0, trained with the same long schedule and the GIoU loss) and above the standard baseline (40.2). DETR is weaker on small objects (AP for small objects 20.5 against 26.6) and stronger on large ones (61.1 against 53.4). DETR was trained for 500 epochs, which is long.

Go deeper Why a set loss and not a per-anchor loss

An anchor-based detector turns “the set of objects” into a classification problem on a fixed set of anchors, by a rule that decides which anchors are positive (IoU above a threshold). That rule is a hand-made guess, and it gives several positives for one object, which NMS must clean up. DETR lets the network and the loss decide: the matching is recomputed in every training step from the current predictions, so the prediction that is closest to a ground truth gets it. In return, the matching is a step that no anchor-based detector has, and it has its own cost weights to tune.

Using a pretrained detector

In practice you rarely train a detector from scratch (P5.10 explains fine-tuning). torchvision offers detectors with weights trained on the COCO dataset. The code below shows the interface and was run with torchvision 0.24.1 on the machine used for this lesson. It builds the model without weights, to show shapes only, and does not download anything.

import torch
from torchvision.models.detection import (
    fasterrcnn_resnet50_fpn)

model = fasterrcnn_resnet50_fpn(
    weights=None, weights_backbone=None)
model.eval()

img = torch.rand(3, 480, 640)  # (C,H,W), 0-1
with torch.no_grad():
    out = model([img])         # a list

print(out[0].keys())
print(out[0]["boxes"].shape)
print(out[0]["labels"].dtype)
print(out[0]["scores"].shape)

Output:

dict_keys(['boxes', 'labels', 'scores'])
torch.Size([100, 4])
torch.int64
torch.Size([100])

The input is a list of images, each a float tensor (C,H,W)(C,H,W) with values in [0,1][0,1], of any size. The output is a list with one dictionary per image: boxes of shape (N,4)(N,4) in the corner format (x1,y1,x2,y2)(x_1,y_1,x_2,y_2) in pixels of the input image, labels with the class indices, and scores in [0,1][0,1], sorted from high to low. With random weights the 100 boxes are meaningless, and 100 is the default limit on detections per image.

With the COCO weights (weights="DEFAULT", a download of about 160 MB when first used) use the category list in weights.meta["categories"] to turn label indices into names. The defaults are a score threshold of 0.05 (P5.11), NMS at IoU 0.5 per class and at most 100 detections, and the torchvision documentation reports 37.0 box AP on COCO val2017 for these weights (the COCO average over IoU thresholds from 0.5 to 0.95, P5.11).

Depth: three ways to see it

Intuition

A detective needs suspects before asking questions. R-CNN asks a helper for 2,000 suspects and interviews every one separately. Fast R-CNN takes one photograph of the whole scene and looks at the suspects in it. Faster R-CNN trains the helper to work from the same photograph. YOLO and SSD do not ask for suspects: they walk over a grid and ask at every square “is anyone here?”. DETR hands 100 detectives one case each and requires them to agree on who takes which person, so no two work on the same one.

The picture breaks at the training: a network does not learn from interviews, but from a loss on boxes and offsets, and the matching of DETR is a calculation done outside the network.

Math

Focal loss, with αt=α\alpha_t=\alpha for a positive and 1−α1-\alpha for a negative (α=0.25\alpha=0.25 and γ=2\gamma=2 in the paper):

FL(pt)=−αt(1−pt)γlog⁡pt.\text{FL}(p_t)=-\alpha_t(1-p_t)^\gamma\log p_t .

DETR matching over one-to-one assignments σ\sigma, solved by the Hungarian algorithm. The loss is then computed with the matched pairs:

σ^=arg⁡min⁡σ∑iC(yi,y^σ(i)).\hat\sigma=\arg\min_\sigma\sum_i\mathcal{C}(y_i,\hat y_{\sigma(i)}).

Code

For matching, the SciPy function linear_sum_assignment solves the assignment problem for sizes where trying every assignment is impossible, and on the cost matrix of the worked example it returns the same assignment as the cell below.

Try it in Python

The cell finds the DETR matching of the worked example by trying all the assignments.

Hungarian matching by brute force

Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).

Change the box of prediction 2 so that it is far from both objects and watch what the matching does, and change the 5 in the cost to 0 to see what the class probabilities alone would pick.

Common mistakes

Quiz

Check your understanding

  1. What does Fast R-CNN change compared with R-CNN, and why does it make the detector faster?

  2. In the focal loss with γ=2\gamma=2, an easy negative has pt=0.9p_t=0.9. How does its loss compare with the cross-entropy loss?

  3. Why does DETR not need non-maximum suppression?

Exercises

  1. An SSD has feature maps of 20×2020\times20, 10×1010\times10 and 5×55\times5 with 6 default boxes per cell. How many default boxes does it have?
    Show answer400⋅6+100⋅6+25⋅6=3,150400\cdot6+100\cdot6+25\cdot6=3{,}150.
  2. A YOLO-style detector with a 13×1313\times13 grid, B=3B=3 boxes per cell and 80 classes gives a tensor of what size? Count the numbers with the formula of this lesson.
    Show answer13⋅13⋅(3⋅5+80)=169⋅95=16,05513\cdot13\cdot(3\cdot5+80)=169\cdot95=16{,}055 numbers.
  3. DETR gives each of 5 ground-truth boxes its own prediction out of 100 (ignoring the padded “no object” targets). In how many ways can this be done, and why does the Hungarian algorithm matter?
    Show answer100⋅99⋅98⋅97⋅96=9,034,502,400100\cdot99\cdot98\cdot97\cdot96=9{,}034{,}502{,}400 ways, so trying all of them (as the cell above does for 3⋅2=63\cdot2=6) is not possible. The Hungarian algorithm finds the cheapest assignment in a time that grows with the cube of the size, without trying them all.

Next: P5.13 adds a mask inside each box and a label for every pixel: semantic and instance segmentation, with FCN, U-Net and Mask R-CNN.

Key takeaways

  • Every detector answers three questions: where to look (proposals, a grid, anchors or queries), how to classify and correct each candidate, and how to remove duplicates.
  • R-CNN ran a CNN on about 2,000 warped proposals. Fast R-CNN ran the CNN once and pooled each region from the shared map. Faster R-CNN replaced the proposal method with a Region Proposal Network that scores anchors on the same map.
  • One-stage detectors skip proposals. YOLO version 1 outputs a 7×7×307\times7\times30 grid, and SSD predicts from default boxes on six maps, 8,732 for a 300×300300\times300 input.
  • A dense detector such as RetinaNet sees about 100,000 anchors per image, almost all easy background. The focal loss −(1−pt)γlog⁡pt-(1-p_t)^\gamma\log p_t with γ=2\gamma=2 shrinks easy examples: at pt=0.9p_t=0.9 it is 100 times smaller than cross-entropy.
  • FPN gives every scale a strong feature map. FCOS and CenterNet predict from points, with no anchors.
  • DETR predicts a set of 100 boxes with a Transformer. Hungarian matching gives each ground truth one prediction and trains the rest to say no object, so it needs no NMS.
Found a mistake? Tell us