Skip to content
mlmentorship

Object detection: Faster R-CNN, YOLO, DETR

Localize and classify objects in an image. The three main architectural families: two-stage proposal-based, one-stage grid-based, and transformer-based.

Published · 7 min read ·Specialist ·Intermediate

Visual quick review

Contrast how proposal- and grid-based detectors collapse redundant candidates with NMS against how DETR learns distinct prediction slots through one-to-one matching and emits its set without NMS.

Learning objective

Classic proposal and dense detectors resolve duplicates after prediction

Classic proposal and dense detectors resolve duplicates after prediction Faster R-CNN proposals and the dense predictions used by RetinaNet and most YOLO versions can produce three overlapping boxes for one object. At inference, non-maximum suppression keeps the highest-scoring box and removes the two lower-scoring duplicates. CLASSIC PROPOSAL / DENSE PIPELINE many scored candidates for one object 0.94 · highest overlap is expected, not three objects INFERENCE · NMS keeps 0.94 one kept box
DETR learns distinct prediction slots before direct inference Four learned object-query slots predict a dog box, a car box, and two no-object values in parallel. During training only, Hungarian bipartite matching assigns at most one query to each ground-truth object. At inference, the slots directly emit the final set and there is no NMS gate. DETR · SET-PREDICTION PIPELINE fixed learned query slots predict in parallel Q1 Q2 Q3 Q4 dog box car box no object no object TRAINING ONLY · one-to-one Hungarian match INFERENCE · direct final set dog + car · no NMS gate
the left lane resolves scored overlaps with inference-time NMS. The right lane assigns targets one-to-one during training and predicts a set at inference. That objective discourages duplicates; it does not guarantee perfect uniqueness.
Check: Which duplicate-resolution operation is used during inference in each pictured pipeline? Which matching exists only in training?
Full explanation 7 min read
Reading depth

Object detection constructs a scored set of boxes; candidate generation, training assignment and duplicate handling are separate choices.

Summary

Where are candidates generated, assigned to target objects, and converted into the final prediction set? Declare box coordinates, classes, score meaning and the maximum output count. Background or no-object predictions are not additional objects.

Two-stage: Faster R-CNN (Ren et al., 2015)

Extract backbone features, generate RPN objectness/box proposals, then classify and refine selected regions. RoI pooling quantizes regions; RoIAlign samples aligned features without that coordinate quantization. Proposal and final duplicate handling belong to the specified implementation. Mask R-CNN adds a mask head; it does not change this comparison into a speed guarantee.

One-stage: YOLO (Redmon et al., 2015 onward), RetinaNet (Lin 2017)

Dense heads predict from feature locations without a separate region-classification stage. YOLO v1’s grid differs from v3’s multiscale predictions and later anchor-free or assignment variants. Name the version and head, not merely the family. RetinaNet uses focal loss to reduce easy-background dominance. Anchor-free parameterization does not imply NMS-free inference.

Set prediction: DETR (Carion et al., 2020)

Learned object queries attend to encoded image features and predict boxes/classes, including no-object. During training, one-to-one matching assigns targets to distinct slots; unmatched queries receive the specified no-object loss. Inference does not match against unavailable ground truth. Original DETR emits slots without an NMS stage, but training incentives do not mathematically forbid all duplicate predictions.

Learning objective

Training-time matching and inference-time duplicate removal are different operations

Training assignment and inference suppression solve different problemsTraining matches predictions to ground-truth supervision. Inference removes redundant predicted boxes without access to ground truth.Assignment consumes truth; inferencesuppression consumes predictionsTraining: match predictions to truthsupervisiontruthpred.Inference: predictions only; suppressredundancy-pred.
Read it this way: Training matches predictions to ground-truth supervision. Inference removes redundant predicted boxes without access to ground truth. Does inference NMS require ground-truth boxes?
Reference drawing

Learning objective

Training-time matching and inference-time duplicate removal are different operations

