Computer Vision Lab Models DETR (ResNet-50)

DETR (ResNet-50)

CNN backbone + transformer encoder–decoder, 100 object queries

Knowledge card: reformulates detection as set prediction: no anchors and no NMS, and Hungarian matching enforces one prediction per object. The price is long training (500 epochs) and relative weakness on small objects.

Object detectionKnowledge card

ArchitectureCNN backbone + transformer encoder–decoder, 100 object queries
TaskObject detection
Training dataCOCO 2017
the number of parameters≈41M (paper)
FrameworkPyTorch
File size159 MB
LicenceApache-2.0
Where it runsKnowledge card only
Official sourcegithub.com
Official weightsdl.fbaipublicfiles.com

Published metrics (from the official source, not measured by this site)

MetricValueEvaluation dataSource
box AP42.0COCO val2017 (500 epochs)Source

Architecture diagram

Architecture diagram DETR (ResNet-50)memoryInput image3×H×WResNet-502048 × H/32 × W/32Conv 1×1d = 256Flatten + positional encodingHW/1024 tokensTransformer encoder ×6self-attention, 8 headsObject queriesN = 100 learnedTransformer decoder ×6self + cross attentionShared FFN per query3-layer MLP (box) + linear (class)N × (class or ∅, box)cx, cy, w, hHungarian matching losstraining: set prediction
DETR by Carion et al. (2020): a CNN backbone then an encoder–decoder transformer and 100 learned object queries; it predicts the set of boxes directly and is matched to the ground truth with the Hungarian algorithm, so no anchors or NMS are needed.
  • Input / output
  • Convolutional layer
  • Attention / transformer
  • Composite block
  • Embedding / tokens / queries
  • Output head
  • Loss / training only

Detailed model explanation

Idea and intuition

DETR (DEtection TRansformer) reformulated detection as set prediction: the model outputs a fixed number N of predictions (100 in the paper), and they are compared with the ground-truth objects through an optimal «bipartite matching» with the Hungarian algorithm. Since each ground-truth object is matched to only one prediction, the model learns by itself not to duplicate boxes, so there is no need for NMS or anchors.

Architecture

  1. A CNN backbone (ResNet-50) produces a feature map at 1/32 resolution, whose channels are reduced to d=256 and flattened into a sequence.
  2. A transformer encoder with six self-attention layers, with a 2D sinusoidal positional encoding.
  3. A transformer decoder with six layers that receives N learned «object queries», each attending to the others and to the encoder features.
  4. A small FFN per query outputs a class (with a «no object» class ∅) and a normalised box.

Mathematical formulation

The optimal matching between ground-truth objects y and predictions \hat y:

\hat\sigma = \arg\min_{\sigma\in\mathfrak S_N}\sum_{i=1}^{N}\mathcal L_{match}\big(y_i,\hat y_{\sigma(i)}\big)
\mathcal L_{Hungarian} = \sum_{i=1}^{N}\Big[-\log\hat p_{\hat\sigma(i)}(c_i) + \mathbb 1_{c_i\neq\varnothing}\big(\lambda_{L1}\lVert b_i-\hat b_{\hat\sigma(i)}\rVert_1 + \lambda_{giou}\mathcal L_{giou}(b_i,\hat b_{\hat\sigma(i)})\big)\Big]

Performance

According to the official repository, DETR with a ResNet-50 backbone reaches AP = 42.0 on COCO val2017 after a long training schedule (500 epochs).

Strengths and limitations

  • Strength: a simple end-to-end pipeline with no anchors and no NMS.
  • Strength: global attention helps large objects and relations between objects.
  • Limitation: very slow training convergence, which later works such as Deformable DETR and RT-DETR addressed.
  • Limitation: weaker on small objects because the features are single-scale and low-resolution.

Uses

Detection, the basis of the DETR family (Deformable DETR, DINO-DETR and RT-DETR) and query-based segmentation.

Runtime requirements

GPU for training.

How to load

Not loaded in the lab (knowledge card).

References

  1. N. Carion, F. Massa, G. Synnaeve, N. Usunier, A. Kirillov, S. Zagoruyko (2020).End-to-End Object Detection with Transformers. arXiv:2005.12872 (ECCV 2020). doi:10.48550/arXiv.2005.12872
  2. A. Vaswani et al. (2017).Attention Is All You Need. arXiv:1706.03762 (NeurIPS 2017). doi:10.48550/arXiv.1706.03762

Related algorithms