LW-DETR

LW-DETR (Light-Weight DEtection TRansformer) is a real-time detection transformer.

  • Paper: Chen, Su, Zhang, Wang, Chen, Shen, Han, Chen, Xu, Li, Zhang, Yao, Ding, Zhang and Wang (Baidu Inc. and collaborators), LW-DETR: A Transformer Replacement to YOLO for Real-Time Detection, June 2024, arXiv:2406.03459.
  • Architecture: where RT-DETR keeps a convolutional backbone and rebuilds the DETR encoder, LW-DETR goes the other way: the encoder is a plain ViT, and the whole detector is a three-part stack, ViT encoder → convolutional projector → shallow DETR decoder.
  • Contribution: no architectural invention at all; a careful assembly of existing techniques.
  • Training-effective techniques: Objects365 pre-training, IA-BCE loss, Group DETR supervision, deformable cross-attention.
  • Inference-efficient techniques: interleaved window/global attention, window-major feature map organization, a 3-layer decoder.
  • Headline result: five models spanning 42.6 mAP at 500 FPS (tiny) to 58.3 mAP at 52 FPS (xlarge) on COCO val2017, T4 + TensorRT FP16, dominating YOLO-NAS, YOLOv8, RTMDet, YOLOv10 and RT-DETR at every scale.

LW-DETR vs. state-of-the-art real-time detectors: mAP against end-to-end inference time

The starred curves are the competitors with their NMS score threshold tuned by the authors rather than left at the official default — i.e. the baselines are strengthened, not weakened, before the comparison. LW-DETR is above all of them across the whole latency range.

Core idea: a plain ViT is a viable real-time detection backbone

The premise the paper tests is that the DETR line’s real-time problem was never the transformer as such, but the specific way DETRs were built. The received wisdom by 2024 was that real-time detection needs a convolutional backbone (every YOLO, and RT-DETR too), because global self-attention is quadratic in the number of patches. LW-DETR argues that a plain ViT encoder becomes affordable once you (a) replace most global attention layers with window attention, (b) implement that replacement without the permutation overhead the standard ViTDet implementation incurs, and (c) shorten the decoder from the customary 6 layers to 3.

The second premise, and empirically the larger one, is that detection transformers benefit far more from large-scale pre-training than convolutional detectors do. Objects365 pre-training is worth mAP on average across the LW-DETR scales — a gain the YOLO-family baselines simply do not get (see Pre-training below).

Architecture

LW-DETR is exactly three components.

ViT encoder

A plain ViT: a patchification layer plus transformer encoder layers, each a multi-head self-attention followed by an FFN. Two modifications:

Multi-level feature map aggregation. Instead of feeding the decoder only the last layer’s output, the encoder aggregates intermediate and final feature maps into one richer encoded map. Because a plain ViT is isotropic — every layer has the same spatial resolution — this is a plain concatenation, not a feature pyramid; there is no resampling involved.

LW-DETR encoder: interleaved window and global attention with multi-level feature aggregation

Interleaved window and global attention. Some global self-attention layers are replaced with window self-attention, which partitions the feature map into non-overlapping windows and attends within each. In the 6-layer tiny encoder, layers 0, 2 and 4 are window layers; in the 10-layer small/medium/large/xlarge encoders it is layers 0, 1, 3, 6, 7. The number of windows is fixed at 16 across image resolutions rather than the window size being fixed — which is why the input must be divisible by the window count, and why the paper uses a window size at .

Projector

A C2f block — the cross-stage-partial DenseNet extension used in YOLOv8 — connecting encoder to decoder. Its job is channel reduction and a little convolutional mixing on the aggregated encoded feature maps.

Single-scale projector (a) for tiny/small/medium, multi-scale projector (b) for large/xlarge

For tiny/small/medium the projector is single-scale: one C2f block, one output map at resolution. For large/xlarge it outputs two scales, and , via two parallel C2f blocks — one path upsamples the input with a deconvolution, the other downsamples it with a strided convolution — and the decoder becomes the multi-scale deformable decoder of Deformable DETR.

Decoder

A stack of transformer decoder layers, each self-attention → cross-attention → FFN, with deformable cross-attention (Deformable DETR) for efficiency. The critical departure from DETR convention is depth: 3 layers, not 6. On the tiny model this cuts decoder time from 1.4 ms to 0.7 ms, against 1.3 ms for everything else — so it is roughly a 25% end-to-end saving, not a rounding error.

