DETRs Beat YOLOs on Real-time Object Detection
- Publication
- CVPR 2024Conference
- First submitted to arXiv
- arXiv:2304.08069
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{objectdetectionrtdetr2023,
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.08069}
}
In April 2023, authors from Baidu and Peking University posted a paper on arXiv whose title, DETRs Beat YOLOs, claims that DETR beats YOLO at real-time object detection.
Their model is called RT-DETR (Real-Time DEtection TRansformer). It reads a 640×640 photo and outputs 300 predictions, each made of a box, a class and a score; to use them, you just drop the low-scoring boxes with a score threshold, and no NMS follows. It is going after YOLO's jobs, such as the object tracking, video surveillance and self-driving cars the paper lists at the start, which have to process dozens of images per second.
At the time, that title was a bold claim. The most accurate DETR in the paper's Table 2 is DINO, whose ResNet-50 version reaches 50.9 AP on COCO but manages only 5 images per second on a T4 GPU (with 800×1333 input). YOLO's large models also reach 52 or 53 AP on COCO, at dozens of images per second and up.
To say that DETR wins, you first have to settle how YOLO's speed is measured. YOLO's output is only usable after NMS, and whether NMS time is counted, and at which thresholds, changes the measured speed a lot. The paper's first step is to put NMS back on the stopwatch; then it goes back and breaks down where DETR's time goes.
Problem Definition
How Much Time Does NMS Take?
YOLO guesses boxes at every position of its feature maps. For a 640×640 input, YOLOv8 has 80×80 + 40×40 + 20×20 = 8,400 positions across three feature maps at strides 8, 16 and 32, with one box per position; YOLOv5 places 3 anchors at each position, which makes 25,200. Several positions near the same object all report boxes, so NMS (non-maximum suppression) is needed to clear out the duplicates.
NMS has two thresholds. A confidence threshold first removes boxes whose scores are too low; then, within each class, NMS keeps the highest-scoring box, deletes the boxes whose IoU with it exceeds a threshold, and repeats this on the boxes that remain. IoU is the area of the intersection of two boxes divided by the area of their union.
So how much work NMS does depends on how many boxes pass the confidence threshold. On the same input, the authors counted how many boxes YOLOv5 and YOLOv8 have left at different confidence thresholds. The horizontal axis is the confidence threshold and the vertical axis the number of boxes; blue is the anchor-based YOLOv5 and orange the anchor-free YOLOv8:

