# DETRs Beat YOLOs on Real-time Object Detection

RT-DETR shows a DETR-style detector can beat YOLO in speed and accuracy

Yian Zhao, Wenyu Lv, Shangliang Xu, Jinman Wei, Guanzhong Wang, Qingqing Dang and 2 more · arXiv · 2023-4-17

- **Problem** YOLO detectors need NMS, whose run time and threshold tuning slow them and make them unstable. DETR-style detectors skip NMS but their encoder is too heavy for real-time use.
- **Method** RT-DETR splits the encoder into attention and convolutional fusion.
- **Results** RT-DETR-R50 reaches 53.1% AP at 108 FPS on COCO val2017 on a T4 GPU, beating previously advanced YOLO detectors in both speed and accuracy.

## Why NMS limits real-time YOLO detectors

YOLO detectors are the usual choice for real-time object detection, and most of them finish with Non-Maximum Suppression, which removes overlapping boxes. The cost of NMS depends on how many boxes it has to compare and on two thresholds, a confidence threshold and an IoU threshold. Because the best thresholds shift with whether a use case favours recall or accuracy, tuning them adds a practical burden and makes both speed and accuracy less stable.

DETR-style detectors avoid this step: they predict a one-to-one set of objects with bipartite matching, so no hand-crafted anchors or NMS are needed. Their computation is heavy, though, and that keeps them from meeting real-time needs, so dropping NMS brings them no speed advantage. The central question of the paper is therefore whether a DETR-style model can be made fast enough for real time while still beating the advanced YOLO detectors in both speed and accuracy.

The authors locate the main DETR cost in the encoder. Multi-scale features help training converge, but they lengthen the sequence passed to the encoder, which makes the Transformer encoder the computational bottleneck. On the query side, the existing query selection ranks encoder features by classification score alone, which can pass along features whose boxes are poorly localized.

## Measuring the cost of NMS settings

To test how NMS settings affect run time, the authors count the boxes that survive a confidence filter for YOLOv5 and YOLOv8 at confidence thresholds from 0.001 to 0.25. The more permissive the threshold, the more boxes reach the IoU stage, so the IoU comparisons grow.

With the IoU threshold held at 0.7, YOLOv8 AP drops from 52.9 at confidence threshold 0.001 to 51.2 at 0.05, while its NMS time falls from 2.36 ms to 1.06 ms. So the NMS time depends on both thresholds, and the setting that gives the best accuracy can also carry a larger NMS cost.

These timings come from a T4 GPU with TensorRT FP16, and they cover only the EfficientNMS kernel, not the other kernels of the NMS plugin. The authors point out that the speed figures usually reported for YOLO leave out NMS time, so they understate end-to-end latency.

The end-to-end speed benchmark follows from this. It averages inference time over the images of COCO val2017, uses the NMS thresholds that match each detector's reported accuracy, and excludes I/O and memory copy operations. Applied to the anchor-based YOLOv5 and YOLOv7 and the anchor-free PP-YOLOE, YOLOv6 and YOLOv8, it shows anchor-free detectors needing less NMS time at equal accuracy.

The authors attribute this to anchor-based detectors producing about three times more prediction boxes in the tested set.

## How the hybrid encoder splits the work

The encoder takes the features of the last three backbone stages, S3, S4 and S5, and turns them into a sequence of image features. Before redesigning it, the authors built a family of variants on DINO-Deformable-R50, starting from variant A with the multi-scale Transformer encoder removed. Their reasoning is that high-level features already carry semantic information derived from lower levels, so attention across all concatenated scales repeats work.

The resulting hybrid encoder splits the job into two parts. AIFI runs a single-scale Transformer encoder only on S5, which the authors chose because self-attention on high-level features captures relations between semantic concepts. CCFF handles cross-scale fusion with convolutional blocks in a PANet-style path, so intra-scale attention and cross-scale fusion are no longer computed together.

The authors say lower-level intra-scale attention is unnecessary, because those features lack semantic concepts and would duplicate the high-level interaction.

Each CCFF fusion block has two 1x1 convolutions that adjust channel counts, N RepBlocks built from RepConv that fuse the features, and an element-wise add that combines the two paths. The encoder is written as follows, where Flatten turns S5 into a token sequence and Reshape restores it to the shape of S5. Only the refined S5 enters the fusion with S3 and S4, and the output O is the set of encoder features that the query selection later draws from.

## Which encoder changes pay off

Table 3 reports AP, parameter count and latency for variants A to E, together with DS5, which keeps intra-scale attention only on S5 within variant D. Adding a single-scale encoder to A, which gives variant B, raises AP from 43.0 to 44.9 and latency from 7.2 ms to 11.1 ms. The authors read the gain as evidence that intra-scale interaction matters, and the 54% latency increase as the cost of the single-scale encoder.

