> This is the documentation for LibreYOLO 1.6.0. Current version: https://www.libreyolo.com/docs/models/lw-detr

# LW-DETR
A plain-ViT detection transformer that Baidu positioned as a real-time alternative to YOLO detectors. LibreYOLO ships five sizes for detection, inference only.
Tasks: Detection. Install: pip install libreyolo.
Verified against LibreYOLO v1.5.0.

## Install

LW-DETR needs no optional extra. Everything it imports is in the base install.

```bash
pip install libreyolo
```

## Predict

Weights download from Hugging Face on first use and are cached locally.

**Python**

```python
from libreyolo import LibreYOLO, SAMPLE_IMAGE

model = LibreYOLO("LibreLWDETRt.pt")
result = model(SAMPLE_IMAGE, save=True)

for box in result.boxes:
    print(box.cls, box.conf, box.xyxy)
```

**CLI**

```bash
libreyolo predict model=LibreLWDETRt.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True
```

The returned `Results` object is the one every family returns, so swapping in a
different detector is a one line change. `conf` and `max_det` filter the query
selection; `iou` is accepted for API parity but has no effect, because the
decoder is a set predictor with no NMS step. See
[prediction](/docs/v1.6.0/predict) for sources, streaming and result handling.

LW-DETR is inference-only in LibreYOLO. Upstream trains with Group-DETR
one-to-many supervision across multiple query groups and an IoU-aware
classification loss; that recipe is not wired here, so `train()` raises
`NotImplementedError`.

## Variants

Five sizes, all sharing the plain-ViT encoder, multi-scale projector and
deformable DETR decoder, and all running at the same input resolution. The two
smallest share an encoder width and split by block depth; the next two share a
wider encoder and split by how many projector levels feed the decoder; the
largest steps up to the widest encoder.

## Validate

`val()` returns a dictionary of `metrics/` keys covering precision, recall,
mAP 50 and mAP 50-95, measured against any dataset in the format you trained on.

**Python**

```python
from libreyolo import LibreYOLO

model = LibreYOLO("LibreLWDETRt.pt")

# val() returns a plain dict, not an object
metrics = model.val(data="my-dataset.yaml")

print(metrics["metrics/mAP50-95"])
print(metrics["metrics/mAP50"])
print(metrics["metrics/precision"], metrics["metrics/recall"])
```

**CLI**

```bash
libreyolo val model=LibreLWDETRt.pt data=my-dataset.yaml
```

## Export

| Task | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Detection | yes | yes | yes | yes | yes |  |  |  |  |  |  |  |

A "yes" means the export is supported. An empty cell means the exporter refuses that combination.

An exported artifact loads back through `LibreYOLO()` on its file suffix, so a
`.onnx` or `.engine` file behaves like a checkpoint and returns the same
`Results`. [Export](/docs/v1.6.0/export) lists the arguments every format accepts.

**Python**

```python
from libreyolo import LibreYOLO

model = LibreYOLO("LibreLWDETRt.pt")
model.export(format="onnx", imgsz=640)
model.export(format="tensorrt", imgsz=640, half=True)
```

**CLI**

```bash
libreyolo export model=LibreLWDETRt.pt format=onnx imgsz=640
libreyolo export model=LibreLWDETRt.pt format=tensorrt imgsz=640 half=True
```

**Use the exported file**

```python
from libreyolo import LibreYOLO, SAMPLE_IMAGE

# The factory routes on the file suffix, so an exported artifact loads
# like any checkpoint and returns the same Results object.
model = LibreYOLO("LibreLWDETRt.onnx")
result = model(SAMPLE_IMAGE)

print(result.boxes.xyxy)
```

## Checkpoints

Every published weight file for this family.

| File | Input (px) | Task | Weights license |
| --- | --- | --- | --- |
| `LibreLWDETRt.pt` | 640 | Detection | apache-2.0 |
| `LibreLWDETRs.pt` | 640 | Detection | apache-2.0 |
| `LibreLWDETRm.pt` | 640 | Detection | apache-2.0 |
| `LibreLWDETRl.pt` | 640 | Detection | apache-2.0 |
| `LibreLWDETRx.pt` | 640 | Detection | apache-2.0 |

## Licensing

Check the license on the Hugging Face repository of the specific weights you download. That repository is authoritative and licenses are not always uniform across a family. This is a description of the licenses involved, not legal advice.

- Original work: LW-DETR, Baidu
- Upstream license: Apache-2.0
- Upstream source: https://github.com/Atten4Vis/LW-DETR
- LibreYOLO code: Apache-2.0
- Weights: Apache-2.0, republished at https://huggingface.co/LibreYOLO
- Interpretation: Apache-2.0 is a permissive license, so these weights can be used in commercial and closed-source products. It asks you to keep its license text and attribution notices with any copy of the weights you redistribute, and it grants a patent license. It places no obligation on your own application code, and weights you train yourself on your own data are yours. The published checkpoints are converted from the upstream Apache-2.0 Hugging Face release (xbsu/LW-DETR) and rehosted under the same license.

## Citation

```bibtex
@article{chen2024lw,
    title={LW-DETR: A Transformer Replacement to YOLO for Real-Time Detection},
    author={Chen, Qiang and Su, Xiangbo and Zhang, Xinyu and Wang, Jian and Chen, Jiahui and Shen, Yunpeng and Han, Chuchu and Chen, Ziliang and Xu, Weixiang and Li, Fanrong and others},
    journal={arXiv preprint arXiv:2406.03459},
    year={2024}
}
```

Copied from https://github.com/Atten4Vis/LW-DETR#10-citation