At a confidence threshold of 0.001, YOLOv5 keeps over 9,000 boxes and YOLOv8 over 3,000; raise the threshold to 0.25 and both are down to a few hundred. At every threshold, YOLOv5 has more boxes than YOLOv8.
Next, the authors measured YOLOv8's AP and the NMS execution time on COCO val2017. NMS uses TensorRT's efficientNMSPlugin and runs on a T4 GPU with TensorRT FP16:
| Confidence threshold | IoU threshold | AP | NMS time (ms) |
|---|---|---|---|
| 0.001 | 0.5 | 52.1 | 2.24 |
| 0.001 | 0.6 | 52.6 | 2.29 |
| 0.001 | 0.7 | 52.9 | 2.36 |
| 0.001 | 0.8 | 52.8 | 2.46 |
| 0.01 | 0.7 | 52.4 | 1.73 |
| 0.05 | 0.7 | 51.2 | 1.06 |
Start with the first four rows. With the confidence threshold fixed at 0.001, raising the IoU threshold from 0.5 to 0.8 increases the NMS time from 2.24 to 2.46 ms. The higher the IoU threshold, the fewer boxes each round deletes, and the more rounds have to run. AP is highest at 0.7.
Now the three rows with the IoU threshold fixed at 0.7. Raising the confidence threshold from 0.001 to 0.05 cuts the NMS time from 2.36 to 1.06 ms, by more than half, while AP drops from 52.9 to 51.2.
The best result, 52.9 AP, comes at confidence 0.001 and IoU 0.7, and this setting has the second-longest NMS time in the table. If YOLO wants that AP, it has to pay that time; to save time, it has to give up some AP.
The times in the table cover only part of the work. efficientNMSPlugin contains several kernels, including EfficientNMSFilter, RadixSort and EfficientNMS, and Table 1 lists only EfficientNMS.
The appendix also shows YOLOv8-L's predictions under several threshold settings. With too low a confidence threshold, a pile of extra boxes appears in the image; with a low IoU threshold, objects that occlude each other get deleted as duplicates, and with a high one, overlapping duplicates stay. The authors find the confidence threshold reasonably easy to tune and the IoU threshold hard to set accurately.
Yet when YOLO reports speed, it usually measures only the model itself, without NMS (§3.1). NMS is missing from the speed table, while the AP is computed with NMS attached and a very low confidence threshold.
An End-to-End Stopwatch
So the authors set up an end-to-end benchmark (§3.2):
- The data is COCO val2017, measured image by image and averaged, because NMS time varies with the input.
- YOLO gets TensorRT's NMS plugin attached, with the thresholds each model used to obtain its reported AP. The official speed-test script's default for YOLOv8 is confidence 0.001, IoU 0.7 and at most 300 output boxes.
- I/O and memory copies are excluded; measurements run on a T4 GPU with TensorRT FP16.
Timed with this stopwatch, the authors found that at comparable accuracy, anchor-free YOLOs are faster than anchor-based ones, because the latter output more boxes and NMS takes longer. Among the models they tested, the anchor-based ones had three times as many boxes, consistent with the 25,200 versus 8,400 computed above.
Where Is DETR Slow?
DETR has no NMS, so that time is saved from the start. Its trouble lies in the model itself.
Multi-scale features help DETR converge faster and reach higher accuracy, at the cost of a suddenly much longer sequence for the encoder to process. Deformable attention had already cut the computation, yet the encoder still became the computational bottleneck. The authors cite an analysis from D²ETR, which found that in Deformable DETR the encoder accounts for 49% of the GFLOPs but contributes only 11% of the AP.
So how should the encoder be cut? If you remove it entirely, how much accuracy is lost? If you keep only part of it, which part should stay?
Solution
The Big Picture
RT-DETR is made up of three parts, a backbone, a hybrid encoder and a decoder. The backbone provides the features of its last three stages, , and ; the hybrid encoder turns them into a sequence of image features; query selection picks a fixed number of features from that sequence as the starting points of the queries; and the decoder refines these queries layer by layer and outputs classes and boxes.
Taking a 640×640 image, we drew the size at each stage:

Next, we follow this figure from the encoder all the way to the decoder.
The Encoder's Compute
First, count the positions in each of the three feature levels. For a 640×640 input, S3, S4 and S5 are 80×80, 40×40 and 20×20; once flattened, each position is a token, 8,400 in all, and S3 alone holds 76% of them. Ordinary self-attention pairs every token with all the tokens in the same level, which gives over 40 million pairs in S3 alone; doing it only in S5 takes just 160,000 pairs.
The authors compare accuracy and latency across a set of encoder variants. From left to right, the figure shows five encoders, A to E, and the three arrows under each box stand for the three feature levels. SSE is a single-scale Transformer encoder, MSE a multi-scale Transformer encoder, and CSF cross-scale fusion:

