- Introduced by
- Nicolas Carion
- Year
- 2020
- Type
- Neural network architecture
- Family
- Deep Learning, Object Detection
What does it do?
DETR (Detection Transformer) is an end-to-end object detection framework introduced by Carion et al. in 2020.
It treats detection as a direct set prediction problem solved with a transformer encoder-decoder, so the network outputs its full set of detections in one pass. This removes hand-crafted components such as anchor boxes and non-maximum suppression.
The intuition behind the method
DETR does not frame object detection as regression or classification over dense grids or anchor boxes. It frames it as predicting a set of objects. A CNN backbone encodes the image into a feature map, and a transformer encoder-decoder then predicts a fixed-size set of detections, each with coordinates and a class label. A bipartite matching loss assigns each ground-truth object to exactly one prediction, so duplicate detections are discouraged during training and the pipeline needs no non-maximum suppression step at inference.
History
Nicolas Carion and colleagues introduced DETR in 2020, and the work was published at the European Conference on Computer Vision (ECCV). It showed that a transformer could carry out object detection end-to-end.
When to use it
Choose DETR when you want a detector without anchor box design or non-maximum suppression, and when you can afford a long training schedule. Its fixed set of queries caps the number of objects it can output per image, so it fits scenes where that cap is comfortably above the expected object count. For latency-critical production systems, benchmark DETR on your own hardware and input sizes before committing to it, since its speed relative to Faster R-CNN depends on the backbone, resolution and implementation. It is also a weaker choice when small objects matter, because performance on small objects is notably weaker than that of traditional detectors.
Limitations and considerations
- Inference speed depends on backbone, input resolution and implementation, and reported comparisons with Faster R-CNN vary, so latency should be measured on your own hardware rather than assumed from published results
- Convergence requires many more training iterations than CNN-based detectors and careful hyperparameter tuning
- Performance on small objects is notably weaker than that of traditional detectors
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Removes hand-designed components such as anchor boxes and non-maximum suppression, so the detection pipeline has fewer design choices to tune
- The loss is defined over sets of predictions with bipartite matching, so training and inference share one end-to-end formulation without a separate duplicate-removal step
- The transformer encoder uses attention over all image features, so each prediction can draw on global context rather than only local windows
Applications
- Detecting a bounded number of objects of interest per image, where the fixed query count is a reasonable design fit
- Research comparisons of set-prediction detectors against anchor-based and region-proposal detectors
- Pipelines where removing non-maximum suppression and anchor design simplifies deployment and experimentation
How it works
How it works
A convolutional neural network, typically a ResNet, extracts feature maps from the input image. Spatial resolution is reduced while the features become more semantically rich.
The CNN feature map is flattened, combined with positional encodings, and processed by a transformer encoder. This builds contextual representations that draw on the whole image rather than on local neighbourhoods.
The decoder uses a fixed set of learnable object queries. Each query attends to the encoder features and produces one candidate object, which is then passed to the prediction heads.
Linear heads on each decoder output predict a class probability and a bounding box. A special 'no object' class lets the model leave some queries unused, so the number of detected objects can vary per image. At inference, a query is kept as a detection when its highest non-background class probability exceeds a chosen score threshold. Results are evaluated with COCO-style average precision (AP) metrics.
Common pitfalls
- The number of object queries is a fixed hyperparameter that caps how many objects can be predicted per image. Setting it too low reduces recall in crowded scenes, and it should be chosen with the dataset's object counts in mind
- The matching cost used for bipartite assignment must combine classification and box-localization terms consistently with the loss. A mismatch can produce poor object assignments and unstable training
- DETR usually needs a longer training schedule than CNN baselines, and a schedule copied from a CNN detector may stop before the model has converged. The CNN backbone is commonly given a lower learning rate than the transformer; the original paper gives the specific settings
Frequently asked questions
Why does DETR not use anchor boxes like Faster R-CNN?
Anchor boxes are predefined shapes whose scales and aspect ratios must be chosen by hand. DETR instead predicts boxes directly from learned object queries, so it does not depend on a fixed anchor layout. This removes one set of design choices from the pipeline.
What is bipartite matching and why is it necessary?
Bipartite matching assigns each ground-truth object to exactly one prediction using the Hungarian algorithm. This discourages duplicate detections of the same object during training. The matching cost combines classification and localization terms.
Why is DETR slower than Faster R-CNN?
DETR applies transformer attention over the image feature tokens in its encoder, and its decoder attends from each object query to those features. Faster R-CNN instead uses a Region Proposal Network before its second-stage classifier. Self-attention cost grows with the number of tokens, so the cost depends on feature map size, but this page does not quantify the difference; check the original paper's speed comparison for timing details.
Related methods
Sources
Carion, N., Massa, F., Synnaeve, G., Usunier, N., Kirillov, A., & Zagoruyko, S. (2020). End-to-end object detection with transformers. In European Conference on Computer Vision (pp. 213-229). Springer, Cham.
Open DOI reference