Queries follow DINO’s mixed query selection: each object query is the sum of a content query (a learnable embedding, as in DETR) and a spatial query obtained two-stage — take the top- features from the projector’s last layer, predict boxes from them, and embed those boxes as spatial queries. Content queries stay static, spatial queries are data-dependent.

Objective function

The classification loss is the IA-BCE loss (IoU-aware binary cross-entropy) from Align-DETR:

where is the predicted classification score and the positive target absorbs the IoU against the ground truth:

The target score is thus a geometric mean of the model’s own confidence and its localization quality, so a confidently-classified but badly-localized prediction is trained down. The negative term is weighted by , a focal-style down-weighting of easy negatives. This is the same classification/localization alignment idea as Task-Aligned-Assignment and RT-DETR’s uncertainty-minimal query selection, applied here to the loss target.

The total loss adds the standard DETR box terms:

with the GIoU loss and the L1 box loss.

Box regression reparameterization. Rather than regressing box coordinates directly, each decoder layer predicts a transformation applied to a proposal :

the standard two-stage-detector parameterization, imported into DETR.

Effective training

Group DETR supervision. LW-DETR uses 13 parallel weight-sharing decoders during training, each with its own group of object queries generated from the projector output, following Group DETR. Only the primary decoder is used at inference, so this is free at test time — the same “extra supervision without inference cost” trick as DN-DETR’s denoising branch, from a different direction.

Two-stage Objects365 pre-training. First the ViT alone is pre-trained on Objects365 with the MIM method CAEv2 (worth mAP on COCO over the ImageNet weights); then the encoder is retrained and the projector and decoder trained in a supervised way on Objects365, following Group DETR v2. Only then does COCO fine-tuning start.

Efficient inference: window-major feature map organization

This is the paper’s one genuinely novel implementation detail, and the empirical study shows why it matters. Interleaved window/global attention cuts small’s FLOPs from 23.0G to 16.6G — a 28% reduction — but in the ViTDet implementation the latency actually rises by 0.2 ms. The reason is that ViTDet stores feature maps row-major, so every window-attention layer must permute memory into window order and back, and the permutation costs more than the saved attention.

LW-DETR instead stores the feature map window-major from the start. For a map

with window size , the window-major order is

rather than the row-major

Window attention over the window-major layout is a contiguous read, and global attention is order-agnostic, so both work without any permutation. Latency drops from 3.7 ms to 2.9 ms — a 0.8 ms saving that is larger than the entire decoder-shortening gain.

Instantiations

Five detectors (Table 1):

Encoder layersEncoder dimGlobal attn.Window attn.Projector blocksProjector dimScalesDecoder layersQueries
tiny61923312563100
small101924612563300
medium103844612563300
large103844613843300
xlarge107684613843300

Note that the decoder is 3 layers at every scale — the family scales through encoder width and projector scales only.

Hyperparameters

Objects365 pre-training (Table 9):

SettingValue
OptimizerAdamW
Base LR
Encoder LR
Weight decay
Batch size128
Epochs30
Training image resolutions
Encoder layer-wise LR decay0.8 (T/S), 0.7 (M/L), 0.75 (X)
Encoder layers6 (T), 10 (S/M/L/X)
Drop path0 (T/S/M), 0.05 (L/X)
Window numbers16
Window attention indexes (T), (S/M/L/X)
Output feature indexes (T), (S/M/L/X)
Feature scales (T/S/M), (L/X)
Object queries100 (T), 300 (S/M/L/X)
Decoder layers3
Hidden dimensions256 (T/S/M), 384 (L/X)
Decoder self-attention heads8 (T/S/M), 12 (L/X)
Decoder cross-attention heads16 (T/S/M), 24 (L/X)
Decoder sampling points2 (T/S/M), 4 (L/X)
Group DETR groups13
EMA decay0.9997

There is no LR drop schedule — the initial learning rate is held for the whole pre-training run.

COCO fine-tuning (Table 10) — the modifications on top of the above:

SettingValue
Base LR
Encoder LR
Weight decay (T/S/M/L), (X)
Batch size32 (T/S/M), 16 (L/X)
Epochs50 (T/S/M), 25 (L/X) — 180K iterations total
Drop path0 (T/S/M), 0.1 (L/X)
Component-wise LR decay0.7 (T/S/M), 0.5 (L/X)
Input resolution

