RetinaNet

On this page 7

RetinaNet is a one-stage object detection network that predicts object classes and bounding boxes directly from a dense grid of anchors, using focal loss to handle the extreme imbalance between background and object locations. In computer vision, it marked the point where a single-pass detector first matched the accuracy of two-stage detectors such as Faster R-CNN on the COCO benchmark.

Introduced in 2017 by researchers at Facebook AI Research, RetinaNet combines a ResNet backbone, a feature pyramid network and two small convolutional subnetworks. Its lasting contribution to artificial intelligence is less the architecture than the loss function: focal loss has since been adopted by many detectors, segmentation models and dense prediction systems.

How RetinaNet detects objects in a single pass

RetinaNet processes an image in one forward pass, without a separate region proposal step. The backbone extracts features, the feature pyramid builds maps at several scales, and two heads run on every pyramid level to classify anchors and refine their coordinates.

At each spatial position of each pyramid level, the network places nine anchor boxes: three aspect ratios (1:2, 1:1 and 2:1) multiplied by three scales. For a typical input of about 800 pixels on the short side, this produces roughly 100,000 anchors per image, of which only a few dozen overlap a real object.

The table below lists the main components and what each contributes to the final detection.

ComponentFunctionTypical configuration
BackboneExtracts hierarchical image featuresResNet-50 or ResNet-101
Feature pyramid networkCombines deep semantics with fine resolutionLevels P3 to P7, 256 channels
Classification subnetPredicts class probability per anchorFour 3×3 conv layers, sigmoid output
Box regression subnetPredicts offsets from anchor to objectFour 3×3 conv layers, four outputs per anchor
Post-processingRemoves duplicates and low scoresScore threshold 0.05, NMS at IoU 0.5
Main components of the RetinaNet architecture

The two subnets share weights across all pyramid levels but not with each other. The classification head uses independent sigmoid outputs for each class rather than a softmax, which lets the model treat every class as a separate binary decision against background.

Focal loss and the class imbalance problem

Focal loss is a modified cross-entropy loss that down-weights well-classified examples so training concentrates on hard ones. Dense detectors face an imbalance of about 1,000 background anchors for every positive anchor, and with standard cross-entropy the many easy negatives dominate the gradient even though each contributes only a small loss.

The loss multiplies cross-entropy by the factor (1 – p_t) raised to gamma, where p_t is the predicted probability of the correct class. When an anchor is already confidently classified, this modulating factor approaches zero, and its contribution almost disappears. A second weight, alpha, balances positive and negative examples.

ParameterTypical valueEffect when increased
Gamma2.0 (tested range 0 to 5)Stronger suppression of easy examples
Alpha0.25 for positivesMore weight on the foreground class
Prior probability0.01 at initializationStabler early training
Positive IoU threshold0.5Fewer but cleaner positive anchors
Negative IoU thresholdBelow 0.4More anchors treated as background
Effect of the focal loss parameters

The prior initialization matters as much as the loss itself. The final classification bias is set so every anchor starts with a foreground probability of about 0.01; without it, the flood of background anchors produces a very large loss in the first iterations and training can diverge.

RetinaNet compared with other detectors

RetinaNet sits between the two-stage R-CNN family and fast single-shot detectors in the design space. It keeps the simple pipeline of a one-stage model but reaches accuracy that previously required a region proposal network and a second refinement stage.

DetectorStagesAnchorsMain strength
Faster R-CNNTwoYes, in the proposal networkHigh accuracy, flexible second stage
Single Shot MultiBox DetectorOneYesFast inference on modest hardware
RetinaNetOneYes, nine per locationAccuracy close to two-stage models
YOLO (recent versions)OneOften anchor-freeReal-time speed on edge devices
DETROne, set-basedNoNo hand-designed NMS or anchors
RetinaNet and related object detection approaches

On COCO, the original ResNet-101 model reached about 39 to 40 percent mean average precision, which exceeded contemporary two-stage results. Modern detectors have since surpassed it, yet RetinaNet remains a standard baseline in research libraries because it is simple, well understood and easy to reproduce.

Training and deployment in practice

Practitioners usually start from pretrained weights and fine-tune on their own data. Default settings from the reference implementation transfer well, but anchor scales, image size and the score threshold should match the objects in the target domain.

SituationRecommended choiceReason
Many small objectsLarger input size, keep P3 levelFine levels capture small instances
Unusual object shapesAdjust anchor aspect ratiosBetter initial anchor matching
Limited labeled dataFreeze early backbone stagesReduces overfitting
Tight latency budgetResNet-50 backbone, smaller inputLower compute per image
Crowded scenesTune NMS threshold carefullyAvoids suppressing true neighbors
Configuration choices for common situations

Typical training uses stochastic gradient descent with momentum, a learning rate warm-up and horizontal flip augmentation. Inference speed depends heavily on hardware and input size; on a modern data center GPU, a ResNet-50 model processes images at roughly 10 to 30 frames per second.

Limitations and common mistakes

RetinaNet inherits the weaknesses of anchor-based design. Its behavior depends on hand-chosen anchor shapes and IoU thresholds, and it still needs non-maximum suppression, which can remove correct boxes when objects overlap heavily.

  • Ignoring anchor coverage: objects much smaller than the smallest anchor are rarely matched during training.
  • Skipping the bias prior: training becomes unstable or collapses toward predicting background.
  • Reading focal loss as a cure-all: it addresses foreground-background imbalance, not imbalance between rare and common object classes.
  • Expecting real-time speed on CPUs: the dense heads on five pyramid levels are costly without acceleration.

For new projects, anchor-free detectors such as FCOS and transformer-based models often offer better accuracy or simpler tuning. RetinaNet remains valuable as a reliable reference point and as a clear illustration of why loss design matters in dense prediction.

In everyday language

RetinaNet is a program that finds objects in a photo and draws a box around each one. It looks at the whole image only once. That makes it fairly fast.

The hard part is that most of a photo is empty background. Imagine a teacher grading 1,000 tests where 999 are easy. If every test counts the same, the teacher learns little. RetinaNet’s trick, called focal loss, tells the model to spend its effort on the hard cases. The easy background spots count for almost nothing.

Seen in the real world

A team inspecting aerial images of solar farms needs to find cracked or dirty panels. Each drone image is 4,000 pixels wide, and a damaged panel may cover only a small patch. The team fine-tunes a RetinaNet model with a ResNet-50 backbone on about 3,000 labeled images, keeping the fine P3 pyramid level and adding a narrow anchor ratio for long panel rows.

Because most of each image is healthy panels and grass, a standard loss would let the model ignore rare defects. With focal loss, the detector reaches a recall of about 90 percent on damaged panels in validation. Inspectors now review only flagged images, which cuts manual review time by more than half while keeping a person in the loop for the final decision.