# Deformable DETR: Deformable Transformers for End-to-End Object Detection

Deformable DETR speeds up end-to-end object detection by attending to sparse sampling points

Xizhou Zhu, Weijie Su, Lewei Lu, Bin Li, Xiaogang Wang, Jifeng Dai · arXiv · 2020-10-8

- **Problem** DETR drops hand-built detection parts but needs 500 epochs on COCO to converge. Its attention spreads over every pixel, which also makes high-resolution maps too costly for small objects.
- **Method** Deformable DETR replaces dense attention with deformable attention. Each query looks at a few sampling points around one reference point, placed by learned offsets, so the cost no longer scales with the full pixel count.
- **Results** Deformable DETR reaches 43.8 AP after 50 epochs, compared to 42.0 AP for DETR after 500 epochs on COCO 2017 val. Its small-object AP is 26.4, compared to 20.5 for DETR.

## Why DETR converges slowly and misses small objects

DETR replaced hand-built detection parts, such as anchor generation and NMS, with a Transformer encoder-decoder trained by a set-based Hungarian loss. The cost is slow training: DETR needs 500 epochs on COCO, roughly 10 to 20 times longer than Faster R-CNN. The authors trace this to attention. At initialization the attention is almost uniform over every pixel, so the model needs a long schedule before it learns to focus on sparse, meaningful locations.

Small objects are the second weakness. Detectors usually find small objects on high-resolution feature maps, but the cost of DETR's encoder grows quadratically with the number of pixels. Its self-attention costs \\(O(H^2W^2C)\\), so high resolution quickly becomes unaffordable. DETR's small-object AP is 20.5, which shows the accuracy cost of this limit.

## The key idea: attend to a few learned points

The authors combine two things that each solve half the problem: the sparse sampling of deformable convolution and the relation modeling of Transformers. Each query no longer compares itself with every pixel. It looks at K sampling points placed around one reference point, where K is much smaller than HW. A small fixed number of samples keeps the cost off the full pixel count, and the authors expect this also to ease convergence.

