# DeiT

**카테고리:** ViT · **코드:** [`timm/models/deit.py`](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/deit.py) · **아키텍처:** 16 · **프리트레이닝 가중치:** 24 (ImageNet-1k 결과 포함 24개)

Data-efficient Image Transformers(DeiT)는 ImageNet-1k에서만 학습된 Vision Transformers이며, CNN teacher로부터 학습하는 distillation token을 선택적으로 사용할 수 있습니다. DeiT III 모델은 개선된 학습 레시피로 학습됩니다.

## 논문

* [Attention을 통한 데이터 효율적 이미지 Transformer 및 증류](https://arxiv.org/abs/2012.12877)
* [DeiT III: ViT의 복수](https://arxiv.org/abs/2204.07118)

## 사용

사전 학습된 가중치 로드, 이미지 전처리 및 파인튜닝에 대해서는 [Quickstart](../quickstart)를, 모델을 백본으로 사용하는 방법에 대해서는 [Feature Extraction](../feature_extraction)을 참고하세요.

```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)
```

## 모델 API 지원

| 기능 | `VisionTransformer` | `VisionTransformerDistilled` |
|---|---|---|
| [`features_only=True` feature map](../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) | ✓ | ✓ |
| [입력 크기 무관, 변경 불필요](../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) | ✓ | ✓ |
| [레이어별 LR 감쇠(`group_matcher()`)](../model_api#training-hooks) | ✓ | ✓ |
| [`reset_classifier()`](../model_api#classifier) | ✓ | ✓ |

✓ 지원됨, ✓ (정사각형) 정사각형 크기만 작동, ✗ 미지원, – 필요 없음(모델이 이미 모든 입력 크기를 허용). 무작위로 초기화된 모델(`VisionTransformer`는 `deit_tiny_patch16_224`를 224로, `VisionTransformerDistilled`는 `deit_tiny_distilled_patch16_224`를 224로)에서 각 기능을 실행하여 확인했으며, 같은 클래스의 다른 아키텍처도 동일한 동작을 하는 것으로 예상됩니다. 자세한 내용은 [Model API](../model_api) 페이지를 참조하세요.

## 아키텍처

| 아키텍처 | 클래스 | 매개변수 (M) | GMAC | 입력 크기 | 사전 학습된 가중치 |
|---|---|---:|---:|---:|---:|
| `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와 매개변수 수는 각 아키텍처의 기본 입력 크기 및 분류기를 기준으로 하며, [벤치마크 결과](https://github.com/huggingface/pytorch-image-models/tree/main/results)에서 가져온 값입니다.

## 사전 학습된 가중치

Top-1은 [`results-imagenet.csv`](https://github.com/huggingface/pytorch-image-models/blob/main/results/results-imagenet.csv)에 나열된 평가 크기에서 측정된 ImageNet-1k 검증 정확도이며, 해당 가중치에 ImageNet-1k 결과가 없는 경우(예: 사전 학습 또는 이미지-텍스트 가중치)에는 '-'로 표시됩니다. Classes는 사전 학습된 분류기의 크기를 나타내며, 분류기가 없는 가중치의 경우 해당 값이 없습니다.

| 가중치 | 입력 크기 | Top-1(%) | 평가 크기 | 클래스 | 라이선스 | 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) |

