RepViT: Revisiting Mobile CNN From ViT Perspective
- Publication
- CVPR 2024Conference
- First submitted to arXiv
- arXiv:2307.09283
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{reparameterizationrepvit2023,
title = {{RepViT: Revisiting Mobile CNN From ViT Perspective}},
author = {Ao Wang and Hui Chen and Zijia Lin and Jungong Han and Guiguang Ding},
year = {2023},
eprint = {2307.09283},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2307.09283}
}
Research on reparameterization is thriving and gradually spreading to different model architectures.
This paper aims to redesign MobileNet-V3. Unlike the previous papers we looked at, this time we start from the ViT perspective. Structural reparameterization is used inside selected blocks; the entire original MobileNet-V3 is not simply converted into an equivalent network.
Problem Definition
Research on lightweight vision models is primarily divided into two camps:
- CNN-Based Research: Represented by models like the MobileNet series, which reduce the number of parameters through depthwise separable convolutions and enhance the model's expressiveness using inverted residual bottleneck structures.
- ViT-Based Research: Represented by models like MobileViT, Mobile-Former, and FastViT, which combine convolution and attention in different ways; the separation of token and channel mixing can be analyzed from the MetaFormer perspective.
Is there an insurmountable gap between these two camps?
This paper aims to bridge this gap by redesigning MobileNet-V3 and rethinking it from the ViT perspective.
Solution Approach
Redesigning the Architecture
The main target is measured latency on an iPhone 12. Parameter count and FLOPs still appear in the later comparison tables.
The goal is to be fast, faster, and extremely fast!
We start with MobileNet-V3 and take inspiration from recent lightweight ViTs, which typically use DeiT's training methods.
Specifically, the training methods used include:
- AdamW optimizer
- Cosine learning rate decay; the architectural experiments train for 300 epochs, while the main results also include 450-epoch runs
- RegNetY-16GF as the teacher for knowledge distillation in the main comparison table; the step-by-step architectural experiments in the figure do not use distillation
- Mixup, AutoAugment and Random Erasing for data augmentation, together with Label Smoothing
The subsequent architectural changes follow this training setup; whether distillation is used depends on the particular experiment table. Latency is measured on iPhone 12 with iOS 16, Core ML compilation and batch size 1. The MobileNetV3-L baseline also uses GELU for compiler compatibility.
Reparameterizing the Structure
Next, the structure of MobileNet-V3 is adjusted.
MetaFormer offers a useful decomposition of a block into two parts, rather than a unique explanation of Transformer performance:
- Token-level information exchange, which mixes spatial positions and can be local or global.
- Feature-level information exchange, which corresponds to channel-level information exchange in images.
In the original MobileNet structure, these two aspects are coupled together:
- First, convolutions handle "channel" information exchange.
- Next, depthwise convolutions handle "local spatial" information exchange.
- Followed by a layer, which handles both "global and channel" information exchange.
- Finally, another convolution handles "channel" information exchange.
The authors separate these aspects in the new structure:
- Start with "local spatial" information exchange using a depthwise convolution. During training it has an additional depthwise branch and a shortcut; for inference these are fused into one convolution.
- Then apply the layer for "global and channel" information exchange.
- Conclude with two convolutions forming the channel mixer.
Together, these changes reduce measured latency from 1.01 ms to 0.81 ms, about 20%. The reciprocal throughput increase would be about 25%.
The speed increases, but this step lowers ImageNet Top-1 accuracy from 71.5% to 68.3%.
Next, measures are taken to recover the lost accuracy.
Reducing Expansion Ratio and Increasing Width
In typical ViTs, the expansion ratio in the channel mixer is often set to 4, making the hidden dimensions in the feed-forward network (FFN) four times the input dimensions; MobileNetV3-L varies from about 2.3 to 6, with 6 common in its last two stages. Wider channel mixers increase inference time.
Previous research has shown that the FFN contains a lot of redundant information, and a lower expansion ratio is often sufficient.
- [21.04] LeViT: a Vision Transformer in ConvNet's Clothing for Faster Inference
- [21.04] All Tokens Matter: Token Labeling for Training Better Vision Transformers
- [22.12] SAViT: Structure-Aware Vision Transformer Pruning via Collaborative Optimization
- [23.10] NViT: Vision Transformer Compression and Parameter Redistribution
The authors decide to use an expansion ratio of 2 while widening the stages to 48, 96, 192 and 384 channels to restore expressiveness.
This adjustment recovers accuracy and surpasses the original MobileNet-V3, achieving 73.5% at 0.89 ms latency.
Adjusting the Stem Structure
ViTs typically use a patchify operation as the backbone, dividing the input image into non-overlapping patches, with simple stem structures often using a large convolution. In hierarchical ViTs, a convolution is used.
In contrast, MobileNet-V3 has a complex stem structure with convolutions, depthwise separable convolutions, and inverted residual bottlenecks, as shown in (a).
Since the stem structure processes input images at the highest resolution, its complexity can create significant speed bottlenecks on mobile devices. As a trade-off, MobileNet-V3's stem structure uses a small number of filters (only 16 channels), limiting its expressiveness.
To address this, the authors use early convolutions with two convolutions and a stride of 2 to reduce computation while increasing the number of filters to enhance expressiveness, as shown in (b).
Adjusting the Downsampling Structure
MobileNet-V3 downsamples with a stride-2 depthwise convolution inside an inverted bottleneck. While this design is efficient, it may lack sufficient network depth, leading to information loss and negatively impacting performance, as shown in (c).
To address this, the authors use a more complex downsampling structure, as shown in (d). This structure includes a stride-2 depthwise convolution for spatial downsampling and a 1×1 convolution for adjusting channels, a RepViT module at the front, and an FFN module after convolutions to retain more information.
Simple Classifier
In lightweight ViTs, the classifier typically consists of global average pooling and a linear layer, which is very fast on mobile devices.
In contrast, MobileNet-V3's classifier includes a convolution and an additional linear layer to expand features into a higher-dimensional space, as shown in (e). While this design is crucial for MobileNet-V3, it increases inference time on mobile devices.
The authors abandon MobileNet-V3’s design and opt for a simple global average pooling and linear layer combination for the final architecture.
This design brings inference time back to 0.77 ms, but accuracy drops again!
Adjusting Stage Ratios
Several architectures allocate more blocks to the third stage, but no single ratio is universal. EfficientFormer-L2, for example, uses 1:1:3:1.5.
Recent studies suggest that more aggressive ratios might benefit smaller models. For example, Conv2Former-T and Conv2Former-S use ratios of 1:1:4:1 and 1:1:8:1, respectively.
The authors adopt a 1:1:7:1 ratio with deeper stages of 2:2:14:2, achieving a deeper network layout.
This adjustment finally recovers the lost accuracy, reaching 76.9% at 0.91 ms latency.
Kernel Size Selection
In previous research, larger kernel convolutions (e.g., or ) in small networks have been effective in improving model expressiveness.
In the tested mobile/compiler environment, larger kernels have higher computation and memory costs and less optimization than 3×3 kernels. This is not a universal limitation of mobile hardware.
To ensure inference efficiency on mobile devices, the authors prioritize convolutions across all modules.
This keeps accuracy at 76.9% while reducing inference time from 0.91 to 0.89 ms.
Squeeze-and-Excitation (SE) Layer Decision
The SE module has been widely used in various network architectures to enhance model expressiveness.
- However, SE modules are quite slow!
To balance the benefits of SE modules with speed, the authors use them sparingly:
- Applying SE modules selectively in the 1st, 3rd, 5th... blocks of each stage.
Discussion
Performance on ImageNet-1K
Experiments were conducted using standard 224×224 pixel images for training and testing, evaluating the performance of various models with different training epochs (300 or 450 epochs).
Key results include:
-
Model Performance Comparison:
- Among the 300-epoch models near 0.9 ms in the table, RepViT-M0.9 reaches 78.7% Top-1 accuracy, 3.0 and 2.0 percentage points above EfficientFormerV2-S0 at 75.7% and FastViT-T8 at 76.7%, respectively. RepViT-M1.1 reaches 80.7% at 1.1 ms after 300 epochs, 1.7 points above EfficientFormerV2-S1 at 79.0%.
-
Latency and Accuracy:
- RepViT-M1.0 has 1.0 ms latency on the tested iPhone 12. Its Top-1 accuracy is 80.0% after 300 epochs and 80.3% after 450 epochs; only the latter exceeds 80%.
- The largest model, RepViT-M2.3, reaches 83.3% / 83.7% Top-1 accuracy after 300 / 450 epochs at 2.3 ms latency.
-
Impact of Knowledge Distillation:
Even without knowledge distillation (in the table below), RepViT has higher accuracy in several comparisons at nearby latencies. For example, RepViT-M1.0 reaches 78.6% at 1.0 ms, 2.7 percentage points above MobileOne-S1 at 0.9 ms. For larger models, RepViT-M2.3 is 1.1 points above PoolFormer-S36, while latency falls from 3.5 to 2.3 ms, a reduction of about 34.3%.
Ablation Study - Reparameterized Structure
To validate the effectiveness of the reparameterized structure in RepViT, the authors conducted ablation studies by removing the multi-branch topology during training on ImageNet-1K.
Removing the training-time structural reparameterization (SR) branches lowers Top-1 accuracy by 0.27, 0.20 and 0.20 percentage points for M0.9, M1.5 and M2.3, respectively. This table compares training topologies, not the latency of branches left in the deployed model.
Ablation Study - Impact of SE Layers
To verify the advantage of using SE layers in a cross-block manner, the authors compared scenarios with all SE layers removed and where SE layers are used in each block.
For M0.9, alternating SE gives 78.74% accuracy at 0.87 ms, nearly matching SE in every block at 78.75% while improving on its 0.92 ms latency. For M1.5, both placements reach 82.29%, while latency falls from 1.58 to 1.52 ms with alternating SE. Removing SE altogether is faster again, but accuracy is lower.
Conclusion
The authors describe RepViT-M1.0 as an early lightweight model reaching 80% ImageNet-1K accuracy at about 1.0 ms on iPhone 12. This is a historical result under the paper’s conditions; application preprocessing and postprocessing require separate measurements.
The authors have explored efficient designs for lightweight CNNs, combining innovative lightweight ViT structures to introduce the RepViT series.
This lightweight CNN model, designed for resource-constrained mobile devices, demonstrates superior performance in various vision tasks. RepViT not only outperforms current state-of-the-art lightweight ViTs and CNNs in accuracy but also excels in latency.
The authors hope RepViT will become a solid baseline for lightweight model design and inspire further research and innovation in this field.