Concretely, the output for query q sums over M attention heads and K sampled keys, reading the value at the reference point plus a learned offset. \\\[ \\mathrm{DeformAttn}(z\_q,p\_q,x)=\\sum\_{m=1}^{M}W\_m\\Big\[\\sum\_{k=1}^{K}A\_{mqk}\\,W'\_m\\,x(p\_q+\\Delta p\_{mqk})\\Big\] \\\] The offsets and the weights both come from one linear projection of z\_q that outputs 3MK channels.

The first 2MK channels are offsets, and a softmax over the remaining MK channels gives weights that sum to one across the K keys. Because p\_q plus an offset is usually fractional, the value is read by bilinear interpolation.

With these choices, the encoder cost becomes \\(O(HWC^2)\\), linear in the number of pixels. In the decoder cross-attention the cost becomes \\(O(NKC^2)\\), which does not depend on the map size HW.

## Multi-scale sampling and the encoder and decoder

The multi-scale version samples L times K points from all feature levels in one pass. Because the points cross levels, the module exchanges information across scales, so the encoder doesn't need a top-down feature pyramid. With one level, one point and an identity projection, the module reduces to deformable convolution.

In the encoder, four feature levels are used: stages C3 to C5 of ResNet, each projected to 256 channels by a 1×1 convolution, plus C6. C6 comes from a 3×3 stride-2 convolution on C5. Each pixel is a query whose reference point is the pixel itself. A learned scale-level embedding is added so that each query knows which level it belongs to.

The decoder keeps its self-attention among object queries and swaps only the cross-attention. The detection head predicts offsets relative to that point, which the authors say ties the decoder attention to the predicted box and speeds convergence.

## Refining boxes and the two-stage variant

Iterative bounding box refinement stacks decoder layers so that each layer refines the boxes predicted by the layer before. The authors borrow the idea from iterative refinement in optical flow estimation. Its gain appears as a cumulative row in the detection table.

The original DETR object queries are not tied to the current image, so the two-stage variant first generates proposals. Every pixel of the multi-scale maps becomes an object query, and the decoder is removed to keep the cost affordable. The top-scoring boxes become region proposals, and no NMS is applied before they go to the second stage.

The proposals then enter the decoder as object queries for refinement.

## Does it converge faster and detect better?

On COCO 2017 val, the default Deformable DETR scored 43.8 AP after 50 epochs, compared to 42.0 AP for DETR after 500 epochs. On small objects it scored 26.4 APS, compared to 20.5 for DETR. So in this table the shorter schedule came with better small-object AP, not a trade-off.

The table has no DETR row at 50 epochs, so the 42.0 AP comparison crosses schedules. A closer control is DETR-DC5 at 50 epochs, which scored 35.3 AP, and 36.2 AP with Focal Loss and 300 object queries. So at equal epochs the gap to DETR-DC5+ is much larger than the gap those two changes make.

Adding iterative refinement raises the default model to 45.4 AP at 50 epochs. The two-stage variant adds a further step to 46.2 AP. These are cumulative rows, so each gain should be read against the row directly above it.

## Which parts of the attention design matter

The ablations use an ImageNet pre-trained ResNet-50 backbone and are scored on COCO 2017 val. With one level and K=1, the model scored 39.7 AP. Adding multi-scale inputs raised it to 41.4 AP, and APS rose from 21.2 to 24.1. The text credits multi-scale inputs with 1.7 points of AP and 2.9 points of APS.

Raising K from 1 to 4, with multi-scale inputs and no cross-level attention, moved AP from 41.4 to 42.3. Turning on multi-scale deformable attention then moved AP from 42.3 to 43.8. The authors read this last step as the value of exchanging information across levels, which the text puts at 1.5 points.

Adding FPN on top gave no gain: 43.8 AP with FPN, 43.9 with BiFPN, and 43.8 without either. The authors take this as evidence that the cross-level exchange already does the job FPN would do.

## Runtime and the cost of deformable attention

Deformable DETR runs at 19 FPS, compared to 12 FPS for DETR-DC5, with 173G FLOPs against 187G. The authors describe this as 1.6 times faster than DETR-DC5. The authors attribute DETR-DC5's slowness to memory access in Transformer attention.

Against Faster R-CNN + FPN, Deformable DETR is 25% slower. Deformable attention still trades that memory access problem for less ordered memory access, so it remains slightly slower than traditional convolution.

## Test-dev results and backbones

On test-dev, Deformable DETR with ResNeXt-101 and DCN scored 50.1 AP without test-time augmentation. With horizontal flip and multi-scale testing, the same model scored 52.3 AP. The ResNet-50 model scored 46.9 AP, and the ResNet-101 model scored 48.7 AP.

These test-dev models also use iterative refinement and the two-stage mechanism. Test-dev numbers come from a different split and different backbones than the ablation rows, so they are not directly comparable to them. EfficientDet-D7 scored 52.2 AP, which is close to the 52.3 AP with test-time augmentation.

## Limitations

The ablations use a ResNet-50 backbone on COCO 2017 val, and the test-dev numbers use other backbones. Experiments use only COCO 2017.

Deformable DETR is 25% slower than Faster R-CNN + FPN. Its deformable attention is still slightly slower than traditional convolution.

## Paper info

- **Authors**: Xizhou Zhu, Weijie Su, Lewei Lu, Bin Li, Xiaogang Wang, Jifeng Dai
- **Venue**: arXiv · Preprint
- **First published**: 2020-10-8
- **Added**: 2026-11-11
- **Updated**: 2021-3-18
- **Version**: v4
- **arXiv**: 2010.04159
- **Category**: cs.CV
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2010.04159v4) · [PDF ↗](https://arxiv.org/pdf/2010.04159v4)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Xizhou Zhu, Weijie Su, Lewei Lu, Bin Li, Xiaogang Wang, Jifeng Dai (2020). Deformable DETR: Deformable Transformers for End-to-End Object Detection. arXiv:2010.04159v4. https://arxiv.org/abs/2010.04159v4

**BibTeX**

```
@misc{zhu2020deformable,
  title = {{Deformable DETR: Deformable Transformers for End-to-End Object Detection}},
  author = {Xizhou Zhu and Weijie Su and Lewei Lu and Bin Li and Xiaogang Wang and Jifeng Dai},
  year = {2020},
  eprint = {2010.04159},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2010.04159v4}
}
```

## Other paper commentary

- [Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation](https://refivu.com/en/papers/178a13b8-5d0e-4448-a1cb-759db558ade3-swin-unet-unet-like-pure-transformer-for-medical.md)
- [The Mythos of Model Interpretability](https://refivu.com/en/papers/28c70275-bdc3-4d2e-8c3b-711d370f197b-the-mythos-of-model-interpretability.md)
- [Learning Transferable Architectures for Scalable Image Recognition](https://refivu.com/en/papers/5559067d-efe6-4393-97f1-bbf1a5119112-learning-transferable-architectures-for-scalable-image.md)
- [UCF101: A Dataset of 101 Human Actions Classes From Videos in The Wild](https://refivu.com/en/papers/a467933a-0520-4f34-b529-6224c8635422-ucf101-a-dataset-of-101-human-actions-classes.md)
- [Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression](https://refivu.com/en/papers/f29df16c-adc4-4f4f-bd28-ea43b995682d-generalized-intersection-over-union-a-metric-and-a.md)
- [FCOS: Fully Convolutional One-Stage Object Detection](https://refivu.com/en/papers/2e08cffe-e9be-4c49-9238-8afaab98cecc-fcos-fully-convolutional-one-stage-object-detection.md)
- [BERTScore: Evaluating Text Generation with BERT](https://refivu.com/en/papers/30f8b3be-d1a1-4c44-9203-702fc98d0cc9-bertscore-evaluating-text-generation-with-bert.md)
- [How transferable are features in deep neural networks?](https://refivu.com/en/papers/cb0b30a7-565d-41f8-bd71-41713c953bea-how-transferable-are-features-in-deep-neural-networks.md)
- [HuggingFace's Transformers: State-of-the-art Natural Language Processing](https://refivu.com/en/papers/226edb36-2edb-4a96-aca3-9909969cdf23-huggingface-s-transformers-state-of-the-art-natural.md)
- [Federated Learning: Challenges, Methods, and Future Directions](https://refivu.com/en/papers/85104455-c32d-4181-89ff-29d70a64be44-federated-learning-challenges-methods-and-future-directions.md)
- [Natural Language Processing (almost) from Scratch](https://refivu.com/en/papers/4ded66b6-2d8b-4f92-9605-511ba715f3f1-natural-language-processing-almost-from-scratch.md)

## Terms in this paper

- [Transformer](https://refivu.com/en/terms/48e8be2570bc-transformer)
- [Object detection](https://refivu.com/en/terms/113bfdb14049-object-detection)
- [ResNet](https://refivu.com/en/terms/ca7e0121c7a8-resnet)
- [Faster R-CNN](https://refivu.com/en/terms/6a6dc13482bb-faster-r-cnn)
- [AP](https://refivu.com/en/terms/476f7c8deadf-ap)
- [FLOPs](https://refivu.com/en/terms/14c405888d5b-flops)
- [focal loss](https://refivu.com/en/terms/55a77da0ac9c-focal-loss)
- [FPN](https://refivu.com/en/terms/ad78e3a6bd84-fpn)
- [DETR](https://refivu.com/en/terms/86857f2f379d-detr)
- [deformable attention](https://refivu.com/en/terms/863041c104f6-deformable-attention)
- [deformable convolution](https://refivu.com/en/terms/2caf738356d7-deformable-convolution)
- [COCO 2017](https://refivu.com/en/terms/d7d6496ff636-coco-2017)
- [object queries](https://refivu.com/en/terms/59f62c82701a-object-queries)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/e0311cd6-f252-409d-a37d-7b236622ec8e-deformable-detr-deformable-transformers-for-end-to-end)
