Models · Object detection

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

Checkpoint

Paper 2024 Added in 0.2.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 2.20 ms 800x1344, fp16
vs the faster original 7.5× original fp16: 16.4 ms
Peak memory 94 MiB original: 114 MiB
Accuracy vs original fp32 −0.06 kernels box mAP, COCO val2017 (49.05 original)

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)

BackenddtypeTime per call (ms)vs original fp16Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32fp32not measured ––––
Original fp16torch.autocast(float16) around the call; transformers LwDetrForObjectDetection + image processor (CPU), the authors' PostProcess (all kept)fp16 16.4–114 MiB/132 MiB0.70.17
Portable fp32fp32not measured ––––
Portablefp16 7.452.2×92 MiB/112 MiB2.70.35
Kernelsfp16 2.207.5×94 MiB/134 MiB2.90.33
Portable + torch.compile 2.985.5×112 MiB/130 MiB22 (build)–
TensorRT fp16fp16 0.99916×44 MiBenginenot comparable60 (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

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14Originalfp3252.0 1,864 MiB process–800x1344
Portablefp1641.2 1,742 MiB processmatches800x1344
Portablefp3247.3 1,776 MiB processmatches800x1344
Kernelsfp16not 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

Our reading of the licences, not legal advice.

Weights

lwdetr-tiny.config.json 5.6 KB· hosted on Hugging Face
lwdetr-tiny.model.safetensors 48.3 MB· hosted on Hugging Face

fastforks downloads and checks these files on first use (fastforks download lw-detr-tiny-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 20th image, box mAP

Rundtypebox mAP ↑Δ box mAP vs fp32 originalimagesms / image
Original fp32fp3249.05 reference 250 –
Original fp16not measured
Portable fp32not measured
Portablefp1648.81 −0.24 250 –
Kernelsfp1648.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).

CheckToleranceMeasured
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 output
  • max_detections=100>= 1· changes the output
  • cuda_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.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
lw-detr-tiny-cocosynthetic (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-cocosynthetic (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-cocosynthetic (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-cocosynthetic (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-cocosynthetic (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-coco 3000x4000 (0.5 GiB peak allocated, 0.5 reserved); lw-detr-small-coco 3000x4000 (0.5 GiB peak allocated, 0.5 reserved); lw-detr-medium-coco 3000x4000 (0.5 GiB peak allocated, 0.5 reserved); lw-detr-large-coco 3000x4000 (0.5 GiB peak allocated, 0.5 reserved); lw-detr-xlarge-coco 3000x4000 (0.7 GiB peak allocated, 0.7 reserved)
  • lw-detr-tiny-coco 800x1344, first call: portable + torch.compile 22 s (cold Inductor cache), TensorRT fp16 60 s (ONNX + engine).
  • lw-detr-small-coco 800x1344, first call: portable + torch.compile 23 s (cold Inductor cache), TensorRT fp16 63 s (ONNX + engine).
  • lw-detr-medium-coco 800x1344, first call: portable + torch.compile 22 s (cold Inductor cache), TensorRT fp16 63 s (ONNX + engine).
  • lw-detr-large-coco 800x1344, first call: portable + torch.compile 30 s (cold Inductor cache), TensorRT fp16 56 s (ONNX + engine).
  • lw-detr-xlarge-coco 800x1344, first call: portable + torch.compile 30 s (cold Inductor cache), TensorRT fp16 58 s (ONNX + engine).
  • lw-detr-tiny-coco original 800x1344: torch.autocast(float16) around the call; transformers LwDetrForObjectDetection + image processor (CPU), the authors' PostProcess (all kept)
  • lw-detr-small-coco original 800x1344: torch.autocast(float16) around the call; transformers LwDetrForObjectDetection + image processor (CPU), the authors' PostProcess (all kept)
  • lw-detr-medium-coco original 800x1344: torch.autocast(float16) around the call; transformers LwDetrForObjectDetection + image processor (CPU), the authors' PostProcess (all kept)
  • lw-detr-large-coco original 800x1344: torch.autocast(float16) around the call; transformers LwDetrForObjectDetection + image processor (CPU), the authors' PostProcess (all kept)
  • lw-detr-xlarge-coco original 800x1344: torch.autocast(float16) around the call; transformers LwDetrForObjectDetection + image processor (CPU), the authors' PostProcess (all kept)
  • lw-detr-tiny-coco load / first call: original 3.8 s / 0.644 s, portable 2.69 s / 0.348 s, kernels 2.91 s / 0.329 s
  • lw-detr-small-coco load / first call: original 4.14 s / 0.634 s, portable 2.72 s / 0.351 s, kernels 2.91 s / 0.331 s
  • lw-detr-medium-coco load / first call: original 3.91 s / 0.642 s, portable 3.64 s / 0.344 s, kernels 3.65 s / 0.332 s
  • lw-detr-large-coco load / first call: original 3.82 s / 0.72 s, portable 3.2 s / 0.36 s, kernels 3.04 s / 0.338 s
  • lw-detr-xlarge-coco load / 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.

variantdatasetoriginal fp32portableportable fp32kernelsnote
lw-detr-tiny-cocoCOCO val2017, every 20th image, box mAP49.0548.8148.99
lw-detr-small-cocoCOCO val2017, every 20th image, box mAP52.8552.93
lw-detr-medium-cocoCOCO val2017, every 20th image, box mAP57.6557.60
lw-detr-large-cocoCOCO val2017, every 20th image, box mAP60.6761.0160.74
lw-detr-xlarge-cocoCOCO val2017, every 20th image, box mAP61.5761.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).

variantkernels error vs original, mean / p99GPU, torchkernels used
lw-detr-tiny-coco0.04142 / 0.06935RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400
lw-detr-small-coco0.17032 / 0.61935RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400
lw-detr-medium-coco0.1222 / 0.42107RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400
lw-detr-large-coco0.07557 / 0.17951RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400
lw-detr-xlarge-coco0.06452 / 0.31725RTX 5060 Ti, torch 2.14.1+cu130cudnn_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.