# MLP-Mixer, ResMLP 및 gMLP

**카테고리:** MLP · **코드:** [`timm/models/mlp_mixer.py`](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/mlp_mixer.py) · **아키텍처:** 15 · **프리트레인드 가중치:** 19 (ImageNet-1k 결과가 포함된 14개)

패치 간 토큰 믹싱과 채널 믹싱을 번갈아 사용하는 All-MLP 아키텍처: MLP-Mixer, ResMLP 및 gMLP(공간 투영을 통한 게이팅). 모듈 docstring에는 gMLP 구현이 검증되지 않았다고 명시되어 있습니다.

## 논문

* [MLP-Mixer: 비전용 올-MLP 아키텍처](https://arxiv.org/abs/2105.01601)
* [ResMLP: 데이터 효율적 학습을 위한 이미지 분류 피드포워드 네트워크](https://arxiv.org/abs/2105.03404)
* [MLP에 주목하세요](https://arxiv.org/abs/2105.08050)
* [대중을 위한 ImageNet-21K 사전 학습](https://arxiv.org/abs/2104.10972)
* [자기지도 Vision Transformer의 부상하는 특성](https://arxiv.org/abs/2104.14294)

## 사용

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

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

## 모델 API 지원

| 기능 | `MlpMixer` |
|---|---|
| [`features_only=True` feature map](../model_api#intermediate-features) | ✓ (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) | ✓ |

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

## 아키텍처

| 아키텍처 | 매개변수 (M) | GMAC | 입력 크기 | 사전 학습된 가중치 |
|---|---:|---:|---:|---:|
| `gmixer_12_224` | 12.70 | 2.67 | 224 | 0 |
| `gmixer_24_224` | 24.72 | 5.28 | 224 | 1 |
| `gmlp_b16_224` | 73.08 | 15.78 | 224 | 0 |
| `gmlp_s16_224` | 19.42 | 4.42 | 224 | 1 |
| `gmlp_ti16_224` | 5.87 | 1.34 | 224 | 0 |
| `mixer_b16_224` | 59.88 | 12.62 | 224 | 4 |
| `mixer_b32_224` | 60.29 | 3.24 | 224 | 0 |
| `mixer_l16_224` | 208.20 | 44.60 | 224 | 2 |
| `mixer_l32_224` | 206.94 | 11.27 | 224 | 0 |
| `mixer_s16_224` | 18.53 | 3.79 | 224 | 0 |
| `mixer_s32_224` | 19.10 | 1.00 | 224 | 0 |
| `resmlp_12_224` | 15.35 | 3.01 | 224 | 3 |
| `resmlp_24_224` | 30.02 | 5.96 | 224 | 3 |
| `resmlp_36_224` | 44.69 | 8.91 | 224 | 2 |
| `resmlp_big_24_224` | 129.14 | 100.23 | 224 | 3 |

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는 사전 학습된 분류기의 크기를 나타내며, 분류기가 없는 가중치의 경우 해당 값이 없습니다.

Weights는 소스에 따라 그룹화됩니다: 사전 학습 설정에 명시된 논문 또는 출처, `timm`가 아닌 Hub 조직, 사전 학습 태그의 첫 번째 부분(`architecture.tag`) 순서입니다. 단일 weight만 있는 소스는 other에 나열됩니다.

### `fb` 태그

| 가중치 | 입력 크기 | Top-1(%) | 평가 크기 | 클래스 | 라이선스 | Hub |
|---|---:|---:|---:|---:|---|---|
| `resmlp_12_224.fb_dino` | 224 | - | - | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/resmlp_12_224.fb_dino) |
| `resmlp_12_224.fb_distilled_in1k` | 224 | 77.948 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/resmlp_12_224.fb_distilled_in1k) |
| `resmlp_12_224.fb_in1k` | 224 | 76.660 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/resmlp_12_224.fb_in1k) |
| `resmlp_24_224.fb_dino` | 224 | - | - | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/resmlp_24_224.fb_dino) |
| `resmlp_24_224.fb_distilled_in1k` | 224 | 80.766 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/resmlp_24_224.fb_distilled_in1k) |
| `resmlp_24_224.fb_in1k` | 224 | 79.380 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/resmlp_24_224.fb_in1k) |
| `resmlp_36_224.fb_distilled_in1k` | 224 | 81.150 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/resmlp_36_224.fb_distilled_in1k) |
| `resmlp_36_224.fb_in1k` | 224 | 79.772 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/resmlp_36_224.fb_in1k) |
| `resmlp_big_24_224.fb_distilled_in1k` | 224 | 83.594 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/resmlp_big_24_224.fb_distilled_in1k) |
| `resmlp_big_24_224.fb_in1k` | 224 | 81.034 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/resmlp_big_24_224.fb_in1k) |
| `resmlp_big_24_224.fb_in22k_ft_in1k` | 224 | 84.414 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/resmlp_big_24_224.fb_in22k_ft_in1k) |