Variant C adds cross-scale fusion around the multi-scale encoder, giving 45.6 AP at 13.3 ms, 0.7 AP above B. Variant D decouples the intra-scale and cross-scale work and reaches 46.4 AP at 12.2 ms, 0.8 AP above C with 8% lower latency. Keeping intra-scale attention only on S5 in DS5 cuts latency from 12.2 ms to 7.9 ms, 35% below D, while AP rises by 0.4 to 46.8.

Compared with D, E gains 1.5 AP, adds about 20% parameters, and cuts latency by 24%, which the authors take as a better trade-off between speed and accuracy. All these variants start from DINO-Deformable-R50 and report AP under the 1x configuration, so the rows compare encoder designs on a shared base rather than the final RT-DETR results.

## The uncertainty term in query selection

Earlier DETR variants take the highest-scoring encoder features as initial object queries, and they score features by confidence. The authors argue that a useful feature must be right about both category and location, so ranking by classification alone can let poorly localized features become queries.

The authors define the feature uncertainty as the gap between the localization distribution P and the classification distribution C of an encoder feature, and they treat it as epistemic uncertainty. \\\[ U(\\hat X) = \\lVert P(\\hat X) - C(\\hat X) \\rVert, \\quad \\hat X \\in \\mathbb{R}^{D} \\\] Here \\(\\hat X\\) is an encoder feature in a D-dimensional space, and P and C are the predicted distributions it yields.

The uncertainty is placed in the training loss, \\\[ L(\\hat X, \\hat Y, Y) = L\_{box}(\\hat b, b) + L\_{cls}(U(\\hat X), \\hat c, c) \\\] where the box term acts on the predicted box and the classification term takes the uncertainty as an argument. The uncertainty enters through the loss used for gradient-based optimization, so it shapes what the encoder learns rather than appearing as a separate input at selection time.

The comparison describes the baseline selection as taking the top 300 encoder features by classification score as content queries, with the boxes of those features as initial position queries. Under the 1x configuration on RT-DETR-R50, the uncertainty-minimal scheme raises the share of features with classification score above 0.5 from 0.35 to 0.82, and the share with both scores above 0.5 from 0.30 to 0.67.

Accuracy rises from 47.9 to 48.7 AP on COCO val2017 with the same setup.

## Trading decoder layers for speed

Table 5 reports AP and latency per decoder layer index for RT-DETR-R50 trained with 6x configuration. With the detector that has 6 decoder layers, stopping at the 5th layer gives 53.0 AP instead of 53.1 AP and lowers latency from 9.3 ms to 8.8 ms.

The authors observe that the accuracy difference between neighbouring layers shrinks as the layer index grows, so late layers contribute less. Latency per layer index ranges from 9.6 ms at layer 7 down to 7.0 ms at layer 1.

The authors report the 6-layer setting as the most accurate in this table and treat the number of decoder layers as a run-time setting.

## Accuracy and speed against YOLO and DETR baselines

Table 2 compares RT-DETR with YOLO detectors and DETRs. RT-DETR and the YOLO detectors use a 640 by 640 input, while the other DETRs use 800 by 1333. FPS is measured on a T4 GPU with TensorRT FP16, and the YOLO detectors use their official pre-trained models under the end-to-end benchmark. RT-DETR-R50 reaches 53.1% AP at 108 FPS, and RT-DETR-R101 reaches 54.3% AP at 74 FPS.

Against YOLOv5-L, which has 49.0 AP and 54 FPS in Table 2, RT-DETR-R50 is 4.1 AP higher and runs at 100.0% higher FPS. Against YOLOv8-L, which has 52.9 AP and 71 FPS, RT-DETR-R50 is 0.2 AP higher and 52.1% faster. Against the X models, RT-DETR-R101 is 1.4 AP above YOLOv7-X (52.9 AP, 45 FPS) and 0.4 AP above YOLOv8-X (53.9 AP, 50 FPS), with 64.4% and 48.0% higher FPS respectively.

RT-DETR-R50 is 2.2% AP higher and about 21 times faster in this comparison.

## Objects365 pre-training as a separate setting

The authors pre-train RT-DETR on Objects365 and then fine-tune it on COCO. After this procedure RT-DETR-R50 reaches 55.3% AP and RT-DETR-R101 reaches 56.2% AP. Their COCO-only results are 53.1% and 54.3% AP, so the pre-trained numbers are higher on the same COCO metric. This is a separate setting from the COCO-only models, so the difference should be read as a comparison between two training recipes.

## Limits on small objects and tested scope

The authors name one shortcoming: like other DETRs, RT-DETR performs worse on small objects than the strongest real-time detectors. The authors leave closing this gap to future work.