Training assignment and inference suppression solve different problemsTraining matches predictions to ground-truth supervision. Inference removes redundant predicted boxes without access to ground truth.Assignment consumes truth; inferencesuppression consumes predictionsTraining: match predictions to truthsupervisiontruthpred.Inference: predictions only; suppressredundancy-pred.
Derivation
Classic proposal and dense detectors resolve duplicates after prediction Faster R-CNN proposals and the dense predictions used by RetinaNet and most YOLO versions can produce three overlapping boxes for one object. At inference, non-maximum suppression keeps the highest-scoring box and removes the two lower-scoring duplicates. CLASSIC PROPOSAL / DENSE PIPELINE many scored candidates for one object 0.94 · highest overlap is expected, not three objects INFERENCE · NMS keeps 0.94 one kept box
DETR learns distinct prediction slots before direct inference Four learned object-query slots predict a dog box, a car box, and two no-object values in parallel. During training only, Hungarian bipartite matching assigns at most one query to each ground-truth object. At inference, the slots directly emit the final set and there is no NMS gate. DETR · SET-PREDICTION PIPELINE fixed learned query slots predict in parallel Q1 Q2 Q3 Q4 dog box car box no object no object TRAINING ONLY · one-to-one Hungarian match INFERENCE · direct final set dog + car · no NMS gate
the left lane resolves scored overlaps with inference-time NMS. The right lane assigns targets one-to-one during training and predicts a set at inference. That objective discourages duplicates; it does not guarantee perfect uniqueness.
Check: Which duplicate-resolution operation is used during inference in each pictured pipeline? Which matching exists only in training?
Read it this way: Training matches predictions to ground-truth supervision. Inference removes redundant predicted boxes without access to ground truth. Does inference NMS require ground-truth boxes?

Work the assignment

Matching costTarget oneTarget two
Query one12
Query two2100

Taking query one’s cheapest target first leaves total cost . Swapping assignments gives , the global minimum. Matching cost selects pairs; subsequent training losses and their weights must be defined separately. This equal-count toy omits unmatched-query costs.

Change the deployment requirement

Meet a request deadline

New task: complete an edge request within thirty milliseconds.

Picture and change: a hypothetical serial trace takes four ms preprocessing, eighteen ms model time and ten ms postprocessing.

Check: total time is 32 ms, so the model-only timing hides a miss. A compatible twelve-ms model gives 26 ms on that same assumed trace. Measure accuracy, memory and actual end-to-end tails; component percentiles cannot simply be added.

Use when: service constraints change; family labels alone do not establish FPS or quality.

Prioritize small or crowded objects

New task: one-pixel localization errors now determine usefulness.

Picture and change: shift a two-by-two box one pixel horizontally: IoU becomes .

Check: the same shift of a twenty-by-twenty box gives . Evaluate small/crowded slices and consider resolution, multiscale features and duplicate policy. Text-conditioned classes additionally need grounding checks; a vocabulary match is not localization evidence.

Use when: the object distribution or class vocabulary differs from the benchmark average.

Reconstruct the distinction

Does using no anchors remove duplicate-resolution requirements?

Reasoned answer

No. Parameterization, training assignment and inference selection are independent design axes. An anchor-free head can still use NMS.

Key shared components

Bounding box parameterization

Declare center/size versus corner coordinates, normalization, resizing and padding transforms before losses or evaluation.

IoU loss

IoU compares intersection to union; disjoint boxes have zero IoU. GIoU adds enclosure geometry; DIoU uses center distance; CIoU includes an aspect-ratio term. These are different objectives, not interchangeable names for ordinary coordinate L1 loss.

Non-Maximum Suppression (NMS)

Specify score ordering, class grouping, IoU threshold and maximum detections. Aggressive suppression can remove distinct nearby objects. See the anchor/NMS owner for exact decode and threshold arithmetic.

Anchors

Anchors provide reference geometry for offsets; anchor-free heads use other coordinate conventions. Neither alone specifies assignment or postprocessing.

Datasets and metrics

VOC, COCO, Open Images and LVIS use different classes and evaluation conventions. Use the official evaluator and state IoU thresholds, interpolation, area slices, class averaging and maximum detections. AP integrates a ranked precision-recall curve under that protocol; duplicates do not universally reduce AP in every score order.

Production considerations

FPN supplies multiscale features; test whether the small-object slice improves. Deformable DETR, DINO and related variants change computation or training; retain versioned comparisons. Open-vocabulary models add text-conditioned class support, not guaranteed grounding for arbitrary new objects.

Common pitfalls

An unspecified FPS number omits hardware, resolution, batching and postprocessing. Keep annotation policy, augmentation and class/area coverage visible when comparing detectors.