当前位置:网站首页>当CNN遇见Transformer《CMT:Convolutional Neural Networks Meet Vision Transformers》
当CNN遇见Transformer《CMT:Convolutional Neural Networks Meet Vision Transformers》
2022-07-28 17:23:00 【我是大黄同学呀】
原文地址
论文阅读方法
初识
ViT直接将Transformer架构用于视觉,依附于大数据集上的预训练,达到了不错的效果。并且后续也出现大量优秀的改进工作,展现了transformer不凡的性能,但还是弱于相同尺寸的CNN(比如EfficientNet)。
作者认为虽然标准的transformer能够捕获到patch间的长距离依赖关系,但相比于NLP任务,视觉任务中的2D结构,以及patch间的局部空间信息也非常重要。此外,transformer由于固定的尺寸,因此其很难去捕获低分辨率、多尺度的特征,这对密集预测任务非常不利(分割、检测)。而且transformer的self-attention模块对于输入图像分辨率的时间、空间复杂度都是O( N 2 C N^2C N2C),而卷积神经网络为O( N C 2 NC^2 NC2)。
N表示序列长度,C表示维度。
本文的目的就是将CNN的优点结合到Transformer中,以解决上述问题。从而提出了一个全新的架构CMT,引入卷积操作进行细粒度特征提取,此外引入层级结构(stage-wise)用于提取多尺度特征并降低计算消耗,同时也设计了一些特殊的组件提取局部以及全局特征。最后在不同的数据集上进行实验,即提高了性能,也降低计算损耗。
相知
核心技术
此节忽略了Scaling策略和计算复杂度的比较,大家有兴趣可以参考原文。

上图中,(a)为CNN中经典的ResNet网络,(b)为目前的视觉ViT结构。可以看到ViT直接将输入图像切成不重叠的patch然后进行线性映射,这样直接失去了patch中的2维空间特征。因此CMT采用stem结构,用3x3卷积下采样以及提取局部特征。此外,为了提取到多尺度特征采用stage结构,因此每个stage前均使用2x2卷积+LayerNorm进行下采样和升维度(channel x 2)。在每个stage内,构建一系列的CMT模块提取特征,它既能捕获局部性能,也能捕获长距离依赖关系。下面详细介绍下每个block内的细节:
① LPU,local perception unit局部感知单元:

旋转和平移是CNN中常用的增广方法,用于增加模型的平移不变性。然而在ViT中通常采用绝对位置编码,每个patch都对应一个唯一位置编码,因此无法通过数据增广引入平移不变性,也同时忽略了局部相关性和结构信息。因此LPU采用3x3的深度分离卷积+残差连接进一步提取局部特征。
② LMHSA,lightweight multi-head self-attention轻量级多头注意力:

原始的self-attention操作如下:

而LMHSA会先用步长为K的KxK深度卷积减少K与V的空间维度(变为 n k 2 × d k \frac{n}{k^2}\times d_k k2n×dk),并且增加了可学习的偏置项B:

③ IRFFN,inverted residual feed-forward network反向残差前馈网络

这个模块类似于mobilenetv2中的inverted residual模块(两头窄中间宽的通道维度设计),只是改变了残差连接的位置以及使用的是GELU作为激活函数。

最后,作者设计了几种不同的网络架构,有点类似于ResNet与Efficient的结合:
实验结果
实验只附上在ImageNet上的结果,关于消融实验和transfer任务这里不提及。

上图对比了相似精度下的CNN和transformer方法,可以看到CMT在性能提升的基础上,还保持较少的参数量和计算消耗。还有值得注意的一点是,之前所有基于transformer的方法性能均不如efficientnet,而CMT超越了efficientnet,并且计算损耗更低。
回顾
CMT为华为诺亚方舟实验室出品,文章分析了transformer模型在视觉任务上的弊端:1. 损失了空间局部结构信息;2. 参数量大、计算量大;3. 无法提取细粒度特征、多尺度特征。而这些方面CNN做得很好,因此作者将CNN网络的一些经典设计引入到transformer中,并且加入卷积模块,提升效率和性能,比如:ResNet的残差结构、Mobilenet中的depth-wise卷积、efficient中的参数Scaling策略等等。
虽然整篇文章在方法上并没有太高的学术创新,更多偏向工程化的网络设计,但这无疑推动了transformer在CV领域的落地进展,毕竟谁会拒绝一个又快又好的模型呢。
代码
目前官方代码并无开源,但github已经有很多优秀的复现工作,贴上一份:
https://github.com/FlyEgle/CMT-pytorch
边栏推荐
- RFs self study notes (III): clutter model - first determine the number with Poisson distribution, and then use uniform distribution as probability distribution
- 搜索问题与技术
- PyG搭建异质图注意力网络HAN实现DBLP节点预测
- Minio distributed file system learning notes
- 2022年最火的十大测试工具,你掌握了几个
- Using CPLEX to solve small-scale energy-efficient FJSP
- What is the future of software testing? How to learn?
- 【图像隐藏】基于DCT、DWT、LHA、LSB的数字图像信息隐藏系统含各类攻击和性能参数附matlab代码
- QT & OpenGL lighting
- 优麒麟系统安装BeyondComare
猜你喜欢

Pytorch GPU yolov5 reports an error

软件测试开发基础|测开中的几个工具开发实战
![[filter tracking] target tracking based on EKF, TDOA and frequency difference positioning with matlab code](/img/c7/e149e35a544b7a89bbd167c45637a4.png)
[filter tracking] target tracking based on EKF, TDOA and frequency difference positioning with matlab code

About ASM redundancy

Self-adaptive multi-objective evolutionary algorithm for flexible job shop scheduling with fuzzy pro

Using CPLEX to solve small-scale energy-efficient FJSP

Bm11 list addition (II)

From Bayesian filter to Kalman filter (2)

1、 My first wechat applet

Learn from Li Mu, deep learning - linear regression and basic optimization function
随机推荐
Server body 21: pre compilation processing by different compilers (a brief introduction to MSVC and GCC)
Application of time series database in Hydropower Station
How to adjust the brightness of win11? Four methods of adjusting screen brightness in win11
RFs self study notes (III): clutter model - first determine the number with Poisson distribution, and then use uniform distribution as probability distribution
C and SQL mixed programming, vs need to download what things
ACM warm-up exercise 3 in 2022 summer vacation (detailed)
DevCon.exe 导出output至指定文件
Pointer learning of C language -- the consolidation of pointer knowledge and the relationship with functions, arrays and structures
Is software testing really as good as online?
Qt: one signal binds multiple slots
As for the white box test, you have to be skillful in these skills~
Kali doesn't have an eth0 network card? What if you don't connect to the Internet
The difference between --save Dev and --save in NPM
How many of the top ten test tools in 2022 do you master
It is the best tool to evaluate six kinds of map visualization software in three categories
Random finite set RFs self-study notes (6): an example of calculation with the formula of prediction step and update step
pytest 自定义HOOK函数
What if svchost.exe of win11 system has been downloading?
Tikz draw Gantt chart in FJSP -trans necessary
BM11 链表相加(二)