{"notes":[{"id":"lightweight/mobile-former","category":"lightweight","legacyPath":"lightweight/2108-mobile-former","legacySlug":"2108-mobile-former","legacyPaths":[],"title":"Mobile-Former","subtitle":"双向连通桥","author":"Z. Yuan","paperDate":"2021-08-12","publishedOn":"2024-09-03","paperTitle":"Mobile-Former: Bridging MobileNet and Transformer","paperUrl":"https://arxiv.org/abs/2108.05895","bibliography":{"title":"Mobile-Former: Bridging MobileNet and Transformer","authors":["Yinpeng Chen","Xiyang Dai","Dongdong Chen","Mengchen Liu","Xiaoyi Dong","Lu Yuan","Zicheng Liu"],"url":"https://arxiv.org/abs/2108.05895","pdfUrl":"https://arxiv.org/pdf/2108.05895","codeUrl":null,"preprint":{"id":"2108.05895","submittedOn":"2021-08-12","url":"https://arxiv.org/abs/2108.05895"},"publication":{"venue":"CVPR","year":2022,"kind":"conference","url":"https://arxiv.org/abs/2108.05895"},"citation":"@misc{lightweightmobileformer2021,\n  title = {{Mobile-Former: Bridging MobileNet and Transformer}},\n  author = {Yinpeng Chen and Xiyang Dai and Dongdong Chen and Mengchen Liu and Xiaoyi Dong and Lu Yuan and Zicheng Liu},\n  year = {2021},\n  eprint = {2108.05895},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2108.05895}\n}\n","citationPath":"/content/papers/citations/lightweight/mobile-former.e0fa77029109.bib"},"thumbnail":{"src":"/content/papers/assets/0e6780b6892b71f46efb8e71a58ef01488f230f81775b453e08e9471354e9a3e.jpg","width":1224,"height":1068},"locale":"zh-hans","path":"/content/papers/zh-hans/lightweight/mobile-former.7a43a6804151.md","headings":[{"id":"定义问题","text":"定义问题","depth":2},{"id":"解决问题","text":"解决问题","depth":2},{"id":"模型架构","text":"模型架构","depth":3},{"id":"架构参数","text":"架构参数","depth":3},{"id":"讨论","text":"讨论","depth":2},{"id":"imagenet-上的性能","text":"ImageNet 上的性能","depth":3},{"id":"消融实验","text":"消融实验","depth":3},{"id":"结论","text":"结论","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"lightweight/mobilevit","relation":"comparison","topic":"结合轻量卷积与注意力"},{"id":"reparameterization/fastvit","relation":"comparison","topic":"结合轻量卷积与注意力"}]},{"id":"lightweight/mobilevit","category":"lightweight","legacyPath":"lightweight/2110-mobilevit","legacySlug":"2110-mobilevit","legacyPaths":[],"title":"MobileViT","subtitle":"变更设计卷积核","author":"Z. Yuan","paperDate":"2021-10-05","publishedOn":"2024-09-04","paperTitle":"MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer","paperUrl":"https://arxiv.org/abs/2110.02178","bibliography":{"title":"MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer","authors":["Sachin Mehta","Mohammad Rastegari"],"url":"https://arxiv.org/abs/2110.02178","pdfUrl":"https://arxiv.org/pdf/2110.02178","codeUrl":null,"preprint":{"id":"2110.02178","submittedOn":"2021-10-05","url":"https://arxiv.org/abs/2110.02178"},"publication":{"venue":"ICLR","year":2022,"kind":"conference","url":"https://arxiv.org/abs/2110.02178"},"citation":"@misc{lightweightmobilevit2021,\n  title = {{MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer}},\n  author = {Sachin Mehta and Mohammad Rastegari},\n  year = {2021},\n  eprint = {2110.02178},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2110.02178}\n}\n","citationPath":"/content/papers/citations/lightweight/mobilevit.f81f40aca27f.bib"},"thumbnail":{"src":"/content/papers/assets/4b04c873571d684cc92c774de290e347e8cd46c3dda6d9e3faa2028258cbbb20.jpg","width":1686,"height":400},"locale":"zh-hans","path":"/content/papers/zh-hans/lightweight/mobilevit.43223e24b00f.md","headings":[{"id":"定义问题","text":"定义问题","depth":2},{"id":"解决问题","text":"解决问题","depth":2},{"id":"卷积回顾","text":"卷积回顾","depth":3},{"id":"模型架构","text":"模型架构","depth":3},{"id":"实验配置","text":"实验配置","depth":3},{"id":"讨论","text":"讨论","depth":2},{"id":"在-imagenet-上的性能","text":"在 ImageNet 上的性能","depth":3},{"id":"结论","text":"结论","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"lightweight/mobile-former","relation":"comparison","topic":"结合轻量卷积与注意力"},{"id":"reparameterization/fastvit","relation":"comparison","topic":"结合轻量卷积与注意力"}]},{"id":"reparameterization/fastvit","category":"reparameterization","legacyPath":"reparameterization/2303-fastvit","legacySlug":"2303-fastvit","legacyPaths":[],"title":"FastViT","subtitle":"重参数化的 ViT 试验","author":"Z. Yuan","paperDate":"2023-03-24","publishedOn":"2024-07-16","paperTitle":"FastViT: A Fast Hybrid Vision Transformer using Structural Reparameterization","paperUrl":"https://arxiv.org/abs/2303.14189","bibliography":{"title":"FastViT: A Fast Hybrid Vision Transformer using Structural Reparameterization","authors":["Pavan Kumar Anasosalu Vasu","James Gabriel","Jeff Zhu","Oncel Tuzel","Anurag Ranjan"],"url":"https://arxiv.org/abs/2303.14189","pdfUrl":"https://arxiv.org/pdf/2303.14189","codeUrl":null,"preprint":{"id":"2303.14189","submittedOn":"2023-03-24","url":"https://arxiv.org/abs/2303.14189"},"publication":{"venue":"ICCV","year":2023,"kind":"conference","url":"https://arxiv.org/abs/2303.14189"},"citation":"@misc{reparameterizationfastvit2023,\n  title = {{FastViT: A Fast Hybrid Vision Transformer using Structural Reparameterization}},\n  author = {Pavan Kumar Anasosalu Vasu and James Gabriel and Jeff Zhu and Oncel Tuzel and Anurag Ranjan},\n  year = {2023},\n  eprint = {2303.14189},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2303.14189}\n}\n","citationPath":"/content/papers/citations/reparameterization/fastvit.0b2741f99b2b.bib"},"thumbnail":{"src":"/content/papers/assets/095c905b22b0b0e80a3fdb19b68680885648cdd70aa6ff754434e08a3a1aa78a.jpg","width":1618,"height":1038},"locale":"zh-hans","path":"/content/papers/zh-hans/reparameterization/fastvit.e629440daeee.md","headings":[{"id":"定义问题","text":"定义问题","depth":2},{"id":"解决问题","text":"解决问题","depth":2},{"id":"模型架构","text":"模型架构","depth":3},{"id":"模型配置","text":"模型配置","depth":3},{"id":"训练与评估策略","text":"训练与评估策略","depth":3},{"id":"讨论","text":"讨论","depth":2},{"id":"imagenet-上的性能","text":"ImageNet 上的性能","depth":3},{"id":"结论","text":"结论","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"lightweight/mobilevit","relation":"comparison","topic":"结合轻量卷积与注意力"},{"id":"lightweight/mobile-former","relation":"comparison","topic":"结合轻量卷积与注意力"},{"id":"reparameterization/repvit","relation":"comparison","topic":"面向部署的快速视觉骨干"}]}],"text":"为了让 ViT 可以在移动设备上动起来，研究者们可真是想尽了各种办法。\n\n## 定义问题\n\n也不是不能跑，但就是慢。\n\nViT 的架构在手机上的支持度不高，很难享受到硬件加速的好处。\n\n本篇论文的作者想着：\n\n- **要不我们就在 MobileNet 的基础上加上「一点点」的 Transformer 的架构吧！**\n\n## 解决问题\n\n### 模型架构\n\n![mobile-former arch](/content/papers/assets/0e6780b6892b71f46efb8e71a58ef01488f230f81775b453e08e9471354e9a3e.jpg)\n\n作者提出了一个双向连通桥架构，将 MobileNet 和 Transformer 用并联的方式连接在一起。\n\n详细流程如下图，我们按照步骤来说明：\n\n![mobile-former detail](/content/papers/assets/007e27c30321588ce8b8e88d6ec27f77cdf56583fbd306f49bbba7959ab3ad72.jpg)\n\n1. **蓝色区块**：输入图片经过 MobileNet 的特征提取层，得到特征图。\n2. **黄色区块**：Transformer 分支以可学习的 token 为输入，通过跨注意力读取蓝色区块的影像特征。\n   - 在这个步骤中，作者会预先准备一组可学习的 token，数量小于等于 6 个。\n   - 将这些 token 视为查询的输入，并将特征图视为键值对。\n3. **绿色区块**：经过 Cross-Att 之后，接着计算 Self-Att。\n4. **红色区块**：以第一步骤的特征图作为查询，第三步骤的 token 作为键和值，通过跨注意力将全局信息送回特征图。\n5. 最后，第四步骤的输出会成为下一个 MobileNet block 的输入；同时，第三步骤的输出会成为下一个 Transformer block 的输入。\n\n在双向桥接的跨注意力中，作者省略 Mobile 端的线性投影，以减少计算量：Mobile→Former 不投影特征图的键和值；Mobile←Former 不投影特征图的查询。Former 端的投影仍然保留。\n\n其他细部设计像是 FFN 使用 2 作为膨胀比（原本为 4）；将 Dynamic ReLU 的输入改成绿色区块的输出（原本是通过平均池化和 MLP 计算）；使用 Post-LN 的方式来进行归一化等，这边我们就不再赘述。\n\n\n> [!TIP]\n> \n> 这篇要注意的是：绿色区块的输出除了传到红色区块之外，还会传到蓝色区块，作为 Dynamic ReLU 的输入。\n> \n> 我们认为这个操作有很大的讨论空间，可能影响模型速度；但论文没有单独量测这一步的延迟。\n\n\n### 架构参数\n\n如下表，基于原本的 MobileNet-V3 架构，作者在第 2～5 阶段使用 Mobile-Former block，第 1 阶段仍是轻量瓶颈区块。\n\n![mobile-former params](/content/papers/assets/b26c517c7b863acb8a1b5cbac7fceff57fcc6872aa86a77484732b4931ad7fbd.jpg)\n\n## 讨论\n\n### ImageNet 上的性能\n\n![imagenet 1](/content/papers/assets/9ea234d5eb38ce79fd06a273a3d4ad55b030ea35c9dd8bc9df12060182c6d49a.jpg)\n\n作者在 ImageNet 数据集上进行影像分类实验。ImageNet 数据集包含 1000 个类别，共有 1,281,167 张训练影像与 50,000 张验证影像。\n\nMobile-Former 分类模型的训练影像分辨率设为 224×224。模型从头开始训练，使用 AdamW 优化器，训练 450 个 epoch，并采用余弦学习率衰减。批量大小为 1024。数据增强技术包含 Mixup、自动增强（AutoAugment）、以及随机擦除（Random Erasing）。针对不同复杂度的模型，使用了不同组合的初始学习率、权重衰减和 dropout。\n\n上表显示了 Mobile-Former 与经典高效 CNN 的比较，这些 CNN 包括：MobileNetV3、EfficientNet、ShuffleNetV2 及其延伸版本 WeightNet。比较范围涵盖 26M 到 508M FLOP，并分为七组进行比较。\n\nMobile-Former 在大多数组别中，以更低的计算成本（FLOP）超越了高效 CNN，仅在约 150M FLOP 的组别中，Mobile-Former 的 FLOP 略高于 ShuffleNet/WeightNet，但其 Top-1 准确率显著更高（75.2% vs. 69.1%/72.4%）。\n\n---\n\n![imagenet 2](/content/papers/assets/4953376ee1dab160ffeaadbcb75abd7a9aa3b0534b9644e24c77840f1ed6d57f.jpg)\n\n接着作者将 Mobile-Former 与其他视觉 Transformer 模型进行比较，如上表，包括：DeiT、T2T-ViT、PVT、ConViT、CoaT、ViTC、Swin。\n\n表中变体均使用 224×224 的影像分辨率，且未使用教师网络进行蒸馏训练。Mobile-Former-294M 达到 77.9%，Mobile-Former-508M 达到 79.3%；在各自的比较组别中，两者都以较少的计算量取得较高准确率。作者将此归因于较少的 token 建模全局交互，以及 MobileNet 提取局部特征。\n\nMobile-Former（训练 450 个 epoch 且未进行蒸馏）甚至优于使用教师网络蒸馏且训练 1000 个 epoch 的 LeViT（准确率 77.9% vs. 76.6%，FLOP 为 294M vs. 305M）。\n\n---\n\n![imagenet 3](/content/papers/assets/0672466b4863f5772c96695b0ecec5fd4bf0997386a7a3231d24c6f1f0f820f5.jpg)\n\n如上图，作者将 Mobile-Former 与更多的 CNN 模型（如 GhostNet）及视觉 Transformer 变体（如 Swin 和 DeiT）进行比较。\n\nSwin 与 DeiT 的 FLOP 范围从 100M 到 2G，通过仔细减小网络的宽度与高度实现。Mobile-Former 明显超越了这些 CNN 和 ViT 变体，展示了将 MobileNet 与 Transformer 结合的平行设计的优势。尽管视觉 Transformer 在低 FLOP 范围内明显不如高效 CNN，但本研究证明通过适当的架构设计，Transformer 也能在低 FLOP 范围内发挥作用。\n\n### 消融实验\n\n![ablation](/content/papers/assets/29ea9daadc813d48545a178a2eb94080dac3d1ccc1f42577063e08ef765d1a71.jpg)\n\n那么，Mobile-Former 的哪些部分对性能影响最大呢？\n\n作者使用训练 300 个 epoch 的 Mobile-Former-294M 进行消融实验，观察不同部分对性能的影响。\n\n如上表实验结果显示：MobileNet 加入 Former 和桥接（Mobile→Former 与 Mobile←Former）增加了约 12% 的计算成本，Top-1 准确率比仅使用 Mobile 的基线提高了 2.6 个百分点。\n\n此外，在 Mobile 子模块中使用 Dynamic ReLU 使 Top-1 准确率再提高 1.0 个百分点。动态 ReLU 中的参数由第一个全局 token 生成，这支持了 Mobile-Former 平行设计在这组消融中的效果。\n\n---\n\n![ablation 2](/content/papers/assets/592e18e2a6ce1a885afd0f8d6706d19441897690ab46e7c5ee1e6ca335de04e5.jpg)\n\n上表展示了使用不同数量的全局 token 在 Former 中的 ImageNet 分类结果。这些 token 的维度为 192。\n\n有趣的是，即便只使用一个全局 token 也能达到良好的表现（77.1% 的 Top-1 准确率）。相较于一个 token，使用 3 个和 6 个 token 时，准确率分别提高了 0.5 和 0.7 个百分点；增加到 9 个 token 则略降至 77.7%。这种全局 token 的紧凑性是 Mobile-Former 高效性的关键因素。\n\n## 结论\n\nMobile-Former 通过将 MobileNet 和 Transformer 进行平行设计，实现了高效的视觉模型。\n\n但作者也表示：在论文附录的延迟测试中，Mobile-Former 处理较大影像时比 MobileNetV3 快，但在较小影像上反而较慢。这组延迟比较是在单线程、batch size 1 的 Intel Xeon CPU 上测得。这个部分值得未来研究者进一步探讨。\n\n\n> [!TIP]\n> \n> 这篇论文中所提到的 MobileNet-V3 的数据比较旧，都是没有经过现代化的训练计划所优化的结果。读者可以在 MobileNet-V4 的论文中看一下最新的信息。\n> \n> - [**[24.04] MobileNet-V4: 时隔五年的传承**](/blog/papers/lightweight/mobilenet-v4)\n> \n> 或许在这个新的基础上，Mobile-Former 会有不一样的表现。\n","imageSizes":{"/content/papers/assets/0e6780b6892b71f46efb8e71a58ef01488f230f81775b453e08e9471354e9a3e.jpg":{"width":1224,"height":1068},"/content/papers/assets/007e27c30321588ce8b8e88d6ec27f77cdf56583fbd306f49bbba7959ab3ad72.jpg":{"width":940,"height":1080},"/content/papers/assets/b26c517c7b863acb8a1b5cbac7fceff57fcc6872aa86a77484732b4931ad7fbd.jpg":{"width":1160,"height":976},"/content/papers/assets/9ea234d5eb38ce79fd06a273a3d4ad55b030ea35c9dd8bc9df12060182c6d49a.jpg":{"width":1160,"height":1012},"/content/papers/assets/4953376ee1dab160ffeaadbcb75abd7a9aa3b0534b9644e24c77840f1ed6d57f.jpg":{"width":1152,"height":872},"/content/papers/assets/0672466b4863f5772c96695b0ecec5fd4bf0997386a7a3231d24c6f1f0f820f5.jpg":{"width":1224,"height":760},"/content/papers/assets/29ea9daadc813d48545a178a2eb94080dac3d1ccc1f42577063e08ef765d1a71.jpg":{"width":1160,"height":244},"/content/papers/assets/592e18e2a6ce1a885afd0f8d6706d19441897690ab46e7c5ee1e6ca335de04e5.jpg":{"width":1306,"height":336}}}