Every variant starts from DINO-Deformable-R50, swaps in RT-DETR's lighter data loading and decoder, and trains for 12 epochs. The table has one extra row, , which has the same structure as D except that SSE processes only S5:
| Variant | What the encoder does | AP | Params (M) | Latency (ms) |
|---|---|---|---|---|
| A | No encoder; the three levels are concatenated directly | 43.0 | 31 | 7.2 |
| B | The three levels share one single-scale Transformer layer, each doing intra-scale interaction, then get concatenated | 44.9 | 32 | 11.1 |
| C | B's results are concatenated and fed into a multi-scale Transformer encoder | 45.6 | 32 | 13.3 |
| D | Intra-scale interaction goes to a single-scale Transformer, cross-scale fusion to a PANet-style structure | 46.4 | 35 | 12.2 |
| Same as D, but only S5 does intra-scale interaction | 46.8 | 35 | 7.9 | |
| E | AIFI + CCFF, which is RT-DETR's design | 47.9 | 42 | 9.3 |
Going down row by row:
- A → B: AP rises by 1.9 and latency by 54%. Intra-scale interaction helps, but self-attention in every level is expensive.
- B → C: AP rises by another 0.7 and latency by another 20%. Cross-scale interaction helps too, but the multi-scale encoder costs even more.
- C → D: Separating intra-scale interaction from cross-scale fusion adds 0.8 AP and actually cuts latency by 8%.
- D → : Keeping self-attention only in S5 cuts latency from 12.2 to 7.9 ms, a 35% reduction, and AP still rises by 0.4.
- D → E: Switching to AIFI and CCFF adds 1.5 AP and 20% more parameters, with 24% less latency.
Step 4 removes the self-attention in S3 and S4, the more than 40 million pairs we just computed, and latency falls by 4.3 ms. Compared with A, which has no encoder at all, the final E adds only 2.1 ms of latency and scores 4.9 AP higher.
Why keep only S5? The authors argue that high-level features carry the semantics of objects, so self-attention at this level can capture the relationships between different objects and concepts in the image and help later modules locate and recognize them; low-level features lack semantics, so intra-scale interaction there is redundant and may even duplicate or confuse the high-level interaction. The row supports this view, computing that much less and still scoring 0.4 AP higher.
AIFI: Self-Attention Only in S5
The paper writes the hybrid encoder in three lines:
AIFI is simply one standard Transformer encoder layer. S5 is flattened into a sequence of 400 tokens, Q, K and V all come from it, and after self-attention and the feed-forward network it is folded back into a 20×20 shape. The sizes follow Table A in the appendix: an embedding dimension of 256, 8 heads, a feed-forward width of 1024, and a single layer. The official code also adds a 2D sin-cos positional encoding to Q and K.
CCFF: Cross-Scale Fusion by Convolution
CCFF follows PANet's route, first top-down and then bottom-up, and at each step fuses the features of two adjacent levels into a new level. The fusion block (Figure 5) concatenates the features of the two adjacent levels and splits them into two paths, each going through a 1×1 convolution; one path then goes through N RepBlocks, and finally the two paths are added element-wise. RT-DETR uses N = 3.
RepBlock is made of RepConv, the RepVGG-style design with several branches during training that merge into a single 3×3 convolution at inference. After fusion the output still has three levels, the same sizes as the input, all with 256 channels; flattened and concatenated, they form a sequence of 8,400 features.
This number is the same as YOLOv8's 8,400 boxes earlier, because both predict on three grids at strides 8, 16 and 32. From here the two part ways. YOLO hands the boxes from every position to NMS, while RT-DETR picks only 300 of them for the decoder.
Picking 300 Queries
DETR's original queries are a set of learnable vectors that have nothing to do with the input image, and they are hard to optimize. Later methods pick them from the encoder output instead. The two-stage version of Deformable DETR and DINO both select the top K features by classification score to initialize the queries (DINO uses them only as positional queries). RT-DETR takes K = 300, uses the selected features as content queries, and uses the boxes they predict as the starting points of the positional queries.
The selection itself is a single topk: each of the 8,400 positions takes its highest class score, and the top 300 are kept. The official code also has a linear layer and a LayerNorm before the prediction heads, and the box prediction adds each position's anchor.
The trouble lies in what the selection is based on. A high classification score says that this position looks like it has an object, but it doesn't guarantee that the predicted box is accurate. A detector has to get both the class and the box location right; if only the classification score counts, poorly localized features may get selected too, and the decoder has to refine from a poor starting point.
The authors call this mismatch uncertainty, define it as the gap between the predicted distributions of localization and classification, and put it into the classification loss so that both are minimized together:
Here is the encoder feature, and are the predicted class and box, and and are the annotations.
The formula is abstract; what the official code does is much more concrete. It trains the classification score with Varifocal loss. If a prediction is matched to an annotation in the Hungarian matching, its training target for that class changes from 1 to the IoU between its box and the annotated box; for unmatched predictions, the target is 0. Take three selected features as an example:
| Feature | Matched annotation | IoU of predicted box and annotation | Usual classification target | RT-DETR classification target |
|---|---|---|---|---|
| #1 | dog | 0.45 | 1 | 0.45 |
| #2 | cat | 0.90 | 1 | 0.90 |
| #3 | unmatched | — | 0 | 0 |
Feature #1's box overlaps the dog with an IoU of only 0.45, so its classification score is pulled toward 0.45 instead of being pushed toward 1 as before. Once the classification score is trained to reflect box quality, the top 300 picked by score lean toward features whose boxes are accurate as well. This loss applies both to the 300 predictions selected from the encoder and to the output of every decoder layer.
How well does it work? On COCO val2017, the authors drew the features picked by the two selection methods as a scatter plot. The horizontal axis is the IoU between box and annotation and the vertical axis the classification score, with only points scoring above 0.5 drawn; purple is the new method, green the original selection by classification score, and the curves on the top and right show the point density:

