> This is the documentation for LibreYOLO 1.5.0. Current version: https://www.libreyolo.com/docs/models/deit

# DeiT
DeiT (Data-efficient image Transformer) is a plain Vision Transformer classifier trained on ImageNet-1k alone, with no extra pretraining data. LibreYOLO carries the tiny, small and base patch-16 sizes as a frozen, inference-only exhibit.
Tasks: classify. Install: pip install libreyolo.
Verified against LibreYOLO v1.5.0.

## Install

DeiT needs no extra beyond the base package.

```bash
pip install libreyolo
```

## Predict

This family is inference-only: `train()` raises `NotImplementedError`, so this
page has no Train section. Predict, validate and export are all supported.
Weights download from Hugging Face on first use and are cached locally. The
`-cls` suffix in the filename is required and selects the classification task.

**Python**

```python
from libreyolo import LibreYOLO, SAMPLE_IMAGE

model = LibreYOLO("LibreDeiTb-cls.pt")
result = model(SAMPLE_IMAGE)

print(result.probs.top1, result.probs.top1conf)
print(result.probs.top5)
```

**CLI**

```bash
libreyolo predict model=LibreDeiTb-cls.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg
```

The returned `Results` object carries a `probs` tensor instead of `boxes`;
`top1` and `top5` index the 1,000 ImageNet-1k classes and `top1conf` is the
softmax score for the top prediction. Each size has a fixed input resolution
from its positional embedding: preprocessing resizes and center-crops to it,
and passing a different `imgsz` raises rather than silently resampling. See
[prediction](/docs/v1.5.0/predict) for sources, streaming and result handling.

## Validate

`val()` returns a dictionary with top-1 and top-5 accuracy, measured against a
dataset laid out in the conventional `train/<class>/` and `val/<class>/`
folder structure.

**Python**

```python
from libreyolo import LibreYOLO

model = LibreYOLO("LibreDeiTb-cls.pt")
metrics = model.val(data="my-dataset.yaml")

print(metrics["metrics/accuracy_top1"])
print(metrics["metrics/accuracy_top5"])
```

**CLI**

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

## Export

| Task | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| classify | yes | 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`. Running the graph in a bare runtime, with no LibreYOLO installed, is
also supported, but then preprocessing and postprocessing are yours to write.

**Python**

```python
from libreyolo import LibreYOLO

model = LibreYOLO("LibreDeiTb-cls.pt")
model.export(format="onnx")
model.export(format="tensorrt", half=True)
```

**CLI**

```bash
libreyolo export model=LibreDeiTb-cls.pt format=onnx
libreyolo export model=LibreDeiTb-cls.pt format=tensorrt 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("LibreDeiTb-cls.onnx")
result = model(SAMPLE_IMAGE)

print(result.probs.top1)
```

## Checkpoints

Every published weight file for this family.

| File | Input (px) | Task | Weights license |
| --- | --- | --- | --- |
| `LibreDeiTt-cls.pt` | 224 | classify | apache-2.0 |
| `LibreDeiTs-cls.pt` | 224 | classify | apache-2.0 |
| `LibreDeiTb-cls.pt` | 224 | classify | 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: DeiT, Meta Research
- Upstream license: Apache-2.0
- Upstream source: https://github.com/facebookresearch/deit
- 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. LibreYOLO ships the plain tiny, small and base patch-16 classifiers at fixed 224px only; the distillation-token, CaiT, DeiT III and 384px variants from the same repository are out of scope.

## Citation

```bibtex
@InProceedings{pmlr-v139-touvron21a,
  title =     {Training data-efficient image transformers & distillation through attention},
  author =    {Touvron, Hugo and Cord, Matthieu and Douze, Matthijs and Massa, Francisco and Sablayrolles, Alexandre and Jegou, Herve},
  booktitle = {International Conference on Machine Learning},
  pages =     {10347--10357},
  year =      {2021},
  volume =    {139},
  month =     {July}
}
```

Copied from https://github.com/facebookresearch/deit#-model-zoo


## DeiT architecture

- DeiT t: [SVG](/diagrams/models/deit/t-classify.svg), [interactive diagram](/diagrams/models/deit/t-classify.html)
- DeiT s: [SVG](/diagrams/models/deit/s-classify.svg), [interactive diagram](/diagrams/models/deit/s-classify.html)
- DeiT b: [SVG](/diagrams/models/deit/b-classify.svg), [interactive diagram](/diagrams/models/deit/b-classify.html)
- DeiT family: [SVG](/diagrams/models/deit/family-classify.svg), [interactive diagram](/diagrams/models/deit/family-classify.html)
