DETR

The paper reframes object detection as direct set prediction with a Transformer encoder-decoder and bipartite matching loss.

Metadata

FieldValue
PaperEnd-to-End Object Detection with Transformers
AuthorsNicolas Carion, Francisco Massa, Gabriel Synnaeve, Nicolas Usunier, Alexander Kirillov, Sergey Zagoruyko
Year2020
VenueECCV 2020
arXiv2005.12872
PaperECVA PDF
Official implementationfacebookresearch/detr
Statusfull note started

One-Line Takeaway

DETR removes anchors, proposal stages, and non-maximum suppression by making object detection a set prediction problem solved with learned object queries and Hungarian matching.

Question

Traditional object detection pipelines often include hand-designed components:

  • anchors;
  • region proposals;
  • non-maximum suppression;
  • heuristic matching rules;
  • task-specific post-processing.

The output of object detection is a set:

where is a class and is a bounding box.

Sets have no canonical order:

The paper asks:

Can object detection be trained end-to-end as direct set prediction?

DETR’s answer:

Main Claim

Object detection can be simplified by combining:

  1. a CNN image backbone;
  2. a Transformer encoder-decoder;
  3. learned object queries;
  4. bipartite matching between predictions and ground truth;
  5. a set loss with a no-object class.

The model predicts a fixed-size set:

where:

  • is the number of object queries;
  • is a class distribution including no-object;
  • is a bounding box.

If an image has ground-truth objects and , the remaining predictions should be no-object.

Architecture Contract

ComponentRole
CNN backboneextracts image feature map
positional encodingpreserves spatial information
Transformer encoderglobally contextualizes image features
object querieslearned slots for possible objects
Transformer decodermaps object queries to object predictions
Hungarian matchingassigns predictions to ground-truth objects
set losstrains unique predictions without NMS

The architectural shift:

Image Backbone

The image is first encoded by a convolutional backbone:

The spatial feature map is flattened into a sequence:

Because flattening destroys explicit 2D coordinates, positional encodings are added:

Then the Transformer encoder processes image tokens:

The CNN provides local visual features; the Transformer provides global interaction.

Transformer Encoder

The encoder applies self-attention over spatial feature tokens:

where:

This lets each spatial location attend to the whole image. The model can reason about object relations and global context, not only local receptive fields.

Object Queries

DETR uses a fixed set of learned object queries:

Each query is a slot that can become one object prediction.

The decoder maps:

Each output slot predicts:

The object queries are not input image patches. They are learned prediction slots.

Transformer Decoder

The decoder has two attention mechanisms:

  1. self-attention among object queries;
  2. cross-attention from queries to image features.

Query self-attention:

Cross-attention:

This lets object slots coordinate with each other and attend to relevant image regions.

The self-attention between object queries helps avoid duplicate predictions:

Set Prediction

The ground truth is a set:

The prediction is a fixed-size set:

The model needs a one-to-one assignment between ground truth objects and prediction slots. DETR uses bipartite matching:

Here is a matching cost based on class and box quality.

This is the core reason DETR does not need NMS. Duplicate predictions are penalized by one-to-one matching.

Matching Cost

A simplified matching cost is:

where:

  • is ground-truth class;
  • is ground-truth box;
  • is predicted class distribution;
  • is predicted box;
  • GIoU measures box overlap quality.

After matching, the training loss is computed on matched pairs plus no-object targets for unmatched slots.

Training Loss

For matched ground-truth/prediction pairs:

For unmatched predictions:

Total loss:

This creates a direct set-level supervision signal.

Why NMS Is Not Needed

Traditional detectors may produce many overlapping boxes and then remove duplicates with non-maximum suppression.

DETR avoids this by training prediction slots with one-to-one matching:

If two slots predict the same object, only one can be matched to it. The other is pushed toward no-object or penalized through the loss.

The decoder query interaction also lets slots coordinate.

Comparison to Faster R-CNN Style Detectors

PropertyFaster R-CNN style detectorDETR
Candidate generationanchors/proposalslearned object queries
Duplicate removalNMSbipartite matching loss
Output formmany dense candidatesfixed-size prediction set
ArchitectureCNN plus detection headsCNN plus Transformer encoder-decoder
Inductive biasstrong spatial detection priorsweaker, more generic set prediction
Trainingmature and efficientslower convergence in original DETR

DETR simplifies the conceptual pipeline, but it pays with training cost and small-object difficulty in the original version.

Comparison to Set Transformer

Set Transformer models unordered input/output structure with attention and learned pooling/query slots. DETR also uses learned slots, but for object detection:

PropertySet TransformerDETR
Main domaingeneric set learningobject detection
Learned queriesPMA seeds/output slotsobject queries
Losstask-dependentHungarian set loss
Outputset-level or slot outputboxes and classes
Key issuepermutation symmetryduplicate-free detection