Component-wise LR decay gives different scale factors to the prediction heads, the DETR decoder layers, the projector and the ViT encoder respectively: with a factor of 0.7 the scales are , , , — i.e. the encoder learns 3.4× slower than the heads.

Latency throughout is measured end-to-end, FP16, batch size 1, on a T4 with TensorRT-8.6.1 / CUDA-11.6 / cuDNN-8.7.0, using the efficientNMSPlugin for the NMS-based baselines.

Results

Empirical study: where the mAP comes from

Table 2 builds small from an all-global-attention initial detector, one technique at a time (45K iterations = 12 epochs, except the final row at 180K):

SettingParams (M)FLOPs (G)Latency (ms)mAP
Initial detector10.822.83.635.3
+ multi-level feature aggregation11.023.03.736.0
+ interleaved window/global attention (ViTDet impl.)11.016.63.934.7
+ window-major feature map organization11.016.62.934.7
+ IoU-aware classification loss11.016.62.935.4
+ more supervision (Group DETR)14.616.62.938.4
+ bounding box reparameterization14.616.62.938.6
+ pre-training on Objects36514.616.62.947.3
LW-DETR-small (180K iterations)14.616.62.948.0

Two things stand out. First, the latency story is entirely the window-major reorganization: interleaved attention alone loses 0.2 ms despite a 28% FLOP cut; the reorganization recovers that and 0.6 ms more. Second, the accuracy story is overwhelmingly pre-training: mAP from Objects365 against for Group DETR, each for feature aggregation and IA-BCE, and for box reparameterization. Architecture contributes single-digit tenths; data contributes 8.7 points.

Against real-time detectors

COCO val2017, T4 + TensorRT FP16, batch 1, total latency including NMS where applicable (Table 3, selected rows; all LW-DETR rows use Objects365 pre-training):

MethodParams (M)FLOPs (G)Model latency (ms)Total latency (ms)mAP
RTMDet-t4.98.12.17.441.7
YOLOv8n3.24.41.56.237.6
LW-DETR-tiny12.111.22.02.042.6
RTMDet-s8.914.82.87.944.9
YOLOv8s11.214.42.67.045.2
YOLO-NAS-s19.017.62.84.747.6
LW-DETR-small14.616.62.92.948.0
YOLO-NAS-m51.148.05.57.851.6
LW-DETR-medium28.242.85.65.652.5
YOLOv8l43.782.79.313.253.3
YOLO-NAS-l66.965.57.58.852.3
LW-DETR-large46.871.68.88.856.1
YOLOv8x68.2129.314.819.154.5
LW-DETR-xlarge118.0174.219.119.158.3

Being NMS-free, LW-DETR’s total latency equals its model latency — the column that costs YOLOv8n 4.7 ms and RTMDet-t 5.3 ms. Against YOLO-NAS, the strongest baseline (itself the product of a neural architecture search), LW-DETR gains 0.4 mAP at 1.6× the speed at small, 0.9 mAP at ~1.4× at medium, and 3.8 mAP at equal speed at large — the margin widens with scale.

Against concurrent work

LW-DETR against RT-DETR, YOLO-MS, Gold-YOLO and YOLOv10

From Table 4:

MethodParams (M)FLOPs (G)Total latency (ms)mAP
YOLOv10-S7.221.62.4946.3
YOLOv10-L24.4120.37.2853.2
YOLOv10-X29.5160.410.7054.4
RT-DETR-R18 (O365)2030.04.649.2
RT-DETR-R50 (O365)4269.49.355.3
RT-DETR-R101 (O365)76131.013.556.2
LW-DETR-small14.616.62.948.0
LW-DETR-large46.871.68.856.1
LW-DETR-xlarge118.0174.219.158.3

LW-DETR-large beats RT-DETR-R50 by 0.8 mAP while being faster (8.8 ms vs 9.3 ms), and beats YOLOv10-X by 1.7 mAP at lower latency (8.8 ms vs 10.70 ms). Note that YOLOv10’s numbers are without Objects365 pre-training, which is a real asymmetry — but see below for why it may not be one that closes.

Pre-training is the single largest term

Table 5, mAP with and without Objects365 pre-training:

ModelParams (M)FLOPs (G)Latency (ms)w/o pre-trainingw/ pre-trainingΔ
tiny12.111.22.036.542.6+6.1
small14.616.62.943.648.0+4.4
medium28.242.85.647.252.5+5.3
large46.871.68.849.556.1+6.6
xlarge118.0174.219.153.058.3+5.3
R18 (conv. encoder)21.221.42.540.944.4+3.5
R50 (conv. encoder)54.667.78.749.754.4+4.7

