# DeiT

**Category:** ViT · **Code:**
[`timm/models/deit.py`](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/deit.py) ·
**Architectures:** 16 · **Pretrained weights:** 24 (24 with ImageNet-1k results)

Data-efficient Image Transformers (DeiT) are Vision Transformers trained on ImageNet-1k only, optionally with a
distillation token that learns from a CNN teacher. DeiT III models are trained with an improved recipe.

## Papers

* [Training data-efficient image transformers & distillation through attention](https://arxiv.org/abs/2012.12877)
* [DeiT III: Revenge of the ViT](https://arxiv.org/abs/2204.07118)

## Usage

See the [Quickstart](../quickstart) for loading pretrained weights, image preprocessing and fine-tuning, and [Feature
Extraction](../feature_extraction) for using the models as backbones.

```py
>>> import timm
>>> model = timm.create_model('deit_small_distilled_patch16_224.fb_in1k', pretrained=True)
>>> data_config = timm.data.resolve_model_data_config(model)
```

## Model API support

| Feature | `VisionTransformer` | `VisionTransformerDistilled` |
|---|---|---|
| [`features_only=True` feature maps](../model_api#intermediate-features) | ✓ (strides 16, 16, 16) | ✓ (strides 16, 16, 16) |
| [`forward_intermediates()`](../model_api#intermediate-features) | ✓ | ✓ |
| [`prune_intermediate_layers()`](../model_api#intermediate-features) | ✓ | ✓ |
| [Any input size, no changes needed](../model_api#input-size) | ✗ | ✗ |
| [`set_input_size()`](../model_api#input-size) | ✓ | ✓ |
| [`dynamic_img_size=True`](../model_api#input-size) | ✓ | ✓ |
| [`set_grad_checkpointing()`](../model_api#training-hooks) | ✓ | ✓ |
| [Layer-wise LR decay (`group_matcher()`)](../model_api#training-hooks) | ✓ | ✓ |
| [`reset_classifier()`](../model_api#classifier) | ✓ | ✓ |

✓ supported, ✓ (square) works for square sizes only, ✗ not supported, – not needed (the model already accepts any input
size). Checked by running each feature on a randomly initialized model (`VisionTransformer` with `deit_tiny_patch16_224`
at 224, `VisionTransformerDistilled` with `deit_tiny_distilled_patch16_224` at 224), other architectures of the same
class are expected to behave the same. See the [Model API](../model_api) page for details.

## Architectures

| Architecture | Class | Params (M) | GMACs | Input size | Pretrained weights |
|---|---|---:|---:|---:|---:|
| `deit3_base_patch16_224` | `VisionTransformer` | 86.59 | 17.58 | 224 | 2 |
| `deit3_base_patch16_384` | `VisionTransformer` | 86.88 | 55.54 | 384 | 2 |
| `deit3_huge_patch14_224` | `VisionTransformer` | 632.13 | 167.40 | 224 | 2 |
| `deit3_large_patch16_224` | `VisionTransformer` | 304.37 | 61.60 | 224 | 2 |
| `deit3_large_patch16_384` | `VisionTransformer` | 304.76 | 191.21 | 384 | 2 |
| `deit3_medium_patch16_224` | `VisionTransformer` | 38.85 | 8.00 | 224 | 2 |
| `deit3_small_patch16_224` | `VisionTransformer` | 22.06 | 4.61 | 224 | 2 |
| `deit3_small_patch16_384` | `VisionTransformer` | 22.21 | 15.52 | 384 | 2 |
| `deit_base_distilled_patch16_224` | `VisionTransformerDistilled` | 87.34 | 17.68 | 224 | 1 |
| `deit_base_distilled_patch16_384` | `VisionTransformerDistilled` | 87.63 | 55.65 | 384 | 1 |
| `deit_base_patch16_224` | `VisionTransformer` | 86.57 | 17.58 | 224 | 1 |
| `deit_base_patch16_384` | `VisionTransformer` | 86.86 | 55.54 | 384 | 1 |
| `deit_small_distilled_patch16_224` | `VisionTransformerDistilled` | 22.44 | 4.63 | 224 | 1 |
| `deit_small_patch16_224` | `VisionTransformer` | 22.05 | 4.61 | 224 | 1 |
| `deit_tiny_distilled_patch16_224` | `VisionTransformerDistilled` | 5.91 | 1.27 | 224 | 1 |
| `deit_tiny_patch16_224` | `VisionTransformer` | 5.72 | 1.26 | 224 | 1 |

GMACs and parameter counts are for the default input size and classifier of each architecture, from the [benchmark
results](https://github.com/huggingface/pytorch-image-models/tree/main/results).

## Pretrained weights

Top-1 is ImageNet-1k validation accuracy from
[`results-imagenet.csv`](https://github.com/huggingface/pytorch-image-models/blob/main/results/results-imagenet.csv) at
the listed eval size, - if the weight has no ImageNet-1k result (e.g. pretraining or image-text weights). Classes is the
size of the pretrained classifier, none for weights without one.

| Weight | Input size | Top-1 (%) | Eval size | Classes | License | Hub |
|---|---:|---:|---:|---:|---|---|
| `deit3_base_patch16_224.fb_in1k` | 224 | 83.800 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_base_patch16_224.fb_in1k) |
| `deit3_base_patch16_224.fb_in22k_ft_in1k` | 224 | 85.728 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_base_patch16_224.fb_in22k_ft_in1k) |
| `deit3_base_patch16_384.fb_in1k` | 384 | 85.088 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_base_patch16_384.fb_in1k) |
| `deit3_base_patch16_384.fb_in22k_ft_in1k` | 384 | 86.742 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_base_patch16_384.fb_in22k_ft_in1k) |
| `deit3_huge_patch14_224.fb_in1k` | 224 | 85.204 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_huge_patch14_224.fb_in1k) |
| `deit3_huge_patch14_224.fb_in22k_ft_in1k` | 224 | 87.180 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_huge_patch14_224.fb_in22k_ft_in1k) |
| `deit3_large_patch16_224.fb_in1k` | 224 | 84.772 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_large_patch16_224.fb_in1k) |
| `deit3_large_patch16_224.fb_in22k_ft_in1k` | 224 | 86.990 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_large_patch16_224.fb_in22k_ft_in1k) |
| `deit3_large_patch16_384.fb_in1k` | 384 | 85.820 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_large_patch16_384.fb_in1k) |
| `deit3_large_patch16_384.fb_in22k_ft_in1k` | 384 | 87.736 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_large_patch16_384.fb_in22k_ft_in1k) |
| `deit3_medium_patch16_224.fb_in1k` | 224 | 83.090 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_medium_patch16_224.fb_in1k) |
| `deit3_medium_patch16_224.fb_in22k_ft_in1k` | 224 | 84.550 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_medium_patch16_224.fb_in22k_ft_in1k) |
| `deit3_small_patch16_224.fb_in1k` | 224 | 81.382 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_small_patch16_224.fb_in1k) |
| `deit3_small_patch16_224.fb_in22k_ft_in1k` | 224 | 83.082 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_small_patch16_224.fb_in22k_ft_in1k) |
| `deit3_small_patch16_384.fb_in1k` | 384 | 83.432 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_small_patch16_384.fb_in1k) |
| `deit3_small_patch16_384.fb_in22k_ft_in1k` | 384 | 84.846 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit3_small_patch16_384.fb_in22k_ft_in1k) |
| `deit_base_distilled_patch16_224.fb_in1k` | 224 | 83.384 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit_base_distilled_patch16_224.fb_in1k) |
| `deit_base_distilled_patch16_384.fb_in1k` | 384 | 85.438 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit_base_distilled_patch16_384.fb_in1k) |
| `deit_base_patch16_224.fb_in1k` | 224 | 81.980 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit_base_patch16_224.fb_in1k) |
| `deit_base_patch16_384.fb_in1k` | 384 | 83.108 | 384 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit_base_patch16_384.fb_in1k) |
| `deit_small_distilled_patch16_224.fb_in1k` | 224 | 81.204 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit_small_distilled_patch16_224.fb_in1k) |
| `deit_small_patch16_224.fb_in1k` | 224 | 79.856 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit_small_patch16_224.fb_in1k) |
| `deit_tiny_distilled_patch16_224.fb_in1k` | 224 | 74.538 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit_tiny_distilled_patch16_224.fb_in1k) |
| `deit_tiny_patch16_224.fb_in1k` | 224 | 72.190 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/deit_tiny_patch16_224.fb_in1k) |