DETR is an important example of set prediction becoming a concrete vision architecture.

Comparison to Vision Transformer

ViT treats image patches as tokens for classification. DETR uses image feature tokens plus object queries for detection.

PropertyViTDETR
Main input tokensimage patchesCNN feature map tokens
Outputclass token or pooled classset of object boxes/classes
Decodernot central in original ViTcentral
Object slotsnolearned object queries
Lossclassificationset matching and box loss

DETR is not simply ViT for detection. Its key novelty is the set decoder and matching objective.

Evidence Reading

The paper demonstrates that object detection can be handled end-to-end with a Transformer set prediction architecture. The main architectural evidence is conceptual simplification with competitive COCO results.

ClaimEvidence TypeWhat It SupportsCaveat
Detection can be direct set predictionCOCO object detection resultsanchors/NMS are not mandatoryoriginal DETR trains slowly
Object queries learn prediction slotsdecoder attention analysis and performancelearned slots can represent objectsquery semantics are not always stable
Bipartite matching removes duplicatesset loss formulationone-to-one matching replaces NMSmatching cost design matters
Unified extension to panoptic segmentationsegmentation variantarchitecture is flexiblenot always best specialized segmentation model

Benchmark Card

FieldValue
Main task familyobject detection and panoptic segmentation
Input unitimage
Output unitset of boxes, classes, optional masks
Architecture familyCNN plus Transformer encoder-decoder
Core mechanismobject queries and Hungarian matching
Main comparisonFaster R-CNN style detectors
Key issueslow convergence and small-object performance in original version
Not the claimTransformer attention alone solves all detection efficiency issues

Implementation Notes

Number of Queries

The number of object queries is the maximum number of predictions:

If is too small, the model cannot predict all objects. If too large, many slots must learn no-object.

No-Object Class

Each prediction has a no-object class:

This is essential because most query slots do not correspond to objects in most images.

Matching Before Loss

The Hungarian assignment is computed before the final supervised loss:

The matching cost and the training loss are related but not necessarily identical.

Small Objects

Original DETR struggles more with small objects partly because feature resolution and global attention do not provide the same multi-scale priors as FPN-style detectors.

Convergence

Original DETR needs long training compared to mature detectors. Later variants such as Deformable DETR address this with sparse deformable attention and multi-scale features.

Molecular and Scientific Modeling Reading

DETR is a vision paper, but the set prediction pattern is relevant outside vision:

Possible analogues:

  • predicting a set of binding-site residues;
  • predicting multiple ligand poses;
  • detecting objects in microscopy images;
  • extracting entities from scientific figures;
  • predicting candidate interaction pairs;
  • set-valued structure annotations.

The useful idea is not bounding boxes themselves. It is:

For molecular structure tasks, the equivalent output might be coordinates, atom groups, interaction sites, or candidate complexes rather than boxes.

Failure Modes

Query Collapse or Duplication

Object queries can learn redundant behavior if matching and no-object weighting are poorly tuned.

Slow Training

The original design is conceptually simple but not training-efficient.

Small-Object Weakness

Without strong multi-scale design, small objects can be missed.

Matching Cost Sensitivity

Changing the cost weights:

can change assignment and training behavior.

Weak Local Prior

Dense detectors encode many spatial priors. DETR removes many of them, which improves simplicity but can reduce sample efficiency.

Common Misreadings

”DETR is just a Transformer detector.”

The essential idea is not only using a Transformer. It is object detection as set prediction with object queries and bipartite matching.

”No NMS means no post-processing at all.”

There is still decoding and thresholding, but duplicate removal via NMS is not central to the method.

”Object queries correspond to fixed semantic classes.”

Not necessarily. They are learned slots, not class prototypes.

”DETR made all classical detection design obsolete.”

No. Many later detectors reintroduce multi-scale features, sparse attention, denoising, anchors-like priors, or hybrid designs for efficiency.

Later-Paper Checklist

When reading later detection Transformer papers, ask:

  • Are object queries learned, dynamic, denoising, or anchor-like?
  • Is matching Hungarian, one-to-many, or hybrid?
  • Is NMS truly removed?
  • How many queries are used?
  • How is no-object handled?
  • Are multi-scale features used?
  • Is attention dense, deformable, sparse, or local?
  • How fast does it converge?
  • How does it perform on small objects?
  • Are comparisons made at equal schedule and augmentation?

Why It Matters

DETR is important because it changed object detection from a heavily engineered dense prediction pipeline into a set prediction architecture:

This pattern influenced detection, segmentation, tracking, video, multimodal grounding, and general set-output architectures.

Limitations

  • Original DETR has slow convergence.
  • Small-object performance is weaker without later improvements.
  • Dense attention over image features can be expensive.
  • Matching cost design is important.
  • Learned queries are flexible but not always interpretable.
  • Specialized detectors can still outperform it under practical constraints.

Connections