# RepViT

**Category:** Efficient/Mobile · **Code:**
[`timm/models/repvit.py`](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/repvit.py) ·
**Architectures:** 8 · **Pretrained weights:** 13 (13 with ImageNet-1k results)

RepViT is a mobile CNN that brings design choices of lightweight vision transformers into MobileNet-V3 style blocks,
with structural re-parameterization.

## Papers

* [RepViT: Revisiting Mobile CNN From ViT Perspective](https://arxiv.org/abs/2307.09283)

## 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('repvit_m2_3.dist_300e_in1k', pretrained=True)
>>> data_config = timm.data.resolve_model_data_config(model)
```

## Model API support

| Feature | `RepVit` |
|---|---|
| [`features_only=True` feature maps](../model_api#intermediate-features) | ✓ (strides 4, 8, 16, 32) |
| [`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 (`RepVit` with `repvit_m1` 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 | Params (M) | GMACs | Input size | Pretrained weights |
|---|---:|---:|---:|---:|
| `repvit_m0_9` | 5.07 | 0.82 | 224 | 2 |
| `repvit_m1` | 5.07 | 0.82 | 224 | 1 |
| `repvit_m1_0` | 6.81 | 1.11 | 224 | 2 |
| `repvit_m1_1` | 8.24 | 1.34 | 224 | 2 |
| `repvit_m1_5` | 14.05 | 2.27 | 224 | 2 |
| `repvit_m2` | 8.24 | 1.34 | 224 | 1 |
| `repvit_m2_3` | 22.93 | 4.52 | 224 | 2 |
| `repvit_m3` | 10.12 | 1.86 | 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 |
|---|---:|---:|---:|---:|---|---|
| `repvit_m0_9.dist_300e_in1k` | 224 | 78.652 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/repvit_m0_9.dist_300e_in1k) |
| `repvit_m0_9.dist_450e_in1k` | 224 | 79.058 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/repvit_m0_9.dist_450e_in1k) |
| `repvit_m1.dist_in1k` | 224 | 78.542 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/repvit_m1.dist_in1k) |
| `repvit_m1_0.dist_300e_in1k` | 224 | 80.152 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/repvit_m1_0.dist_300e_in1k) |
| `repvit_m1_0.dist_450e_in1k` | 224 | 80.430 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/repvit_m1_0.dist_450e_in1k) |
| `repvit_m1_1.dist_300e_in1k` | 224 | 80.826 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/repvit_m1_1.dist_300e_in1k) |
| `repvit_m1_1.dist_450e_in1k` | 224 | 81.314 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/repvit_m1_1.dist_450e_in1k) |
| `repvit_m1_5.dist_300e_in1k` | 224 | 82.382 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/repvit_m1_5.dist_300e_in1k) |
| `repvit_m1_5.dist_450e_in1k` | 224 | 82.520 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/repvit_m1_5.dist_450e_in1k) |
| `repvit_m2.dist_in1k` | 224 | 80.468 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/repvit_m2.dist_in1k) |
| `repvit_m2_3.dist_300e_in1k` | 224 | 83.524 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/repvit_m2_3.dist_300e_in1k) |
| `repvit_m2_3.dist_450e_in1k` | 224 | 83.746 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/repvit_m2_3.dist_450e_in1k) |
| `repvit_m3.dist_in1k` | 224 | 81.494 | 224 | 1000 | apache-2.0 | [timm](https://huggingface.co/timm/repvit_m3.dist_in1k) |

## Citation

```bibtex
@misc{wang2023repvit,
      title={RepViT: Revisiting Mobile CNN From ViT Perspective},
      author={Ao Wang and Hui Chen and Zijia Lin and Hengjun Pu and Guiguang Ding},
      year={2023},
      eprint={2307.09283},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}
```

