Back to paper library
Paper notesarXiv 2023CVPR 2024

RT-DETR

Putting NMS on the Clock

Original paper

DETRs Beat YOLOs on Real-time Object Detection

Paper authors

Yian Zhao · Wenyu Lv · Shangliang Xu …

Show all 8 authors

Yian Zhao · Wenyu Lv · Shangliang Xu · Jinman Wei · Guanzhong Wang · Qingqing Dang · Yi Liu · Jie Chen

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}
}
On this page

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:

Bar chart. The horizontal axis shows the confidence thresholds 0.001, 0.005, 0.01, 0.05, 0.1 and 0.25; the vertical axis is the number of remaining boxes, from 0 to 10,000. The blue bars are YOLOv5, at a little over 9,000 at 0.001, falling step by step to about 600 as the threshold rises; the orange bars are YOLOv8, at a little over 3,000 at 0.001, falling to about 400. At every threshold, blue is higher than orange.
Figure 2 from the paper, Zhao et al., excerpted from page 3 of the v3 PDF. The number of boxes left for the same input at different confidence thresholds.

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:

Table: Compiled from Table 1 of the paper. The original table has two halves, one with a fixed confidence threshold and one with a fixed IoU threshold; here they are merged into one. The table doesn't state the YOLOv8 size; its 52.9 AP matches YOLOv8-L in Table 2.
Confidence thresholdIoU thresholdAPNMS time (ms)
0.0010.552.12.24
0.0010.652.62.29
0.0010.752.92.36
0.0010.852.82.46
0.010.752.41.73
0.050.751.21.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, S3S_3, S4S_4 and S5S_5; 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:

Data-flow diagram of RT-DETR. A 640×640 image passes through a ResNet backbone, which yields three feature levels, S3, S4 and S5, of size 80×80, 40×40 and 20×20, corresponding to 6,400, 1,600 and 400 positions. A 1×1 convolution first converts all three levels to 256 channels. Only S5 enters AIFI, where it is flattened into 400 tokens for one layer of self-attention, producing F5; S3 and S4 skip self-attention and pass straight down. All three enter CCFF, which uses convolutions to fuse adjacent scales top-down and then bottom-up, producing three levels of 80×80, 40×40 and 20×20 that are flattened and concatenated into 8,400 features of 256 dimensions. Query selection takes the top 300 by score, using the features as content and the predicted boxes as starting points. The decoder has 6 layers, each followed by its own set of prediction heads; a red line in the figure shows inference stopping at layer 4, with the last two layers left out. The final output is 300 boxes, classes and scores, filtered with a score threshold and no NMS.
Figure: Drawn for this note, with a ResNet-50 backbone and 640×640 input as the example; stopping the decoder at layer 4 is just one example.

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:

Five boxes side by side, one for each encoder variant. A has only Concat; B is SSE followed by Concat; C is Concat followed by MSE; D is SSE followed by CSF; E is AIFI followed by CCFF. The arrows below mark A to B as adding intra-scale interaction, B to C as adding cross-scale interaction, C to D as separating the two, and D to E as an enhanced version.
Figure 3 from the paper, Zhao et al., excerpted from page 4 of the v3 PDF. The structure of the five encoder variants.

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, DS5\mathrm{D}_{S_5}, which has the same structure as D except that SSE processes only S5:

Table: Table 3 of the paper; the "What the encoder does" column is compiled from §4.2.
VariantWhat the encoder doesAPParams (M)Latency (ms)
ANo encoder; the three levels are concatenated directly43.0317.2
BThe three levels share one single-scale Transformer layer, each doing intra-scale interaction, then get concatenated44.93211.1
CB's results are concatenated and fed into a multi-scale Transformer encoder45.63213.3
DIntra-scale interaction goes to a single-scale Transformer, cross-scale fusion to a PANet-style structure46.43512.2
DS5\mathrm{D}_{S_5}Same as D, but only S5 does intra-scale interaction46.8357.9
EAIFI + CCFF, which is RT-DETR's design47.9429.3

