End-to-End Object Detection with Transformers

Nicolas Carion, Francisco Massa, Gabriel Synnaeve, Nicolas Usunier, Alexander Kirillov, Sergey Zagoruyko

Introduction

Traditional object detection pipelines are often complex, relying on hand-engineered components like anchor generation and Non-Maximum Suppression (NMS) to handle duplicate detections. These heuristics require significant domain expertise and prevent models from being truly end-to-end. DETR (DEtection TRansformer) addresses this by treating object detection as a direct set prediction problem.

Overview of the DETR pipeline, showing the transition from image features to box predictions via a transformer and the bipartite matching loss.

Architecture

The DETR architecture simplifies the detection pipeline into three main components: a CNN backbone, a transformer encoder-decoder, and a set-based loss function.

Backbone and Transformer

A standard CNN (e.g., ResNet-50) extracts a low-resolution feature map from the input image. This map is augmented with positional encodings and fed into a Transformer encoder. The encoder uses self-attention to model global relationships across the entire image.

The Transformer decoder then takes a fixed set of learned positional embeddings, known as "object queries," and attends to the encoder's output. Each query is responsible for identifying an object in a specific learned region of the image.

Detailed DETR architecture showing the backbone, transformer encoder, transformer decoder with object queries, and the final prediction heads.

Bipartite Matching Loss

The "secret sauce" of DETR is its bipartite matching loss. During training, the model uses the Hungarian algorithm to uniquely assign each of the $N$ predicted boxes to a ground-truth object. This one-to-one mapping forces the model to produce unique predictions, eliminating the need for NMS.

Key Insights

  • Global Context: Self-attention allows every part of the feature map to communicate, enabling the model to reason about the entire image simultaneously. This is particularly effective for detecting large objects.
  • Object Queries as Slots: Object queries act as slots that learn to look for objects in different regions. If a slot finds no object, it predicts a "no object" class.
  • Parallelism: Unlike autoregressive models, DETR predicts all objects in parallel, making it efficient for modern hardware.

Results and Performance

DETR achieves performance comparable to highly optimized baselines like Faster R-CNN on the COCO 2017 dataset. Notably, it significantly outperforms Faster R-CNN on large objects (+7.8 $AP_L$), thanks to its global receptive field.

However, DETR currently lags behind in small object detection (-5.5 $AP_S$), likely due to the computational cost of applying transformers to high-resolution feature maps. Additionally, it requires a significantly longer training schedule (300-500 epochs) to converge compared to traditional detectors.

Conclusion

DETR represents a significant shift in object detection, offering a simpler, more extensible architecture that removes the need for legacy heuristics. While challenges remain regarding small object performance and training time, its success in panoptic segmentation demonstrates its potential as a versatile framework for computer vision tasks.

Summary updated

BibTeX
@inproceedings{carion2020end,
  author = {Nicolas Carion and Francisco Massa and Gabriel Synnaeve and Nicolas Usunier and Alexander Kirillov and Sergey Zagoruyko},
  title = {{End-to-End Object Detection with Transformers}},
  booktitle = {European Conference on Computer Vision},
  year = {2020},
  doi = {10.1007/978-3-030-58452-8\_13},
}
Figure