当前位置: 首页 > article >正文

论文阅读(十六):Deep Residual Learning for Image Recognition

文章目录

  • 1.介绍
  • 2.基本原理
  • 3.两种残差块
  • 4.网络结构


  论文:Deep Residual Learning for Image Recognition
  论文链接:Deep Residual Learning for Image Recognition
  代码链接:Github

1.介绍

在这里插入图片描述
  在ResNet网络提出之前,传统的卷积神经网络都是通过将一系列卷积层与下采样层进行堆叠得到的。但是当堆叠到一定网络深度时,就会出现两个问题:

  • 梯度消失/梯度爆炸。
  • 退化问题。

其中,在论文中针对两个问题提出了如下解决方案:

  • 1.梯度消失/梯度爆炸:可通过数据预处理及在网络中使用 B a t c h    N o r m a l i z a t i o n Batch\;Normalization BatchNormalization来解决。
  • 2.退化问题(随着网络层数的加深,效果会变差,如上图所示):本文提出了残差结构( R e s i d u a l    B l o c k Residual\;Block ResidualBlock)进行解决。

  残差块设计的基本思想是,人为地让神经网络某些层跳过下一层神经元的连接,通过隔层相连来弱化每层之间的强联系,这种网络结构称为残差网络( R e s N e t s ResNets ResNets)。效果如下图所示,可见,随着网络的不断加深,效果并没有变差,而是变的更好了。
在这里插入图片描述

2.基本原理

  残差指的是输入特征 x x x与经过卷积模块提取的特征 H ( x ) H(x) H(x)之间的差值。网络深度的增加却使得模型性能下降,说明增加的层并不能学习到新的特征,甚至会导致原始特征的丢失。而若能保证即使新增加的层未学习到任何内容,但也能复制浅层网络学习到的特征(相当于浅层网络的恒等映射),此时深层网络的性能与浅层网络相同,也就解决了残差问题。
  传统的CNN网络如左图所示( C o n v + R e L U + C o n v Conv+ReLU+Conv Conv+ReLU+Conv):
在这里插入图片描述
其输出可定义为 H ( x ) = C o n v ( R e L U ( C o n v ( x ) ) ) H(x)=Conv(ReLU(Conv(x))) H(x)=Conv(ReLU(Conv(x))),而残差网络的结构如下图所示:
在这里插入图片描述
与普通CNN网络结构相比,残差网络增加了跳跃连接( s k i p    c o n n e c t i o n skip\;connection skipconnection),将输入 x x x恒等映射到第二个激活函数之前与 F ( x ) = C o n v ( R e L U ( C o n v ( x ) ) ) F(x)=Conv(ReLU(Conv(x))) F(x)=Conv(ReLU(Conv(x)))之间相加(假设 w e i g h t    l a y e r = C o n v weight\;layer=Conv weightlayer=Conv)。通过这种操作,使得网络在最差的情况下也能获得和输入一样的输出,即增加的层什么也不学习,仅仅复制输入的特征,至少使得网络不会出现退化的问题。

3.两种残差块

   R e s N e t ResNet ResNet中一共有两种残差块结构:
在这里插入图片描述

其中,左侧的残差结构常用于层数较少的 R e s N e t ResNet ResNet中,如例如ResNet18层和ResNet34层网络。而右侧则常用于层数较多的 R e s N e t ResNet ResNet中。这是因为右侧的残差结构能够减少网络参数与运算量。同样输入一个channel为256的特征矩阵,如果使用左侧的残差结构需要大约1170648个参数,但如果使用右侧的残差结构只需要69632个参数。

【残差结构一】
在这里插入图片描述
  上图中左侧的残差块结构用于 R e s N e t    18 − l a y e r 、 34 − l a y e r ResNet\;18-layer、34-layer ResNet18layer34layer网络中,其主分支由两个3x3的卷积层组成,而右侧的分支结构则实现 x x x的恒等映射。
  在 R e s N e t    34 − l a y e r ResNet\;34-layer ResNet34layer中有一些恒等映射使用虚线连接的残差结构,如:
在这里插入图片描述
其真实结构如上图右侧所示,此时恒等映射需要通过卷积核1x1大小、步长为2、个数为128的卷积层来调整 x x x的形状,使之能够与 F ( x ) F(x) F(x)进行相加。

【残差结构二】
在这里插入图片描述
  上图左侧的残差块结构用于 R e s N e t    50 − l a y e r 、 101 − l a y e r 、 152 − l a y e r ResNet\;50-layer、101-layer、152-layer ResNet50layer101layer152layer中,主分支中共有三个卷积层,其中,第一个卷积层用于压缩输入矩阵的通道数,第三个卷积层则将通道数还原回原始大小。
  这些网络中同样有一些恒等映射使用虚线连接的残差结构,具体实现方式如右图所示。其并不直接进行恒等映射,而是使用1x1的卷积块调整输入矩阵的通道数,使能够与 F ( x ) F(x) F(x)正常相加来实现恒等映射。例如, R e s N e t    50 − l a y e r ResNet\;50-layer ResNet50layer B o t t l e n e c k Bottleneck Bottleneck代码实现:

