MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer
- Publication
- ICLR 2022Conference
- First submitted to arXiv
- arXiv:2110.02178
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{lightweightmobilevit2021,
title = {{MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer}},
author = {Sachin Mehta and Mohammad Rastegari},
year = {2021},
eprint = {2110.02178},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2110.02178}
}
Almost two months after Microsoft introduced Mobile-Former, Apple proposed another way to bring vision transformers to mobile devices: MobileViT.
Problem Definition
The question is how to train a small ViT effectively within a limited parameter and compute budget, while keeping mobile inference practical. Compared with Mobile-Former’s two-way bridge between parallel branches, MobileViT borrows the “unfold, local processing, fold” view of convolution and uses a Transformer to build global relationships across patches. This is a design analogy, not a mathematically equivalent replacement of a convolution kernel’s matrix multiplication.
To better understand how MobileViT works, let’s first review the convolution process.
Solution
Convolution Review
One convolution implementation uses unfold → matrix multiplication → output reshaping. This method is more efficient under certain conditions.
-
1. Unfold Operation
The unfold operation, also called "im2col," reshapes the input tensor (e.g., an image) into a form suitable for matrix multiplication.
For example, consider a input matrix :
Suppose we have a kernel . We use the cross-correlation convention common in deep learning, without flipping the kernel, at stride 1 with no padding:
Normally, the kernel slides across the input matrix to compute convolution values. However, with unfold, we transform this process into matrix multiplication. Using a sliding window, we extract four patches from :
We then flatten these patches into row vectors, forming a matrix:
-
2. Matrix Multiplication
Next, we multiply the unfolded input matrix by the flattened convolution kernel :
Here is and is , so the product is a vector:
-
3. Fold Operation
Here, “fold” simply means reshaping the result into the output grid. A library Fold operation generally sums overlapping patches and is not automatically the inverse of Unfold. In this example we reshape to a matrix:
Unfold → matrix multiplication → output reshaping is one way to implement convolution. Its actual speed depends on tensor layout, memory traffic, and the runtime.
The sliding windows in this example overlap. MobileViT's unfold step below instead arranges non-overlapping patches, so the two unfold operations should not be treated as identical.
MobileViT Architecture
The preceding convolution example makes the block easier to read. MobileViT first mixes nearby positions with an convolution, then projects the features to dimensions with a 1×1 convolution. It rearranges non-overlapping patches into , where is the number of positions per patch and is the number of patches. For each relative position within a patch, the Transformer attends across patches; it does not directly compare every pair of pixels in the entire feature map.
The results are folded into a spatial map, projected with a 1×1 convolution, concatenated with the input, and fused by a local convolution. Under the paper's patch/kernel settings, local mixing and cross-patch attention together yield a global receptive field; a single attention operation does not directly compare every pair of pixels.
Since self-attention is more computationally expensive, it is applied selectively. The authors chose specific layers to apply this substitution, as shown below:
MobileViT blocks operate at the last three spatial scales, alongside retained convolutions and MobileNetV2 blocks. The MobileNetV2 blocks chiefly handle downsampling. This supports a shallower, narrower hybrid network.
Experimental Setup
The authors trained MobileViT on the ImageNet-1k dataset, which includes 1.28 million training images and 50,000 validation images. Training was conducted using PyTorch on eight NVIDIA GPUs for 300 epochs. They used the AdamW optimizer and cross-entropy loss with a label smoothing factor of 0.1. The effective batch size was 1,024 images, with a learning rate that gradually increased from 0.0002 to 0.002 over the first 3,000 iterations, then decayed back to 0.0002 following a cosine schedule. L2 weight decay was set at 0.01.
The multi-scale sampler improves accuracy by about 0.5 percentage points and training efficiency by adapting batch size to resolution. It is another contribution of the paper; this note focuses on architecture. Training uses random resized crops and horizontal flips; evaluation reports single-crop top-1 accuracy with an exponential moving average of model weights.
Discussion
Performance on ImageNet
-
MobileViT Outperforms Lightweight CNNs:
- Across different model sizes, MobileViT consistently outperformed lightweight CNN models such as MobileNetv1, MobileNetv2, ShuffleNetv2, ESPNetv2, and MobileNetv3.
- In Figure 8(b), MobileViT-XS has 2.3M parameters and 74.8% top-1. Against models with roughly 2.3–2.6M parameters, it is:
- 5 percentage points higher accuracy than MobileNetv2,
- 5.4 percentage points higher than ShuffleNetv2,
- 7.4 percentage points higher than MobileNetv3.
-
MobileViT Outperforms Heavier CNNs:
- Figure 8(c) puts MobileViT-S (5.6M parameters, 78.4%) above the listed DenseNet-169, ResNet-101, ResNet-101-SE, and the similarly sized EfficientNet-B0.
- EfficientNet-B0 has 5.3M parameters and 76.3% top-1, a gap of 2.1 percentage points. This historical comparison concerns these model configurations and training conditions, not every larger CNN.
Red denotes advanced augmentation and green denotes basic augmentation; the table columns read Advanced and Basic. Advanced recipes may include Mixup, CutMix, and RandAugment. The models do not all share an otherwise identical training recipe.
-
Comparison with ViT Variants:
- MobileViT was compared against various ViT variants trained from scratch, including DeIT, T2T, PVT, CAIT, DeepViT, CeiT, CrossViT, LocalViT, PiT, ConViT, ViL, BotNet, and Mobile-Former.
- In Figure 9(b), MobileViT-XS uses basic augmentation and has 2.3M parameters, about 40% of the 5.7M-parameter DeiT configuration trained with advanced augmentation. It scores 2.6 percentage points higher (74.8% versus 72.2%). This compares two specified configurations; other ViT variants in the figure score higher.
The authors take this as evidence of CNN-like trainability. They separately evaluate MobileViT as a detection and segmentation backbone.
Conclusion
While MobileViT outperforms many lightweight and heavyweight CNN models on ImageNet-1k, its inference speed on mobile devices remains a challenge.
The table reports iPhone 12 Neural Engine results at batch size 1: MobileViT-XS takes 7.28 ms versus MobileNetV2's 0.92 ms, a latency ratio of about 7.9. However, MobileViT uses 256×256 inputs while the others use 224×224, so this is not a controlled equal-resolution comparison or a universal ViT/CNN ratio. The MobileNetV2 accuracy result in the table also uses a multi-scale sampler. The authors discuss two possible factors:
- Transformers benefit from dedicated CUDA kernels on GPUs, but these optimizations do not automatically carry over to phones.
- CNNs benefit from device-level optimizations, such as fusing convolutions with batch normalization, which improve latency and memory access.
Under the paper's runtimes, MobileViT was more accurate yet slower than MobileNetV2 on this phone. Later hardware and software optimizations may change that trade-off; parameters or FLOPs alone cannot determine real latency.