LW-DETR (ViT, tiny / small / medium / large / xlarge)
LW-DETR (tiny to xlarge; ViT, COCO) from Baidu: real-time end-to-end detector, a plain ViT encoder with a multi-level projector and a DETR decoder with deformable attention, no NMS. Apache-2.0 code and weights.
experimental Fork of huggingface/transformers@c4c4605 · backends: portable, kernels
- Paper LW-DETR: A Transformer Replacement to YOLO for Real-Time Detection arXiv · first released 5 Jun 2024
- Authors’ code Atten4Vis/LW-DETR (PyTorch), not the code forked here: fastforks follows the Hugging Face transformers port, which loads the AnnaZhang/lwdetr_*_60e_coco weights, instead of the authors' repository.
Paper 2024 Added in 0.2.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install "fastforks-core[transformers]"
from fastforks import detection
model = detection.load("lw-detr-tiny-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 lw-detr-tiny-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 fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | not measured | – | – | – | – |
| Original fp16torch.autocast(float16) around the call; transformers LwDetrForObjectDetection + image processor (CPU), the authors' PostProcess (all kept) | fp16 | 16.4 | – | 114 MiB/132 MiB | 0.7 | 0.17 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 7.45 | 2.2× | 92 MiB/112 MiB | 2.7 | 0.35 |
| Kernels | fp16 | 2.20 | 7.5× | 94 MiB/134 MiB | 2.9 | 0.33 |
| Portable + torch.compile | 2.98 | 5.5× | 112 MiB/130 MiB | 22 (build) | – | |
| TensorRT fp16 | fp16 | 0.999 | 16× | 44 MiBenginenot comparable | 60 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-13. 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 | 52.0 | 1,864 MiB process | – | 800x1344 |
| Portable | fp16 | 41.2 | 1,742 MiB process | matches | 800x1344 | |
| Portable | fp32 | 47.3 | 1,776 MiB process | matches | 800x1344 | |
| Kernels | fp16 | not implemented | – | 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
- Weights
- Apache-2.0 source
- Training data
-
- COCO 2017 (train, instance annotations) CC-BY-4.0
- Objects365 (train, box annotations) CC-BY-4.0, non-commercial
Our reading of the licences, not legal advice.
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 20th image, box mAP
| Run | dtype | box mAP ↑ | Δ box mAP vs fp32 original | images | ms / image |
|---|---|---|---|---|---|
| Original fp32 | fp32 | 49.05 | reference | 250 | – |
| Original fp16 | not measured | ||||
| Portable fp32 | not measured | ||||
| Portable | fp16 | 48.81 | −0.24 | 250 | – |
| Kernels | fp16 | 48.99 | −0.06 | 250 | – |
pycocotools COCOeval of the top 100 detections per image. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks aee4b565, 2026-11-13.
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.28 and p99 <= 0.93 (absolute error of the output boxes).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.002 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.28 | 0.04142 |
| GPU default dtypes, p99 |diff| | ≤ 0.93 | 0.06935 |
Recorded for lw-detr-tiny-coco on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13, with these kernels: cudnn_hacc
Details
LW-DETR (Chen et al. 2024, Baidu): real-time end-to-end detection with a plain ViT encoder (interleaved window and global attention), a C2f projector and a 3-layer deformable DETR decoder over the encoder's best proposals (no NMS); boxes, scores and COCO classes at the input size. Images are resized to 640x640 (aspect ratio ignored). The portable `module()` is the whole network at its input size (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 (469 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
num_select=100- CUDA kernels
cudnn_haccconvolutions with fp16 accumulation (cuDNN)
- Apple (MPS)
- fp32, fp16
Limitations
- Requires the optional transformers library (the network is its `LwDetrForObjectDetection`).
- The original in the benchmarks and goldens is the Hugging Face transformers 5.19.0 port (AnnaZhang/lwdetr_*_60e_coco weights) of the official LW-DETR (Apache-2.0); the official repository code itself was not run.
Full reference, generated from the repository
LW-DETR (tiny to xlarge; ViT, COCO) from Baidu: real-time end-to-end detector, a plain ViT encoder with a multi-level projector and a DETR decoder with deformable attention, no NMS. Apache-2.0 code and weights.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
lw-detr-tiny-coco | synthetic (800x1344) | original portable kernels portable + torch.compile TensorRT fp16 | 16.4 7.45 2.20 2.98 0.999 | 114 / 132 92 / 112 94 / 134 112 / 130 116 / 128 |
lw-detr-small-coco | synthetic (800x1344) | original portable kernels portable + torch.compile TensorRT fp16 | 19.9 8.82 2.80 3.63 1.36 | 129 / 166 97 / 116 99 / 140 116 / 134 121 / 130 |
lw-detr-medium-coco | synthetic (800x1344) | original portable kernels portable + torch.compile TensorRT fp16 | 23.3 8.75 3.78 3.74 2.30 | 228 / 274 131 / 156 131 / 178 147 / 174 185 / 212 |
lw-detr-large-coco | synthetic (800x1344) | original portable kernels portable + torch.compile TensorRT fp16 | 22.8 10.2 5.64 5.62 3.45 | 355 / 382 204 / 230 192 / 254 195 / 208 270 / 296 |
lw-detr-xlarge-coco | synthetic (800x1344) | original portable kernels portable + torch.compile TensorRT fp16 | 25.5 12.1 9.39 10.7 6.58 | 762 / 850 348 / 360 336 / 382 339 / 358 544 / 566 |
Details
- Original code: https://github.com/huggingface/transformers at
c4c4605f9618 - Code licence: Apache-2.0 (permissive); files:
- Weights licence: Apache-2.0
- Licence evidence: https://huggingface.co/AnnaZhang/lwdetr_tiny_60e_coco/blob/4b636b514dcf623f6eafc9e1ab63b8ad5c513925/README.md
- Training data: COCO 2017 (train, instance annotations), Objects365 (train, box annotations) (COCO 2017 train after detection pretraining on Objects365; the ViT encoders start from CAEv2 self-supervised pretraining (paper arXiv:2406.03459 section 4).)
- Options:
score_threshold= 0.05 (0.0 to 1.0),max_detections= 100 (>= 1),cuda_graphs= True (speed only) - Kernel libraries:
cudnn_hacc - Variants:
lw-detr-tiny-coco,lw-detr-small-coco,lw-detr-medium-coco,lw-detr-large-coco,lw-detr-xlarge-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):
lw-detr-tiny-coco3000x4000 (0.5 GiB peak allocated, 0.5 reserved);lw-detr-small-coco3000x4000 (0.5 GiB peak allocated, 0.5 reserved);lw-detr-medium-coco3000x4000 (0.5 GiB peak allocated, 0.5 reserved);lw-detr-large-coco3000x4000 (0.5 GiB peak allocated, 0.5 reserved);lw-detr-xlarge-coco3000x4000 (0.7 GiB peak allocated, 0.7 reserved) lw-detr-tiny-coco800x1344, first call: portable + torch.compile 22 s (cold Inductor cache), TensorRT fp16 60 s (ONNX + engine).lw-detr-small-coco800x1344, first call: portable + torch.compile 23 s (cold Inductor cache), TensorRT fp16 63 s (ONNX + engine).lw-detr-medium-coco800x1344, first call: portable + torch.compile 22 s (cold Inductor cache), TensorRT fp16 63 s (ONNX + engine).lw-detr-large-coco800x1344, first call: portable + torch.compile 30 s (cold Inductor cache), TensorRT fp16 56 s (ONNX + engine).lw-detr-xlarge-coco800x1344, first call: portable + torch.compile 30 s (cold Inductor cache), TensorRT fp16 58 s (ONNX + engine).lw-detr-tiny-cocooriginal 800x1344: torch.autocast(float16) around the call; transformers LwDetrForObjectDetection + image processor (CPU), the authors' PostProcess (all kept)lw-detr-small-cocooriginal 800x1344: torch.autocast(float16) around the call; transformers LwDetrForObjectDetection + image processor (CPU), the authors' PostProcess (all kept)lw-detr-medium-cocooriginal 800x1344: torch.autocast(float16) around the call; transformers LwDetrForObjectDetection + image processor (CPU), the authors' PostProcess (all kept)lw-detr-large-cocooriginal 800x1344: torch.autocast(float16) around the call; transformers LwDetrForObjectDetection + image processor (CPU), the authors' PostProcess (all kept)lw-detr-xlarge-cocooriginal 800x1344: torch.autocast(float16) around the call; transformers LwDetrForObjectDetection + image processor (CPU), the authors' PostProcess (all kept)lw-detr-tiny-cocoload / first call: original 3.8 s / 0.644 s, portable 2.69 s / 0.348 s, kernels 2.91 s / 0.329 slw-detr-small-cocoload / first call: original 4.14 s / 0.634 s, portable 2.72 s / 0.351 s, kernels 2.91 s / 0.331 slw-detr-medium-cocoload / first call: original 3.91 s / 0.642 s, portable 3.64 s / 0.344 s, kernels 3.65 s / 0.332 slw-detr-large-cocoload / first call: original 3.82 s / 0.72 s, portable 3.2 s / 0.36 s, kernels 3.04 s / 0.338 slw-detr-xlarge-cocoload / first call: original 4.72 s / 0.711 s, portable 3.32 s / 0.34 s, kernels 4.25 s / 0.377 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 | portable | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|
lw-detr-tiny-coco | COCO val2017, every 20th image, box mAP | 49.05 | 48.81 | 48.99 | ||
lw-detr-small-coco | COCO val2017, every 20th image, box mAP | 52.85 | 52.93 | |||
lw-detr-medium-coco | COCO val2017, every 20th image, box mAP | 57.65 | 57.60 | |||
lw-detr-large-coco | COCO val2017, every 20th image, box mAP | 60.67 | 61.01 | 60.74 | ||
lw-detr-xlarge-coco | COCO val2017, every 20th image, box mAP | 61.57 | 61.58 |
Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks aee4b565, 2026-11-13; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 30c7a8e9, 2026-11-17 to 2026-11-18; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks aee4b565, 2026-11-13.
Parity
CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.28 and p99 <= 0.93 (absolute error of the output boxes).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
lw-detr-tiny-coco | 0.04142 / 0.06935 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
lw-detr-small-coco | 0.17032 / 0.61935 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
lw-detr-medium-coco | 0.1222 / 0.42107 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
lw-detr-large-coco | 0.07557 / 0.17951 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
lw-detr-xlarge-coco | 0.06452 / 0.31725 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
Limitations
- Requires the optional transformers library (the network is its
LwDetrForObjectDetection). - The original in the benchmarks and goldens is the Hugging Face transformers 5.19.0 port (AnnaZhang/lwdetr_*_60e_coco weights) of the official LW-DETR (Apache-2.0); the official repository code itself was not run.
Example output
No example rendered for this checkpoint yet.