### `goog` 태그

| 가중치 | 입력 크기 | Top-1(%) | 평가 크기 | 클래스 | 라이선스 | Hub |
|---|---:|---:|---:|---:|---|---|
| `mixer_b16_224.goog_in21k` | 224 | - | - | 21843 | apache-2.0 | [timm](https://huggingface.co/timm/mixer_b16_224.goog_in21k) |
| `mixer_b16_224.goog_in21k_ft_in1k` | 224 | 76.616 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/mixer_b16_224.goog_in21k_ft_in1k) |
| `mixer_l16_224.goog_in21k` | 224 | - | - | 21843 | apache-2.0 | [timm](https://huggingface.co/timm/mixer_l16_224.goog_in21k) |
| `mixer_l16_224.goog_in21k_ft_in1k` | 224 | 72.084 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/mixer_l16_224.goog_in21k_ft_in1k) |

### `miil` 태그

| 가중치 | 입력 크기 | Top-1(%) | 평가 크기 | 클래스 | 라이선스 | Hub |
|---|---:|---:|---:|---:|---|---|
| `mixer_b16_224.miil_in21k` | 224 | - | - | 11221 | apache-2.0 | [timm](https://huggingface.co/timm/mixer_b16_224.miil_in21k) |
| `mixer_b16_224.miil_in21k_ft_in1k` | 224 | 82.314 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/mixer_b16_224.miil_in21k_ft_in1k) |

### `ra3` 태그

| 가중치 | 입력 크기 | Top-1(%) | 평가 크기 | 클래스 | 라이선스 | Hub |
|---|---:|---:|---:|---:|---|---|
| `gmixer_24_224.ra3_in1k` | 224 | 78.048 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/gmixer_24_224.ra3_in1k) |
| `gmlp_s16_224.ra3_in1k` | 224 | 79.652 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/gmlp_s16_224.ra3_in1k) |

## 인용

```bibtex
@article{tolstikhin2021,
  title={MLP-Mixer: An all-MLP Architecture for Vision},
  author={Tolstikhin, Ilya and Houlsby, Neil and Kolesnikov, Alexander and Beyer, Lucas and Zhai, Xiaohua and Unterthiner,
        Thomas and Yung, Jessica and Keysers, Daniel and Uszkoreit, Jakob and Lucic, Mario and Dosovitskiy, Alexey},
  journal={arXiv preprint arXiv:2105.01601},
  year={2021}
}

@misc{touvron2021resmlp,
      title={ResMLP: Feedforward networks for image classification with data-efficient training},
      author={Hugo Touvron and Piotr Bojanowski and Mathilde Caron and Matthieu Cord and Alaaeldin El-Nouby and
        Edouard Grave and Armand Joulin and Gabriel Synnaeve and Jakob Verbeek and Hervé Jégou},
      year={2021},
      eprint={2105.03404},
}

@misc{liu2021pay,
      title={Pay Attention to MLPs},
      author={Hanxiao Liu and Zihang Dai and David R. So and Quoc V. Le},
      year={2021},
      eprint={2105.08050},
}
```