Going down row by row:

  1. A → B: AP rises by 1.9 and latency by 54%. Intra-scale interaction helps, but self-attention in every level is expensive.
  2. 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.
  3. C → D: Separating intra-scale interaction from cross-scale fusion adds 0.8 AP and actually cuts latency by 8%.
  4. D → DS5\mathrm{D}_{S_5}: 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.
  5. 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 DS5\mathrm{D}_{S_5} 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:

Q=K=V=Flatten(S5)F5=Reshape(AIFI(Q,K,V))O=CCFF({S3,S4,F5})\begin{aligned} \mathcal{Q} = \mathcal{K} = \mathcal{V} &= \mathrm{Flatten}(S_5) \\ F_5 &= \mathrm{Reshape}(\mathrm{AIFI}(\mathcal{Q}, \mathcal{K}, \mathcal{V})) \\ \mathcal{O} &= \mathrm{CCFF}(\{S_3, S_4, F_5\}) \end{aligned}

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:

U(X^)=∥P(X^)−C(X^)∥,X^∈RD\mathcal{U}(\hat{\mathcal{X}}) = \lVert \mathcal{P}(\hat{\mathcal{X}}) - \mathcal{C}(\hat{\mathcal{X}}) \rVert, \quad \hat{\mathcal{X}} \in \mathbb{R}^D L(X^,Y^,Y)=Lbox(b^,b)+Lcls(U(X^),c^,c)\mathcal{L}(\hat{\mathcal{X}}, \hat{\mathcal{Y}}, \mathcal{Y}) = \mathcal{L}_{box}(\hat{\mathbf{b}}, \mathbf{b}) + \mathcal{L}_{cls}(\mathcal{U}(\hat{\mathcal{X}}), \hat{\mathbf{c}}, \mathbf{c})

Here X^\hat{\mathcal{X}} is the encoder feature, c^\hat{\mathbf{c}} and b^\hat{\mathbf{b}} are the predicted class and box, and c\mathbf{c} and b\mathbf{b} 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:

Table: An example for this note.
FeatureMatched annotationIoU of predicted box and annotationUsual classification targetRT-DETR classification target
#1dog0.4510.45
#2cat0.9010.90
#3unmatched—00

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:

Scatter plot with IoU score from 0 to 1 on the horizontal axis and Classification score from 0.5 to 1 on the vertical axis. The purple points are Uncertainty-minimal, heavily concentrated in the upper right, with IoU around 0.6 to 0.9 and classification scores of 0.7 and above; the green points are Vanilla, fewer in number and concentrated in the lower right, with classification scores mostly between 0.5 and 0.65. In the density curves on the top and right, purple is clearly higher than green.
Figure 6 from the paper, Zhao et al., excerpted from page 6 of the v3 PDF. Classification scores and IoU of the encoder features picked by the two query selection methods.

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):

Table: Table 4 of the paper.
Query selectionAPShare with classification score > 0.5Share with both > 0.5
By classification score (original)47.90.35%0.30%
uncertainty-minimal48.70.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):

Table: Table 5 of the paper. Det k means the decoder was trained with k layers, and each cell is AP; the latency column depends only on how many layers inference uses.
Layers used at inferenceDet4Det5Det6Det7Latency (ms)
752.69.6
653.152.69.3
552.953.052.58.8
452.752.752.752.18.3
352.452.352.451.57.9
251.651.351.350.67.5
149.648.849.148.37.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:

Table: Excerpted from Table 2 of the paper. APS is the AP on small objects.
ModelParams (M)GFLOPsFPSAPAPS
YOLOv6-L591509952.834.4
YOLOv7-X711894552.936.9
YOLOv8-L431657152.935.3
YOLOv8-X682575053.935.7
DINO-Deformable-DETR-R5047279550.934.6
RT-DETR-R504213610853.134.8
RT-DETR-R101762597454.336.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:

  1. 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.
  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.
  3. 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.
  4. 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.