# MobileViT

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

MobileViT combines MobileNet-V2 inverted residual blocks with MobileViT blocks, which apply transformers to unfolded
patches for global processing. MobileViT-V2 uses separable self-attention. Built on the `ByobNet` class.

## Papers

* [MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer](https://arxiv.org/abs/2110.02178)
* [Separable Self-attention for Mobile Vision Transformers](https://arxiv.org/abs/2206.02680)

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

## Model API support

| Feature | `ByobNet` |
|---|---|
| [`features_only=True` feature maps](../model_api#intermediate-features) | ✓ (strides 2, 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 (`ByobNet` with `mobilevit_xxs` at 256), 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 |
|---|---:|---:|---:|---:|
| `mobilevit_s` | 5.58 | 2.03 | 256 | 1 |
| `mobilevit_xs` | 2.32 | 1.05 | 256 | 1 |
| `mobilevit_xxs` | 1.27 | 0.42 | 256 | 1 |
| `mobilevitv2_050` | 1.37 | 0.48 | 256 | 1 |
| `mobilevitv2_075` | 2.87 | 1.05 | 256 | 1 |
| `mobilevitv2_100` | 4.90 | 1.84 | 256 | 1 |
| `mobilevitv2_125` | 7.48 | 2.86 | 256 | 1 |
| `mobilevitv2_150` | 10.59 | 4.09 | 256 | 3 |
| `mobilevitv2_175` | 14.25 | 5.54 | 256 | 3 |
| `mobilevitv2_200` | 18.45 | 7.22 | 256 | 3 |

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 |
|---|---:|---:|---:|---:|---|---|
| `mobilevit_s.cvnets_in1k` | 256 | 78.298 | 256 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevit_s.cvnets_in1k) |
| `mobilevit_xs.cvnets_in1k` | 256 | 74.618 | 256 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevit_xs.cvnets_in1k) |
| `mobilevit_xxs.cvnets_in1k` | 256 | 68.936 | 256 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevit_xxs.cvnets_in1k) |
| `mobilevitv2_050.cvnets_in1k` | 256 | 70.156 | 256 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevitv2_050.cvnets_in1k) |
| `mobilevitv2_075.cvnets_in1k` | 256 | 75.612 | 256 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevitv2_075.cvnets_in1k) |
| `mobilevitv2_100.cvnets_in1k` | 256 | 78.088 | 256 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevitv2_100.cvnets_in1k) |
| `mobilevitv2_125.cvnets_in1k` | 256 | 79.682 | 256 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevitv2_125.cvnets_in1k) |
| `mobilevitv2_150.cvnets_in1k` | 256 | 80.380 | 256 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevitv2_150.cvnets_in1k) |
| `mobilevitv2_150.cvnets_in22k_ft_in1k` | 256 | 81.466 | 256 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevitv2_150.cvnets_in22k_ft_in1k) |
| `mobilevitv2_150.cvnets_in22k_ft_in1k_384` | 384 | 82.606 | 384 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevitv2_150.cvnets_in22k_ft_in1k_384) |
| `mobilevitv2_175.cvnets_in1k` | 256 | 80.870 | 256 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevitv2_175.cvnets_in1k) |
| `mobilevitv2_175.cvnets_in22k_ft_in1k` | 256 | 81.950 | 256 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevitv2_175.cvnets_in22k_ft_in1k) |
| `mobilevitv2_175.cvnets_in22k_ft_in1k_384` | 384 | 82.920 | 384 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevitv2_175.cvnets_in22k_ft_in1k_384) |
| `mobilevitv2_200.cvnets_in1k` | 256 | 81.148 | 256 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevitv2_200.cvnets_in1k) |
| `mobilevitv2_200.cvnets_in22k_ft_in1k` | 256 | 82.320 | 256 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevitv2_200.cvnets_in22k_ft_in1k) |
| `mobilevitv2_200.cvnets_in22k_ft_in1k_384` | 384 | 83.430 | 384 | 1000 | cvnets-license | [timm](https://huggingface.co/timm/mobilevitv2_200.cvnets_in22k_ft_in1k_384) |