class Bottleneck(nn.Module):
    def __init__(self, inplanes, planes, stride=1, downsample=None, dilation=1):
    	#inplanes:输入通道数;planes:输出通道数;stride:步幅;downsample:下采样层;dilation:膨胀系数
        super(Bottleneck, self).__init__()
        #1×1卷积
        self.conv1      = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False)
        self.bn1        = nn.BatchNorm2d(planes)
        #3×3卷积
        self.conv2      = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=(3*dilation-1)//2, bias=False, dilation=dilation)
        self.bn2        = nn.BatchNorm2d(planes)
        #1×1卷积
        self.conv3      = nn.Conv2d(planes, planes*4, kernel_size=1, bias=False)
        self.bn3        = nn.BatchNorm2d(planes*4)
        #下采样(若步幅不为1或输入通道数与目标通道数不匹配,则进行下采样)
        self.downsample = downsample

    def forward(self, x):
        residual = x
        #1×1卷积
        out      = F.relu(self.bn1(self.conv1(x)), inplace=True)
        #3×3卷积
        out      = F.relu(self.bn2(self.conv2(out)), inplace=True)
        #1×1卷积
        out      = self.bn3(self.conv3(out))
        #若不能直接将x与特征残差连接,则需下采样(对应虚线部分)
        if self.downsample is not None:
            residual = self.downsample(x)
        #残差连接
        return F.relu(out+residual, inplace=True)

downsample在网络中的实现为:

if stride != 1 or self.inplanes != planes*4:
	#使用1×1卷积和批量归一化进行下采样
	downsample = nn.Sequential(nn.Conv2d(self.inplanes, planes*4, kernel_size=1, stride=stride, bias=False), nn.BatchNorm2d(planes*4))

4.网络结构

在这里插入图片描述
  下面这幅图是原论文给出的不同深度的ResNet网络结构配置,表中的残差结构给出了主分支上卷积核的大小与卷积核个数,其中, x N xN xN表示将该残差结构重复N次。
  在 R e s N e t    18 − l a y e r 、 34 − l a y e r 、 50 − l a y e r 、 101 − l a y e r 、 152 − l a y e r ResNet\;18-layer、34-layer、50-layer、101-layer、152-layer ResNet18layer34layer50layer101layer152layer中, c o n v 3 _ x 、 c o n v 4 _ x 、 c o n v 5 _ x conv3\_x、conv4\_x、conv5\_x conv3_xconv4_xconv5_x对应的残差链(指由多个残差块连接而成)结构中,第一层均使用带虚线的残差块来调整输入矩阵的形状(将输入矩阵的高和宽缩减为原来的一半,将图像通道数调整成下一层残差结构所需要的通道数)。例如, 34 − l a y e r 34-layer 34layer的结构如下图所示:
在这里插入图片描述
  而在 R e s N e t    50 − l a y e r 、 101 − l a y e r 、 152 − l a y e r ResNet\;50-layer、101-layer、152-layer ResNet50layer101layer152layer中,其 c o n v 2 _ x conv2\_x conv2_x结构的第一层也是虚线残差块结构,其需要调整输入特征矩阵的通道数。


http://www.kler.cn/news/355107.html

相关文章:

  • Transformer图解以及相关的概念
  • Redis 一初识安装
  • 【机器学习基础】nn.Dropout的用法
  • ES6 Promise的用法
  • Ubuntu配置防火墙
  • ruoyi框架连接mysql+sqlserver
  • QT QML 练习8-Simple Transformations
  • MongoDB 死锁 锁定问题
  • 【C++】unordered_set、unordered_map超详细封装过程,处理底层细节
  • 算法笔记 C/C++快速入门 | 全章节整理
  • 『Mysql集群』Mysql高可用集群之主从复制 (一)
  • 【Java基础】常用类方法记录
  • Python 使用 Jarvis 算法或包装的凸包(Convex Hull using Jarvis’ Algorithm or Wrapping)
  • Unknown column ‘oMIbw5H29LXtmAUjSSm7ZrymASUI‘ in ‘where clause‘
  • 前端技巧汇总
  • 驱动总裁免登陆单文件版
  • 网页前端开发之HTML入门篇:标题标签 heading
  • Leetcode 1223 LCA of Deepest TreeNode
  • 带头结点的单链表按数据域从小到大进行选择排序的算法
  • 生成器和迭代器