The speed evidence comes from one setup, a T4 GPU with TensorRT FP16, and the YOLO comparisons rely on the authors' end-to-end benchmark. The ablations are trained under the 1x configuration, while the final detectors use the 6x configuration, so ablation numbers are not the final results. Other DETRs in Table 2 have no speed measurement, so the speed comparison with DETRs is supported only by the DINO-Deformable-DETR comparison.

The discussion suggests that the decoder's similarity to other DETRs could make it possible to distill a lightweight RT-DETR from large pre-trained DETR models, but the paper does not test this.

## Paper info

- **Authors**: Yian Zhao, Wenyu Lv, Shangliang Xu, Jinman Wei, Guanzhong Wang, Qingqing Dang, Yi Liu, Jie Chen
- **Venue**: arXiv · Preprint
- **First published**: 2023-4-17
- **Added**: 2026-11-11
- **Updated**: 2024-4-3
- **Version**: v3
- **arXiv**: 2304.08069
- **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/2304.08069v3) · [PDF ↗](https://arxiv.org/pdf/2304.08069v3)

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

Yian Zhao, Wenyu Lv, Shangliang Xu, Jinman Wei, Guanzhong Wang, Qingqing Dang, Yi Liu, Jie Chen (2023). DETRs Beat YOLOs on Real-time Object Detection. arXiv:2304.08069v3. https://arxiv.org/abs/2304.08069v3

**BibTeX**

```
@misc{zhao2023detrs,
  title = {{DETRs Beat YOLOs on Real-time Object Detection}},
  author = {Yian Zhao and Wenyu Lv and Shangliang Xu and Jinman Wei and Guanzhong Wang and Qingqing Dang and Yi Liu and Jie Chen},
  year = {2023},
  eprint = {2304.08069},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2304.08069v3}
}
```

## Other paper commentary

- [Deformable DETR: Deformable Transformers for End-to-End Object Detection](https://refivu.com/en/papers/e0311cd6-f252-409d-a37d-7b236622ec8e-deformable-detr-deformable-transformers-for-end-to-end.md)
- [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)
- [BPR: Bayesian Personalized Ranking from Implicit Feedback](https://refivu.com/en/papers/e3d177de-9c9b-45b7-bcb5-9ef28bee1dbb-bpr-bayesian-personalized-ranking-from-implicit-feedback.md)
- [Fast and Accurate Deep Network Learning by Exponential Linear Units (ELUs)](https://refivu.com/en/papers/22cdac80-1bc9-4b93-8cf1-9d62eff18d48-fast-and-accurate-deep-network-learning-by-exponential.md)
- [Prototypical Networks for Few-shot Learning](https://refivu.com/en/papers/04a3b578-d356-4e26-95c4-7e6362f71054-prototypical-networks-for-few-shot-learning.md)
- [Explanation in Artificial Intelligence: Insights from the Social Sciences](https://refivu.com/en/papers/97a0e87f-2056-41e6-ba4d-00a7f2aa4ab0-explanation-in-artificial-intelligence-insights-from-the.md)
- [Retrieval-Augmented Generation for Large Language Models: A Survey](https://refivu.com/en/papers/ac45776a-0a09-4a03-a773-f9aa88c71453-retrieval-augmented-generation-for-large-language-models-a.md)
- [MissForest - nonparametric missing value imputation for mixed-type data](https://refivu.com/en/papers/ab5b3748-ade4-4bb9-b016-975b4f82baee-missforest-nonparametric-missing-value-imputation-for-mixed.md)

## Terms in this paper

- [Transformer](https://refivu.com/en/terms/48e8be2570bc-transformer)
- [COCO](https://refivu.com/en/terms/41f3215c4f4a-coco)
- [AP](https://refivu.com/en/terms/476f7c8deadf-ap)
- [Latency](https://refivu.com/en/terms/884c3275b80a-latency)
- [FPS](https://refivu.com/en/terms/e6b895af6e27-fps)
- [non-maximum suppression](https://refivu.com/en/terms/a710b7d63bcd-non-maximum-suppression)
- [DETR](https://refivu.com/en/terms/86857f2f379d-detr)
- [NMS](https://refivu.com/en/terms/c36344a53ebf-nms)
- [RT-DETR](https://refivu.com/en/terms/05c43f3fd4fb-rt-detr)
- [YOLOv5](https://refivu.com/en/terms/15742c2405fd-yolov5)
- [YOLOv8](https://refivu.com/en/terms/ad511ff20847-yolov8)
- [IOU threshold](https://refivu.com/en/terms/6fcdc407795c-iou-threshold)
- [Objects365](https://refivu.com/en/terms/c0164e60f593-objects365)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/2872fb04-6c8b-4f48-a976-80e6dd5be309-detrs-beat-yolos-on-real-time-object-detection)