The closer a point is to the upper right, the more likely both its class and its box are correct. The purple points crowd into the upper right; the green points cluster in the lower right, with decent boxes but low classification scores, and there are far fewer of them. Table 4 turns this into proportions (RT-DETR-R50, trained for 12 epochs):
| Query selection | AP | Share with classification score > 0.5 | Share with both > 0.5 |
|---|---|---|---|
| By classification score (original) | 47.9 | 0.35% | 0.30% |
| uncertainty-minimal | 48.7 | 0.82% | 0.67% |
Both proportions more than double, and AP rises by 0.8.
The Decoder: Dropping the Last Few Layers
RT-DETR's decoder copies DINO's almost wholesale, with 6 layers, 300 queries, and deformable attention for cross-attention with 4 sampling points. Training also carries over DINO's denoising exercise, and Table A in the appendix lists the denoising number as 200.
Every decoder layer is followed by its own prediction heads, and during training the output of every layer goes into the loss. So every layer produces a complete set of predictions that can be used directly. At inference, the official code uses eval_idx to choose which layer's output to use; the loop stops at that layer, and the layers after it never run.
The authors trained decoders with 4 to 7 layers, then looked at the results of stopping at each layer during inference (RT-DETR-R50, trained for 72 epochs):
| Layers used at inference | Det4 | Det5 | Det6 | Det7 | Latency (ms) |
|---|---|---|---|---|---|
| 7 | 52.6 | 9.6 | |||
| 6 | 53.1 | 52.6 | 9.3 | ||
| 5 | 52.9 | 53.0 | 52.5 | 8.8 | |
| 4 | 52.7 | 52.7 | 52.7 | 52.1 | 8.3 |
| 3 | 52.4 | 52.3 | 52.4 | 51.5 | 7.9 |
| 2 | 51.6 | 51.3 | 51.3 | 50.6 | 7.5 |
| 1 | 49.6 | 48.8 | 49.1 | 48.3 | 7.0 |
Start with the Det6 column. Dropping from 6 layers to 5 costs only 0.1 AP and saves 0.5 ms; at 4 layers, AP is 52.7 at 8.3 ms. Each extra layer adds about 0.4 to 0.5 ms, and the later the layer, the less it helps AP.
Now compare across the columns. Det6 stopped at layer 4 gives 52.7, the same as Det4 trained with 4 layers from the start; stopped at layer 5 it gives 53.0, 0.1 higher than Det5 trained with 5 layers. In this table, training a 6-layer model and truncating it works about as well as training a shallower model separately. As for 7 layers, the best it reaches is 52.6, worse than 6 layers.
How wide is the range? Using only layer 1 takes 7.0 ms, and using all 6 layers takes 9.3 ms. Answering a user on GitHub, the author mentioned that the parts of the current RT-DETR are fairly balanced, with the time going mainly to the backbone and the decoder (RT-DETR #266, 2024-04). And since the number of decoder layers can be adjusted without retraining, it amounts to an extra speed knob.
The officially released models use it this way. The scaled-down RT-DETR-R50 in Table B of the appendix halves the RepBlock channels, and stopping the same model at layers 2 through 6 ranges from 50.3 AP at 154 FPS up to 52.2 AP at 125 FPS; YOLOv8-M in the same table has 50.2 AP at 97 FPS. For RT-DETR-R50-m in the official repository (51.3 AP, 145 FPS), the config file says eval_idx: 2, which uses the output of layer 3.
Discussion
Against YOLO and DINO
Table 2 compares RT-DETR with YOLO's L and X sizes. The data is COCO val2017; RT-DETR and YOLO both use 640×640 input, and the other DETRs use 800×1333; FPS is measured on a T4 with TensorRT FP16 at batch size 1, and YOLO uses official weights with NMS attached, following the end-to-end benchmark above:
| Model | Params (M) | GFLOPs | FPS | AP | APS |
|---|---|---|---|---|---|
| YOLOv6-L | 59 | 150 | 99 | 52.8 | 34.4 |
| YOLOv7-X | 71 | 189 | 45 | 52.9 | 36.9 |
| YOLOv8-L | 43 | 165 | 71 | 52.9 | 35.3 |
| YOLOv8-X | 68 | 257 | 50 | 53.9 | 35.7 |
| DINO-Deformable-DETR-R50 | 47 | 279 | 5 | 50.9 | 34.6 |
| RT-DETR-R50 | 42 | 136 | 108 | 53.1 | 34.8 |
| RT-DETR-R101 | 76 | 259 | 74 | 54.3 | 36.0 |
A few pairs to compare:
- RT-DETR-R50 vs. YOLOv8-L: AP is 53.1 vs. 52.9, only 0.2 higher; speed is 108 vs. 71 FPS, or 9.3 vs. 14.1 ms per image. GFLOPs are a bit lower too, 136 vs. 165.
- RT-DETR-R101 vs. YOLOv8-X: 0.4 AP higher, at 74 vs. 50 FPS.
- RT-DETR-R50 vs. YOLOv6-L: only 0.3 AP higher, at 108 vs. 99 FPS, a much smaller gap.
Small objects are where RT-DETR loses. RT-DETR-R50's APS is 34.8, 0.5 below YOLOv8-L's 35.3; R101's 36.0 is 0.9 below YOLOv7-X's 36.9. The authors list this among their limitations and call it a weakness DETRs share.
The training conditions differ too. RT-DETR's backbone is first pretrained on ImageNet, then trained on COCO for 72 epochs. The R50 weights loaded by the official code are a ResNet50-vd trained by PaddleClas with knowledge distillation (ssld_v2); PaddleClas's model table lists its ImageNet top-1 as 83.0%, against 76.5% for the original ResNet-50. The YOLOv7 and YOLOv8 in the table, by contrast, are trained from scratch, and YOLOv10's paper states in its appendix that it trains from scratch just like YOLOv8, YOLOv7 and YOLOv9. This table compares whole systems, backbone weights and training recipes included.
With additional pretraining on Objects365 and fine-tuning on COCO, R18, R50 and R101 reach 49.2, 55.3 and 56.2 AP, which is 2.7, 2.2 and 1.9 higher than with COCO alone (Table C in the appendix).
Against DINO, RT-DETR-R50 is 2.2 AP higher, at 108 vs. 5 FPS, about 21 times faster. This, too, is a whole-system comparison. DINO's input is 800×1333, 2.6 times the pixels of 640×640, and it trains for 36 epochs, while RT-DETR trains for 72. To see how much the hybrid encoder itself saves, go back to the matched comparison in Table 3.
In June 2024, a user on GitHub questioned this comparison (RT-DETR #349). Measuring on an RTX 3090, the user found that RT-DETR's FLOPs were about half of DINO's, consistent with the paper, yet RT-DETR ran only about twice as fast; the user also pointed out that the two use different data augmentation and backbones. The author replied that DINO's speed has to be measured under the conditions in which it reaches the paper's accuracy, that they had tested on V100, T4 and 3090 with the expected results, and that across different models, only comparing final accuracy and speed is fair. After a few rounds, each side kept its original position.
How Should the Thresholds Be Set?
In October 2023, a user asked a very practical question on GitHub (RT-DETR #77). The end-to-end benchmark uses the validation thresholds, confidence 0.001 and IoU 0.7; in production, though, people usually use a confidence threshold of around 0.1 to filter out most background boxes first, which makes NMS much faster and shrinks RT-DETR's speed advantage.
The author replied that with a 0.1 threshold, YOLO's mAP can't reach the reported number. Measuring accuracy at 0.001 and speed at 0.1 assumes two states the model can't be in at the same time; RT-DETR's score threshold only filters the output, so its speed at deployment is the same as at evaluation.
Both sides have a point. Table 1 happens to supply the middle ground, where raising the confidence threshold from 0.001 to 0.05 cuts the EfficientNMS time by 1.3 ms and AP by 1.7. On the other hand, RT-DETR's 53.1 is also computed by handing all 300 outputs per image to the evaluation code; applying a score threshold at deployment can only keep AP flat or lower it, and the difference is that its speed stays the same.
When reading these two tables, also keep in mind that the YOLO times in Table 2 include the whole NMS plugin while Table 1 lists only one of its kernels, so the times in the two tables can't be subtracted directly.
On Another Machine
In February 2024, another user used trtexec to compare RT-DETR-R18 with YOLOv8s plus NMS on three graphics cards (RT-DETR #214). On an RTX 4090 it was 1.065 vs. 1.90 ms, a ratio in line with the paper; on a T4, however, it was 5.6 vs. 5.4 ms, with YOLOv8s slightly faster; and on a laptop RTX 3050, RT-DETR was almost 2 ms slower.
The author replied that the paper's YOLO speed is an average over the 5,000 images of val2017, because NMS time varies with the number of boxes that pass the score threshold; also, RT-DETR uses more kinds of operators than YOLOv8, and different TensorRT versions support them to different degrees. The thread reached no conclusion. End-to-end speed depends on the hardware, the software versions and the data, so for your own use case you still have to measure it once on your own machine.
Duplicate Boxes Still Turn Up
RT-DETR removed NMS, but duplicate boxes haven't disappeared entirely. In July 2024, a user reported that the same object occasionally gets several boxes, and others had also run into almost perfectly overlapping boxes with different or even identical classes (RT-DETR #379). The author suggested choosing the score threshold carefully. Another user said that the scores of these duplicates are often very close, so a threshold can't separate them; attaching NMS yourself fixes it at the cost of extra time, and the problem is rarer when the model is well trained.
Conclusion
The RT-DETR paper does two things. First, it measures YOLO's speed together with NMS, using the thresholds that produced the reported AP; second, it takes DETR apart to see where the time goes and where it can be saved. Its conclusions come down to roughly these:
- NMS time follows the thresholds. For YOLOv8 on a T4, raising the confidence threshold from 0.001 to 0.05 cuts the EfficientNMS time from 2.36 to 1.06 ms and drops AP from 52.9 to 51.2.
- Keep self-attention only in S5. Removing the intra-scale interaction in S3 and S4 cuts latency by 35% without losing AP; with AIFI and CCFF, the encoder is 2.3 AP higher than variant C, the multi-scale Transformer encoder, with 30% less latency.
- Make the classification score reflect box quality. Using IoU as the classification target for query selection adds 0.8 AP in the 12-epoch setting.
- The decoder can be truncated. Each layer costs about 0.5 ms, and a 6-layer model stopped at layer 4 is as accurate as one trained with 4 layers from the start.
Next time you read a real-time detector's speed table, first check whether NMS is included and which thresholds were used, then which card and which TensorRT version. RT-DETR's speed doesn't change with the threshold, but small-object AP and backbone pretraining belong in the comparison too.
This end-to-end benchmark was later adopted by YOLOv10, and RT-DETR itself became the starting point for later real-time DETRs. At the end of 2024, DEIM changed how RT-DETRv2 and D-FINE are trained so that these models learn faster.