Average mAP. The comparison that makes this interesting is Table 6, the same experiment on the non-end-to-end detectors as a function of schedule length:

ModelPre-trained20 ep60 ep100 ep200 ep300 ep500 ep
YOLOv8n26.230.132.334.035.037.4
YOLOv8n✓31.532.833.234.335.237.6
RTMDet-t30.434.235.236.841.0–
RTMDet-t✓33.436.536.737.541.7–

Objects365 pre-training gives YOLOv8n mAP at 20 epochs but only at 500. Because the YOLO line trains for 300–500 epochs as standard, its published numbers sit exactly where pre-training has stopped helping — the gain is absorbed by the long schedule. LW-DETR, at 50 epochs, is still in the regime where pre-training pays. The paper is explicit that this is a hypothesis with preliminary support, not a settled explanation.

Generalization beyond COCO

Cross-domain, UVO (class-agnostic, 57% of instances outside the 80 COCO classes; models trained on COCO, evaluated directly):

MethodmAPAPAR@100ARARAR
RTMDet-s29.743.355.726.549.471.5
YOLOv8-s29.142.454.327.448.668.8
YOLO-NAS-s31.044.555.125.848.171.6
LW-DETR-small32.345.159.829.452.477.1

mAP and AR over the best competitor, with the recall gain present at every object scale — evidence that the advantage is not COCO-specific tuning.

Multi-domain fine-tuning, RF100 (100 small datasets, 7 imagery domains, AP):

MethodAverageaerialvideogamesmicroscopicunderwaterdocumentselectromagneticreal world
RTMDet-s79.270.188.068.168.081.077.483.3
YOLOv8-s80.170.787.974.770.279.879.082.9
YOLO-NAS-s81.5–––––––
LW-DETR-small82.571.888.974.569.686.784.685.3
LW-DETR-medium83.572.990.875.470.586.186.286.4

The margin is concentrated in documents ( AP) and electromagnetic ( AP) — the two domains least like COCO.

Limitations

  • The gains are not architectural. By the paper’s own ablation, of the mAP the recipe adds to the initial detector come from Objects365 pre-training. Read strictly, LW-DETR demonstrates that a plain-ViT DETR can be made fast, and that pre-training helps DETRs disproportionately — not that this particular stack is better designed than RT-DETR’s.
  • The comparison is not schedule-matched. LW-DETR trains 50 epochs (25 for L/X) plus 30 epochs of Objects365; the YOLO baselines train 300–500 epochs on COCO. Table 6 is the paper’s own evidence that this asymmetry is exactly where the advantage lives, which makes the headline comparison harder to read than it looks.
  • xlarge scales badly. 118M parameters and 174.2 GFLOPs for 58.3 mAP is 2.5× the parameters of large for mAP, at 2.2× the latency. The family’s good operating points are small through large.
  • Detection only. The paper explicitly scopes itself to real-time detection; open-world detection, multi-person pose estimation and multi-view 3D detection are named as untried future work.
  • No multi-scale below large. Three of the five models run a single feature map, and the paper reports no AP breakdown on COCO at all, so the small-object behaviour — historically every DETR’s weak spot, and RT-DETR’s acknowledged one — is not characterized.
  • The authors note the recipe is deliberately minimal and that token sparsification, distillation, efficient multi-scale fusion and NAS (as in YOLO-NAS) are all untried on top of it.

See also

  • RT-DETR — the concurrent real-time DETR LW-DETR is measured against; the opposite design choice (CNN backbone, redesigned encoder) for the same goal
  • DETR Family Comparison — where LW-DETR sits relative to the rest of the line
  • DETR — the set-prediction formulation and NMS-free matching that make the end-to-end latency argument possible
  • Deformable DETR — supplies the deformable cross-attention in LW-DETR’s decoder and the multi-scale decoder used by large/xlarge
  • DINO — source of the mixed query selection scheme
  • DN-DETR — the other “extra supervision, zero inference cost” mechanism; Group DETR plays the same role here
  • YOLOv8 — the C2f block LW-DETR uses as its projector, and a baseline throughout
  • YOLOv10 — the NMS-free YOLO LW-DETR compares against in Table 4
  • Task-Aligned-Assignment — the same IoU/classification alignment idea that IA-BCE applies to the loss target
  • Implementing Research Papers