Mobile-Former: Bridging MobileNet and Transformer
- Publication
- CVPR 2022Conference
- First submitted to arXiv
- arXiv:2108.05895
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{lightweightmobileformer2021,
title = {{Mobile-Former: Bridging MobileNet and Transformer}},
author = {Yinpeng Chen and Xiyang Dai and Dongdong Chen and Mengchen Liu and Xiaoyi Dong and Lu Yuan and Zicheng Liu},
year = {2021},
eprint = {2108.05895},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2108.05895}
}
Researchers have tried all kinds of approaches to make ViT work on mobile devices.
Problem Definition
It can run, but it is slow.
ViT is difficult to make efficient on a phone. So the authors thought:
- Why not add just a little Transformer to MobileNet?
Solution
How Do the Two Paths Communicate?
The authors place MobileNet and Transformer in parallel and connect them with a two-way bridge. The Mobile path processes local image features; the Former path starts with a few learnable tokens, rather than image patches.
The next figure shows the steps in one block:
- Blue, Mobile: The image enters MobileNet's feature extractor and becomes a local feature map .
- Yellow, Mobile→Former: A small set of learnable tokens enters the Transformer path. The tokens are queries, and the local feature map supplies keys and values, so cross-attention brings image information into the tokens.
- Green, Former: The tokens then pass through self-attention and the FFN.
- Red, Mobile←Former: The local feature map acts as queries; the updated tokens supply keys and values, sending global information back to the local path.
- The resulting local features and tokens enter the next block.
To keep cross-attention cheap, the bridge omits linear projections on the Mobile side: no key or value projections for the local features in Mobile→Former, and no query projection for them in Mobile←Former. Projections on the Former side remain.
Other details include an FFN expansion ratio of 2 instead of 4, Post-LN, and Dynamic ReLU parameters generated from the updated first global token rather than from pooled Mobile features. I will not dwell on those here.
Reading the Layer Table
The table below gives the Mobile-Former-294M architecture. Based on MobileNetV3, it keeps a lightweight bottleneck block at stage 1 and uses Mobile-Former blocks at stages 2–5. This particular model starts with six global tokens of dimension 192; the other model sizes have their own specifications.
Discussion
ImageNet: Check the Comparison Conditions
The authors test image classification on ImageNet, which has 1,000 classes, 1,281,167 training images, and 50,000 validation images. Their Mobile-Former models use 224×224 inputs and train from scratch with AdamW for 450 epochs, cosine learning-rate decay, batch size 1024, Mixup, AutoAugment, and Random Erasing. Initial learning rate, weight decay, and dropout vary with model size.
The table compares Mobile-Former with MobileNetV3, EfficientNet, ShuffleNetV2, and WeightNet from 26M to 508M multiply-adds. Mobile-Former is more accurate with fewer operations in most groups. Around 150M, it instead uses slightly more operations than ShuffleNetV2 and WeightNet, 151M versus 138M/141M, but is more accurate, 75.2% versus 69.1%/72.4%. These are reported model results; the comparison rows do not all use the same input resolution or training recipe.
Next, the authors compare Mobile-Former with DeiT, T2T-ViT, PVT, ConViT, CoaT, ViTC, and Swin. These Table 3 variants use 224×224 inputs without teacher distillation. Mobile-Former-294M reaches 77.9% Top-1 and Mobile-Former-508M reaches 79.3%, each with fewer multiply-adds than the stronger ViT entries in its comparison group. The Swin and DeiT rows marked ‡ are smaller variants implemented by this paper's authors.
The authors also compare Mobile-Former with LeViT outside the table: 77.9% versus 76.6% at 294M versus 305M operations. Mobile-Former trained for 450 epochs without distillation; LeViT used a teacher and 1,000 epochs.
Here the authors add more CNNs, such as GhostNet, and reduced Swin and DeiT variants to the accuracy-versus-compute plot. At the reported low operation counts, Mobile-Former comes out ahead. That shows how a little Transformer can help a MobileNet-style network, but the horizontal axis is multiply-adds, not phone latency.
Ablating the Bridge, Activation, and Token Count
Which parts of Mobile-Former help most?
The authors train the 294M design for 300 epochs for this ablation, rather than the 450 epochs used for the main comparison. Adding Former and the two-way bridge to Mobile raises Top-1 from 74.2% to 76.8% while operations rise from 259M to 290M, about 12% more compute for 2.6 percentage points of accuracy. Adding Dynamic ReLU to Mobile raises Top-1 by another 1.0 point, to 77.8%. Its parameters come from the first global token, supporting the value of the two paths working together in this experiment.
The table shows how many global tokens the Former path needs. Each has 192 dimensions. Even one token reaches 77.1% Top-1; three and six tokens improve that by 0.5 and 0.7 percentage points, respectively. Nine tokens dip slightly to 77.7%. Keeping the global token set small is part of this model's efficiency.
Conclusion
By running MobileNet and a small Transformer path in parallel, Mobile-Former makes an efficient vision model in these ImageNet comparisons.
But the authors also point out a speed trade-off. Their appendix measures Mobile-Former-214M and MobileNetV3 Large on a single-threaded Intel Xeon E5-2650 v3 with batch size 1: Mobile-Former is slower at 224×224 and becomes faster only when the image exceeds roughly 750×750. This is a CPU result, not a phone measurement. What happens on a mobile device is worth testing in future work.