Computer Vision Lab Models RetinaNet ResNet-50 FPN

RetinaNet ResNet-50 FPN

One-stage detector, FPN P3–P7, focal loss

Knowledge card: the first one-stage detector to match the accuracy of two-stage detectors, thanks to the Focal Loss, which addresses the huge imbalance between background and foreground anchors. The published value is for the first torchvision weights (V1).

Object detectionKnowledge card

ArchitectureOne-stage detector, FPN P3–P7, focal loss
TaskObject detection
Training dataCOCO 2017
the number of parameters34,014,999
FrameworkPyTorch (torchvision)
File size≈130 MB
LicenceBSD-3-Clause (torchvision code); weights trained on COCO 2017
Where it runsKnowledge card only
Official sourcepytorch.org
Official weightsdownload.pytorch.org

Published metrics (from the official source, not measured by this site)

MetricValueEvaluation dataSource
box mAP36.4COCO val2017Source

Architecture diagram

Architecture diagram RetinaNet ResNet-50 FPNFPNInput imageResNet-50 backbonestages conv2–conv5C3stride 8P3lateral 1×1 + top-down ×2, 3×3C4stride 16P4lateral 1×1 + top-down ×2, 3×3C5stride 32P5lateral 1×1 + top-down ×2, 3×3P6extra levelP7extra levelClass subnet (shared, P3–P7)4 × [Conv 3×3, 256, ReLU]Conv 3×3 → sigmoidK × A outputs (A = 9)Box subnet (shared, P3–P7)4 × [Conv 3×3, 256, ReLU]Conv 3×34 × A offsetsFocal loss + smooth L1training
RetinaNet by Lin et al. (2017): a one-stage detector on FPN (P3–P7) with two heads shared across all levels and 9 anchors per location, trained with the Focal Loss, which weakens the effect of easy examples.
  • Input / output
  • Convolutional layer
  • Composite block
  • Memory / intermediate features
  • Output head
  • Loss / training only

Detailed model explanation

Idea and intuition

Lin and colleagues observed that one-stage detectors were less accurate than two-stage ones, and attributed the main cause to the severe imbalance between examples: each image has tens of thousands of anchors, most of them easy background. These many easy examples dominate the total loss even if each one's loss is small. So they proposed the «Focal Loss», which automatically down-weights well-classified examples, and built RetinaNet to prove that a one-stage detector can match a two-stage one.

Architecture

  • A ResNet backbone with an FPN pyramid at levels P3–P7.
  • Nine anchors per location (3 scales × 3 ratios).
  • Two small subnetworks shared across levels: a classification branch (four 3×3 convolutions then KA outputs with sigmoid) and an independent box regression branch with the same structure.
  • Initialising the bias of the last classification layer so that probabilities start small (\pi=0.01), so the loss does not explode at the start of training.

Mathematical formulation

\mathrm{FL}(p_t) = -\alpha_t\,(1-p_t)^{\gamma}\,\log(p_t),\qquad p_t=\begin{cases}p & y=1\\ 1-p & y=0\end{cases}

When \gamma=0 The loss reduces to weighted cross-entropy. With \gamma=2 (the value chosen in the paper with \alpha=0.25) the weight of an example whose correct probability is 0.9 drops by a factor of (0.1)^2=0.01, so learning focuses on hard examples.

Performance

The torchvision release RetinaNet ResNet-50 FPN (v1): about 34 million parameters and box mAP = 36.4 on COCO val2017.

Strengths and limitations

  • Strength: the focal loss is a general idea that spread to detection, medical segmentation and imbalanced classification problems.
  • Strength: a simple one-stage architecture.
  • Limitation: still relies on anchors and NMS.
  • Limitation: the two prediction heads are relatively heavy on high-resolution levels.

Uses

General detection, the basis for many later detectors, detection in medical images.

Runtime requirements

—

How to load

Not loaded in the lab (knowledge card).

References

  1. T.-Y. Lin, P. Goyal, R. Girshick, K. He, P. Dollár (2017).Focal Loss for Dense Object Detection. arXiv:1708.02002 (ICCV 2017). doi:10.48550/arXiv.1708.02002
  2. T.-Y. Lin, P. Dollár, R. Girshick, K. He, B. Hariharan, S. Belongie (2016).Feature Pyramid Networks for Object Detection. arXiv:1612.03144 (CVPR 2017). doi:10.48550/arXiv.1612.03144
  3. T.-Y. Lin et al. (2014).Microsoft COCO: Common Objects in Context. ECCV 2014 (LNCS 8693). doi:10.1007/978-3-319-10602-1_48

Related algorithms