RT-DETRv2 (ResNet-vd, S / M / M* / L / X)
RT-DETRv2 (S, M, M*, L, X; ResNet-vd, COCO) from the RT-DETR authors: real-time end-to-end detector, 300 queries and deformable attention, no NMS.
stable Fork of lyuwenyu/RT-DETR@df2a96c · backends: portable, kernels
- Paper RT-DETRv2: Improved Baseline with Bag-of-Freebies for Real-Time Detection Transformer arXiv · first released 24 Jul 2024
Paper 2024 Added in 0.1.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install fastforks-core
from fastforks import detection
model = detection.load("rtdetrv2-s-coco") # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.boxes # also: scores, labels
result.backend # what ran: mode, device, dtype, kernels fastforks bench rtdetrv2-s-coco Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.
Speed and memory
Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.
Input: synthetic, 800x1344 (the task’s standard size)
| Backend | dtype | Time per call (ms) | vs original fp32 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32incl. CPU resize + host copy (official pipeline) | fp32 | 14.1 | – | 196 MiB/226 MiB | 0.3 | 0.09 |
| Original fp16torch.autocast(fp16) around the forward; incl. CPU resize + host copy (official pipeline) | fp16 | 16.8 | 0.84× | 192 MiB/220 MiB | 1.3 | 0.42 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 9.60 | 1.5× | 137 MiB/166 MiB | 1.4 | 0.39 |
| Kernels | fp16 | 4.10 | 3.4× | 137 MiB/208 MiB | 1.5 | 0.36 |
| Portable + torch.compile | 4.22 | 3.3× | 152 MiB/182 MiB | 37 (build) | – | |
| TensorRT fp16 | fp16 | 1.81 | 7.8× | 98 MiBenginenot comparable | 42 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-02 to 2026-11-16. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two
times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.
Other devices
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14 | Original | fp32 | 65.2 | 1,768 MiB process | – | 800x1344 |
| Portable | fp16 | 44.4 | 1,631 MiB process | matches | 800x1344 | |
| Portable | fp32 | 44.0 | 1,650 MiB process | matches | 800x1344 | |
| Kernels | fp16 | not implemented | – | 800x1344 | ||
| NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 13.1 | 110 MiB/126 MiB | – | 800x1344 |
| Kernels | fp16 | 4.56 | 111 MiB/212 MiB | – | 800x1344 | |
| NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 9.62 | 110 MiB/126 MiB | – | 800x1344 |
| Kernels | fp16 | 2.76 | 112 MiB/208 MiB | – | 800x1344 | |
| NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 8.33 | 110 MiB/126 MiB | – | 800x1344 |
| Kernels | fp16 | 4.88 | 112 MiB/208 MiB | – | 800x1344 | |
| NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 9.88 | 110 MiB/126 MiB | – | 800x1344 |
| Kernels | fp16 | 4.74 | 113 MiB/208 MiB | – | 800x1344 | |
| NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08 | Portable | fp16 | 3.55 | 134 MiB/146 MiB | – | 800x1344 |
| Kernels | fp16 | 2.21 | 158 MiB/248 MiB | – | 800x1344 | |
CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.
Licence and weights
Commercial use allowed
- Code
- Apache-2.0 LICENSE
- Weights
- Apache-2.0 (assumed from code)(not stated by the authors; assumed to follow the code) source
- Training data
-
- COCO 2017 (train, instance annotations) CC-BY-4.0
- ImageNet-1k (ILSVRC 2012 classification) noncommercial, non-commercial
- weights licence not stated by the original authors; assumed to be the code licence
Our reading of the licences, not legal advice.
Weights
rtdetrv2_r18vd_120e_coco_rerun_48.1.pth 81.2 MB· hosted on GitHubfastforks downloads and checks these files on first use (fastforks download rtdetrv2-s-coco).
Accuracy
The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.
COCO val2017
every 10th image, box mAP
| Run | dtype | box mAP ↑ | Δ box mAP vs fp32 original | images | ms / image |
|---|---|---|---|---|---|
| Original fp32 | fp32 | 49.29 | reference | 500 | 12.3 |
| Original fp16 | fp16 | 49.26 | −0.03 | 500 | 15.8 |
| Portable fp32 | fp32 | 49.30 | +0.01 | 500 | 8.72 |
| Portable | fp16 | 49.29 | ±0.00 | 500 | 8.11 |
| Kernels | fp16 | 49.31 | +0.02 | 500 | 4.15 |
pycocotools COCOeval of the top 100 detections per image. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-06; portable fp32: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 44640884, 2026-11-17; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06.
Closeness to the original
Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.2 and p99 <= 1.0 (absolute error of the output boxes).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.002 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.2 | 0.03739 |
| GPU default dtypes, p99 |diff| | ≤ 1 | 0.1098 |
Recorded for rtdetrv2-s-coco on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-03, with these kernels: cudnn_hacc
Details
RT-DETRv2 (Lv et al. 2024, Baidu): real-time end-to-end detection; ResNet-vd backbone, hybrid encoder (one attention layer, CSP-RepVGG feature pyramid), deformable-attention decoder over 300 selected queries, no NMS; boxes, scores and COCO classes at the input size. The portable `module()` is the whole network at 640x640 (class logits and normalised boxes).
- Input / output
- Input: one RGB image. Output: boxes, class labels, scores and instance masks.
- Input size
- any H x W >= 32, padded to a multiple of 32; tested up to 3000x4000 (530 MiB allocated)
- Options
score_threshold=0.050.0 to 1.0· changes the outputmax_detections=100>= 1· changes the outputcuda_graphs=true
- Outputs
boxes,scores,labels- Checkpoint
blocks=[2,2,2,2],bottleneck=false,expansion=0.5,dec_layers=3,eval_layers=3- CUDA kernels
cudnn_haccconvolutions with fp16 accumulation (cuDNN)
- Apple (MPS)
- fp32, fp16
Limitations
- Kernels keep CUDA graphs: their private pool and static outputs stay reserved, so peak reserved is ~110 MiB above portable (peak allocated is not); `cuda_graphs=false` or `release_graphs()` frees it.
Full reference, generated from the repository
RT-DETRv2 (S, M, M*, L, X; ResNet-vd, COCO) from the RT-DETR authors: real-time end-to-end detector, 300 queries and deformable attention, no NMS.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
rtdetrv2-s-coco | synthetic (800x1344) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 14.1 16.8 9.60 4.10 4.22 1.81 | 196 / 226 192 / 220 137 / 166 137 / 208 152 / 182 187 / 218 |
rtdetrv2-m-coco | synthetic (800x1344) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 17.1 20.9 9.96 5.19 5.35 2.42 | 239 / 254 254 / 270 159 / 190 159 / 212 177 / 206 199 / 222 |
rtdetrv2-ms-coco | synthetic (800x1344) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 24.7 22.5 11.1 5.40 5.82 2.62 | 322 / 374 309 / 358 169 / 202 169 / 242 193 / 220 244 / 288 |
rtdetrv2-l-coco | synthetic (800x1344) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 30.3 38.4 12.4 6.53 7.29 3.32 | 366 / 424 354 / 412 180 / 200 180 / 262 204 / 238 255 / 286 |
rtdetrv2-x-coco | synthetic (800x1344) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 36.3 46.8 14.9 9.17 10.9 5.23 | 529 / 596 589 / 622 247 / 278 247 / 320 269 / 296 381 / 430 |
Details
- Original code: https://github.com/lyuwenyu/RT-DETR at
df2a96c8c3a0 - Code licence: Apache-2.0 (permissive); files:
LICENSE - Weights licence: Apache-2.0 (assumed from code)
- Licence evidence: https://github.com/lyuwenyu/RT-DETR/blob/df2a96c8c3a098567a1149bf0248da6efe6d495d/LICENSE
- Training data: COCO 2017 (train, instance annotations), ImageNet-1k (ILSVRC 2012 classification) (COCO 2017 train (72 to 84 epochs); the ResNet-vd backbones start from ImageNet-1k (PaddleClas) pretraining)
- Options:
score_threshold= 0.05 (0.0 to 1.0),max_detections= 100 (>= 1),cuda_graphs= True (speed only) - Kernel libraries:
cudnn_hacc - Variants:
rtdetrv2-s-coco,rtdetrv2-m-coco,rtdetrv2-ms-coco,rtdetrv2-l-coco,rtdetrv2-x-coco - Outputs: boxes, scores, labels; label_set:
coco-80 - Input size: any H x W >= 32, padded to a multiple of 32
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
rtdetrv2-s-coco3000x4000 (0.5 GiB peak allocated, 0.6 reserved);rtdetrv2-m-coco3000x4000 (0.5 GiB peak allocated, 0.7 reserved);rtdetrv2-ms-coco3000x4000 (0.5 GiB peak allocated, 0.7 reserved);rtdetrv2-l-coco3000x4000 (0.6 GiB peak allocated, 0.7 reserved);rtdetrv2-x-coco3000x4000 (0.6 GiB peak allocated, 0.8 reserved) rtdetrv2-s-coco800x1344, first call: portable + torch.compile 37 s (cold Inductor cache), TensorRT fp16 42 s (ONNX + engine).rtdetrv2-m-coco800x1344, first call: portable + torch.compile 32 s (cold Inductor cache), TensorRT fp16 44 s (ONNX + engine).rtdetrv2-ms-coco800x1344, first call: portable + torch.compile 28 s (cold Inductor cache), TensorRT fp16 44 s (ONNX + engine).rtdetrv2-l-coco800x1344, first call: portable + torch.compile 42 s (cold Inductor cache), TensorRT fp16 48 s (ONNX + engine).rtdetrv2-x-coco800x1344, first call: portable + torch.compile 44 s (cold Inductor cache), TensorRT fp16 55 s (ONNX + engine).rtdetrv2-s-cocooriginal (fp32) 800x1344: incl. CPU resize + host copy (official pipeline)rtdetrv2-s-cocooriginal 800x1344: torch.autocast(fp16) around the forward; incl. CPU resize + host copy (official pipeline)rtdetrv2-m-cocooriginal (fp32) 800x1344: incl. CPU resize + host copy (official pipeline)rtdetrv2-m-cocooriginal 800x1344: torch.autocast(fp16) around the forward; incl. CPU resize + host copy (official pipeline)rtdetrv2-ms-cocooriginal (fp32) 800x1344: incl. CPU resize + host copy (official pipeline)rtdetrv2-ms-cocooriginal 800x1344: torch.autocast(fp16) around the forward; incl. CPU resize + host copy (official pipeline)rtdetrv2-l-cocooriginal (fp32) 800x1344: incl. CPU resize + host copy (official pipeline)rtdetrv2-l-cocooriginal 800x1344: torch.autocast(fp16) around the forward; incl. CPU resize + host copy (official pipeline)rtdetrv2-x-cocooriginal (fp32) 800x1344: incl. CPU resize + host copy (official pipeline)rtdetrv2-x-cocooriginal 800x1344: torch.autocast(fp16) around the forward; incl. CPU resize + host copy (official pipeline)rtdetrv2-s-cocoload / first call: original 1.32 s / 0.417 s, portable 1.37 s / 0.389 s, kernels 1.51 s / 0.361 srtdetrv2-m-cocoload / first call: original 0.45 s / 0.023 s, portable 1.45 s / 0.37 s, kernels 1.64 s / 0.329 srtdetrv2-ms-cocoload / first call: original 0.52 s / 0.057 s, portable 1.51 s / 0.344 s, kernels 1.8 s / 0.31 srtdetrv2-l-cocoload / first call: original 0.66 s / 0.043 s, portable 1.54 s / 0.358 s, kernels 1.89 s / 0.301 srtdetrv2-x-cocoload / first call: original 1.13 s / 0.076 s, portable 1.79 s / 0.322 s, kernels 2.14 s / 0.285 s- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5
Measured
pycocotools COCOeval of the top 100 detections per image. Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | original fp16 | portable | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|---|
rtdetrv2-s-coco | COCO val2017, every 10th image, box mAP | 49.29 | 49.26 | 49.29 | 49.30 | 49.31 | |
rtdetrv2-m-coco | COCO val2017, every 10th image, box mAP | 49.83 | 49.81 | 49.84 | 49.83 | 49.79 | |
rtdetrv2-ms-coco | COCO val2017, every 10th image, box mAP | 51.97 | 51.98 | 51.95 | 51.96 | 51.96 | |
rtdetrv2-l-coco | COCO val2017, every 10th image, box mAP | 54.52 | 54.57 | 54.51 | 54.55 | 54.49 | |
rtdetrv2-x-coco | COCO val2017, every 10th image, box mAP | 55.51 | 55.54 | 55.51 | 55.56 | 55.49 |
Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 44640884, 2026-11-17; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06.
Parity
CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.2 and p99 <= 1.0 (absolute error of the output boxes).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
rtdetrv2-s-coco | 0.03739 / 0.1098 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
rtdetrv2-m-coco | 0.06517 / 0.13434 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
rtdetrv2-ms-coco | 0.06765 / 0.17406 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
rtdetrv2-l-coco | 0.04387 / 0.1019 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
rtdetrv2-x-coco | 0.05571 / 0.2201 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
Limitations
- Kernels keep CUDA graphs: their private pool and static outputs stay reserved, so peak reserved is ~110 MiB above portable (peak allocated is not);
cuda_graphs=falseorrelease_graphs()frees it.
Example output
One fixed input through this checkpoint, the same for every model of the task (kernels · float16 · NVIDIA GeForce RTX 5060 Ti).
- person 0.95
Input: Astronaut Eileen Collins, NASA (public domain).