Res-Family: From ResNet to SE-ResNeXt
姚伟峰
http://www.cnblogs.com/Matrix_Yao/
Res-Family: From ResNet to SE-ResNeXt
ResNet(2015 Dec)
Paper
Network Visualization
Problem Statement
Why
Conclusion
How to Solve it
Breakdown
Residule Module
Identity Shortcut and Projection Shortcut
Tricks
Mind Experiment
Another Perspective
ResNet-v2 (2016 Jul)
Paper
Network Visualization
Motivation
The Ways
The Importance of Identity Shortcut
Proposed Architecture
Mind Experiment
ResNeXt (2017 Apr)
Paper
Network Visualization
Motivation
The Ways
美来自简单的重复
C和d的确定
One more thing
效果
Mind Experiment
SE-ResNet, SE-ResNeXt (2018 Apr)
Paper
Network Visualization
Motivation
How it works
Implementation Notes
Mind Experiment
ResNet(2015 Dec)
Paper
Deep Residual Learning for Image Recognition
Network Visualization
https://dgschwend.github.io/netscope/#/preset/resnet-50
Problem Statement
A paradox between neural network depth and its representation capability.
Intuition:
deeper the network, stronger the representation capability
Observation
network performance will degrade while network is deeper
Alt text
Why
Overfit
Gradient Vanish checked back propogated diff, also BN can secure this.
Conjecture: deep plain nets may have exponentially low convergence rate, which impact the reducing of the training error.
Conclusion
Current plain network design impede us pursue bigger representation capability through make network deeper.
How to Solve it
可以通过构造性方法,构造出一个性能至少与对应的浅层模型相等的深度模型。当add-on block输出为0时,这个deeper net的性能与shallower net的性能一致。
Alt text
从函数逼近的角度,假设我们需要逼近函数, shallower net给出了一个, 那add-on block可以看作在逼近, 即残差(residual),这本质上是残差学习(residual learning)或者是boosting的想法。这也是ResNet的基本想法。
Breakdown
Residule Module
Alt text
the right block is called bottleneck architecture.
Alt text
Identity Shortcut and Projection Shortcut
上面的topology图中,实线即表示identity shortcut,虚线即表示projection shortcut. 出现projection shortcut的原因是该module内部的操作改变了feature map的dimension(height, width, channel),我们需要一个projection来match dimension。下图中的f指该模块的输出channel数。
Alt text
Tricks
h/w和c的关系是:spatial每做一次1/2 down sample, c就乘以2, 所以
Mind Experiment
对ResNet-50 inference有哪些适用的优化策略?
operator fusion
vertical fusion
BN folding
conv + BN + ScaleShift -> conv
conv + relu
conv + relu + pooling
conv + eltsum + relu Alt text
horizontal fusion
multi-branch fusion Alt text
advanced tech
lossless topology compression Alt text
other potentials
kernel = 1 pooling optimization Alt text
Another Perspective
We can treat ResNet as a Stacked Boosting Ensemble.
ResNet-v2 (2016 Jul)
Paper
Identity Mappings in Deep Residual Networks
Network Visualization
http://dgschwend.github.io/netscope/#/gist/6a771cf2bf466c5343338820d5102e66
Motivation
When we express ResNet as a general formula:
在ResNet中,所以称为shortcut。 另一个叫法就是highway,因为的信息在这条路径上可以无衰减地传输,就像一个高速公路一样。但在ResNet中因为是一个ReLU会损失掉一部分信息,所以的无衰减传输只能限于本block, 并不能在整个网络中无衰减地传下去。现在的猜想是:如果我们把也变成一个identity mapping,这个highway会更加顺畅,效果会不会更好?
The Ways
The Importance of Identity Shortcut
作者尝试了很多种方式与identity shortcut作了对比,发现效果都没有identity shortcut好。
Alt text
Alt text
Proposed Architecture
Alt text
上述结构称为pre-activation Residual Module,因为与以前的Residual Block是CBR(Conv, BN, ReLU)结构,而这个是BRC(BN, ReLU, Conv)结构,activation在conv之前,所以称为pre-activation结构。
因此,ResNet-v2可以表示为如下形式:
即 ,把递归式展开,有:
这是一个纯的additive model,比ResNet更像stacked boosting。效果如下图:
Alt text
Mind Experiment
ResNet-v2 在inference优化上与ResNet有什么不同的地方?
New Vertical Fusion
BN + ReLU
Conv + eltsum
有同学会觉得上面的b图中的两个branch因为scaling都是0.5,与原始Residual Block相比只相当于把再乘个0.5, 在数学上是等价的,为啥效果会差很多呢?。这句话对了一半,就单个module而言,确实如此。
但一旦把module串联起来形成网络,事情发生了质的变化。不失一般性,我们如下形式化constant scaling module(这里为了简化推导我把relu换成了identity,不会影响最终结论):
把递归式展开后为:
可以看到与原展开式相比,constant scaling对输入特征进行了指数式衰减,两者是完全不等价的。
ResNeXt (2017 Apr)
Paper
Aggregated Residual Transformations for Deep Neural Networks
Network Visualization
https://chakkritte.github.io/netscope/#/preset/resnext-50
Motivation
随着deep learning的兴起,视觉识别中的研究已经从feature engineering转向了network engineering,即设计topology。而随着深度的增加,topology中超参数(如卷积核大小,stride,channel数等)越来越多,很难确定。VGG和ResNet的成功表明通过堆叠相同形状的block的方法不仅可以显著减少超参数的数量,而且能取得SOTA的结果,是非常有前途的方向(这个感觉跟分形的想法很类似)。这是方向一。
而以GoogleNet/GoogleNet-v2/Inception为代表的实践也表明,通过split-transform-merge策略进行精细的网络设计也能达到非常好的结果。这是方向二。
Alt text
ResNeXt的想法是把这两种好的想法揉到一起,看效果会不会更好。“In this paper, we present a simple architecture which adopts VGG/ResNets’ strategy of repeating layers, while exploiting the split-transform-merge strategy in an easy, extensible way.”
The Ways
美来自简单的重复
如果像GoogleNet系那样做split-transform-merge(如上图),因为每个branch都需要设计卷积核的超参,以及branch的深度,所以超参会迅速膨胀。所以,要想个办法,既做了split-transform-merge,有没有多少超参量的增加,这个时候其实还是利用“重复大法”来达成。我们先看一下ResNeXt的设计:
Alt text
可以看到这个结构是一个单元重复32次然后再相加的结果。每个单元是一个bottleneck结构:先把输入feature map 通过1x1卷积embedding到4 channel的feature map,然后做3x3卷积,然后再expand回去。我们把这个结构叫做32x4d的结构。其中32是ResNeXt引入的新的自由度,称为cardinality。ResNeXt的名字也源于此,X指的就是 neXt dimension。最后,不要忘了residual shortcut。
C和d的确定
为了得到与对应的ResNet参数量相当的ResNeXt,我们可以按照如下公式确定ResNeXt block的C和d:
One more thing
进一步地,通过等效变形,可以把ResNeXt看成是囊括了GoogleNet/grouped convolution/ResNet的一种范型。 这样,ResNeXt论文的层次就超脱了只是ResNet的优化了。
Alt text
上图a是ResNeXt module的原始形式,b是googlenet形式的等价型,c是group convolution的等价型。从性能(速度)的角度看,c的最好。
效果
最后作者给出了top-1 error,可以看到确实有较明显的提升。
Alt text
Mind Experiment
ResNeXt从最终实现上来看与ResNet基本相同,唯一区别是residual module中的 3x3 convolution被换成了group convolution。
SE-ResNet, SE-ResNeXt (2018 Apr)
Paper
Squeeze-And-Excitation Networks
Network Visualization
http://dgschwend.github.io/netscope/#/gist/4a41df70a3c7c41f97d775f991f036e3
Motivation
2017年开始,Google说“Attention is all you need”,天下豪杰竞相响应。2018的很多工作的都是基于Attention机制的进展。这篇文章也可看作其中之一,因为我们可以把SENet看成是channel-wise的attention。如下图,SENet在常规动作后增加了一条专门计算channel-wise scale的branch,然后把得到的值乘到相应的channel上。
Alt text
How it works
SENet计算channel-wise attention,分为两个步骤:
Squeeze: 如下图的红框。把每个input feature map的spatial dimension 从H * W squeeze到1。这里是通过global average pooling完成的。
Alt text
Excitation: 如下图的绿框。通过一个bottleneck结构来捕捉channel的inter-dependency,从而学到channel的scale factor(或者说是attention factor) 。
Alt text
下图是SE-ResNet, 可以看到SE module被apply到了residual branch上。
Alt text
下图是网络配置,这里FC后边的方括号里面的数表示和。
Alt text
最后是效果,可以看到SENet在收敛速度和accuracy上都有提高。
Alt text
Implementation Notes
SENet的FC等效于1x1的convolution,可以用conv1x1来代替。
channel wise scale + eltsum可以fuse成channel-wise axpy。
Mind Experiment
Q: SE module最终实现上其实是channel wise的scale,这个在数学操作上与BN是一样的。那SE module为什么不能被BN代替呢?
A:BN只建模了spatial内的dependency,而SE module不仅建模了spatial dependency还建模了inter-channel的dependency。https://www.cnblogs.com/Matrix_Yao/p/9563063.html