Advertisement

MobileViT: Lightweight general purpose and mobile friendly vision transformer (移动端-ViT:一种轻量级的通用移动端V

阅读量:

1. 摘要

轻量级卷积网络在移动端计算中得到了广泛应用。这些模型通过空间归纳偏差能够在不同视觉任务中以较少的参数学习表征。然而,这些表征在空间维度上具有一定的局限性。为了捕获全局表征,视觉transformer架构中的自注意力机制被引入。如何结合卷积神经网络和视觉transformer的优势,构建一个低延迟、轻量级的网络以有效检测视觉任务?在此基础上,本文提出了一种名为Mobile Vit的轻量级视觉模型。本文旨在探讨如何结合卷积神经网络和视觉transformer的优势,构建一个适用于移动视觉任务的轻量级、低延迟网络。为此目的,我们引入了MobileViT,一种通用的轻量级视觉transformer架构,适用于移动设备。

2. 需求

Self-attention-based models, particularly vision transformers (ViTs; Figure 1a; Dosovitskiy et al., 2021), present an alternative to convolutional neural networks (CNNs) for learning visual representations. In essence, ViTs segment an image into a sequence of non-overlapping patches and utilize multi-headed self-attention mechanisms in transformers (Vaswani et al., 2017) to capture interpatch relationships. A notable trend is the increase in the number of parameters within ViT architectures to enhance performance (e.g., Touvron et al., 2021a; Graham et al., 2021; Wu et al., 2021). However, this performance improvement is accompanied by a trade-off in model size and latency. Many real-world applications, such as augmented reality and autonomous wheelchairs, require efficient processing of visual recognition tasks on resource-constrained mobile devices. For effective deployment in these environments, ViT models must be lightweight and fast. Despite efforts to reduce model size to meet mobile device constraints, their performance often falls short compared to lightweight CNNs. For instance, under a parameter budget of approximately 5-6 million, DeIT (Touvron et al., 2021a) achieves only 3% less accuracy than MobileNetv3 (Howard et al., 2019). Consequently, the development of lightweight ViT models remains crucial.

3. 模型结构

卷积操作通常分为三个步骤:展开局部区域、逐点处理和折叠。他们采用了较为直接的替代方法。需要注意的是,unfold函数是一种图像分块的技术,用于提取卷积核滑动过程中经过的像素信息,而不进行额外的计算。在PyTorch框架中,卷积操作通过Conv接口实现,该接口将所有细节封装,用户只需关注输入输出的处理逻辑。

在这里插入图片描述

We also notice notable performance improvements when MobileViT is employed as a feature backbone in highly optimized mobile vision systems tailored for specific tasks. Replacing MNASNet (Tan et al., 2019) with MobileViT in SSDLite (Sandler et al., 2018) leads to enhanced performance (1.8% increase in mAP) and reduced size (1.8x reduction), as demonstrated in Figure 2.

复制代码
     基于SA的Transformer已经成为CNN的一种替代方案,ViT通过将输入图像切分一系列互不重叠的Patch然后使用多头注意力特征表述,也有一系列工作来进一步提升ViT的性能,但都是以模型大小、网络参数和延迟为代价。但是现实世界许多场景都是需要在资源有限的平台上进行视觉识别任务,这就要求设计的ViT模型更加轻量级低延迟。比如当参数量5-6M时DeiT比MobileNetv3的性能低3%,因此轻量级ViT的模型设计志在必得。

    
    
      
    
    AI助手

为了提升轻量级CNN的适用性,尽管基于Transformer的ViT模型在轻量级方面仍有较大提升空间。ViT本质上属于"重量级"模型,其优化难度较高,通常需要依赖数据增强技术。对于密集预测任务,还需搭配昂贵的解码器。例如,在分割任务中,ViT的参数规模达到345 million,相比之下,同样功能的轻量级CNN(如DeepLab v3)仅需59 million参数。为构建更加鲁棒的模型,部分研究尝试将卷积神经网络与Transformer架构相结合,但这种混合模型依然具有较高的"重量级"特性,并对数据增强操作极为敏感。若放弃使用CutMix技术,可能会导致模型性能显著下降。

探索卷积网络与Transformer的有效结合仍然具有重要的研究价值,特别是在轻量化设计方面。为此,我们需要设计出一个更加轻量级、低延迟且在满足一定硬件资源限制下保持较高准确率的模型,并且这种设计最好是通用的,这样才能适应不同的应用场景。

值得注意的是,FLOPs(浮点运算次数)指标虽然重要,但并不完全等同于设备的低延迟。因为FLOPs计算忽略了内存访问次数、并行度以及硬件平台的特性等因素。例如,Heo等人提出的方法基于Vision Transformer(ViT)的FLOPs比基于DeiT的方法少3倍,但实际在硬件部署时两者的性能差异不大。因此,本文并未将FLOPs作为优化目标,而是重点设计了一个既轻量化又通用且具有低延迟特性的网络结构。

本文最终提出的设计方案叫做MobileViT,它成功地融合了卷积神经网络(CNN)的空间聚合能力与数据增强敏感性,同时也继承了Vision Transformer(VIT)的全局依赖特性以及输入自适应的优势。特别值得一提的是,所提出的MobileViT模块能够有效地整合张量的局部特征与全局信息,具体可见图1(b)的展示。

与其他ViT变体不同,MobileViT通过提供学习全局表示的不同视角来实现独特性。传统卷积操作主要包括三个步骤:展开(unfold)、局部处理(local processing)和折叠(fold)。MobileViT创新性地将局部处理替换为Transformer的全局计算机制,从而实现了在保持卷积和Transformer优势的同时,显著减少了模型参数量。据研究显示,这是首个证明轻量级ViT能够与轻量级CNN性能相当的案例,且无需复杂训练过程。在ImageNet-1K数据集上,当参数量控制在5至6百万时,轻量级的MobileViT达到了78.4%的识别精度,较MobileNet提升了3.2%。此外,将其作为特征提取器应用于其他移动视觉任务时,也展现出显著性能提升效果,例如与MNASNet相比,MobileViT可带来1.8%的mAP提升,同时网络复杂度降低1.8倍。

4. 相关工作

Light-weight convolutional neural networks (CNNs) are fundamental components in modern convolutional neural networks. To mitigate the computational overhead of convolution layers, various studies have explored methods to decompose the convolution operation, such as MobileNet, ShuffleNet, ESPNet, MixNet, MNASNet, and others. These lightweight networks not only offer improved training efficiency but also provide flexibility by allowing the replacement of heavy-weight backbones. However, a common limitation of these methods is their spatial locality. This paper aims to leverage the complementary strengths of convolutional neural networks and Transformer architectures to develop a lightweight and versatile network framework.

Transformer的优势在于可以捕捉全局联系,但是却难以训练,主要就是因为ViT缺乏空间上的归纳偏执信息,因此需要借助在大规模数据集上预训练的结果。
也有的工作尝试借助卷积来弥补归纳偏执信息,比如使用深度可分离卷积替换原来的linear操作,BoTNet则是将ResNet中3x3的卷积替换为了MHSA操作。虽然这些改进都一定程度上提升了性能,但是一般都是“重量级”的网络。比如PiT,CvT分别是EfficientNet的参数量的6.1x和1.7x;如果把参数量降下来那这些模型性能就比轻量级CNN差了,比如同等参量的PiT精度会比MobileNet下降2.2%.
Discussion
一个悬而未决的问题是:如何有效的结合卷积和Transformer来搭建轻量级的网络模型。为此本文将ViT与CNN结合搭建了MobileViT,有以下优势:
(1)更好的性能。 在相同的参数下本文的MobileViT获得了最佳的性能;
(2)更好的泛化性能。 泛化能力指的是在测试集和验证集上的差距,与ViT相比MobileViT在没见过的数据集上有更好的性能
(3)鲁棒性。
一个好的模型应该对超参数具有足够的鲁棒性,因为人工调参非常耗时也耗费资源,与ViT相比,MobileViT只需要在简单的数据增强就能训练,并且对L2正则化不敏感。

5. 特点

5.1 编码特性

在这里插入图片描述

在图中,灰色块和黑色block分别代表单个像素和一个被划分得到的patch。在当前的feature map中,蓝色的像素块能够提取邻域范围内的像素信息。因此,红色像素块通过Transformer机制能够捕获图像中多个patch的全局信息。

5.2 为什么Mobile-ViT是轻量级模型?

We think that the main issues lie in learning global representations through transformers. For a given patch, previous research (e.g., Touvron et al., 2021a; Graham et al., 2021) convert the spatial information into latent features by learning a linear combination of pixels (as shown in Figure 1a). These models then encode global information by learning inter-patch relationships using transformers. However, this leads to a loss of image-specific inductive bias, which is inherent in CNNs. As a result, these models require more capacity to learn visual representations, making them deep and wide in structure. Unlike these models, MobileViT employs a unique approach where the resultant block maintains convolution-like properties while simultaneously enabling global processing.

基于其独特的结构设计,该模型不仅具备了基于transformer学习全局特征的能力,还成功继承了CNN模型的spatial inductive biases。然而,先前的一些研究因未能保持CNN模型的这一内在特征,导致在表示视觉信息时需要更大的计算能力与空间维度。相比之下,ViT通过巧妙的设计实现了对这两种模型优势的完美融合。

全部评论 (0)

还没有任何评论哟~