经典卷积神经网络-ResNet

经典卷积神经网络-ResNet

一、背景介绍

残差神经网络(ResNet)是由微软研究院的何恺明、张祥雨、任少卿、孙剑等人提出的。ResNet 在2015 年的ILSVRC(ImageNet Large Scale Visual Recognition Challenge)中取得了冠军。残差神经网络的主要贡献是发现了“退化现象(Degradation)”,并针对退化现象发明了 “快捷连接(Shortcut connection)”,极大的消除了深度过大的神经网络训练困难问题。神经网络的“深度”首次突破了100层、最大的神经网络甚至超过了1000层。

在这里插入图片描述

二、ResNet网络结构

2.0 残差块

在这里插入图片描述

配合吴恩达深度学习视频中的图片进行讲解:

在这里插入图片描述

如图所示,Residual block就是将 a [ l ] a^{[l]} a[l]传送到 z l + 2 z^{l+2} zl+2上,其相加之后再进行激活得到 a [ l + 2 ] a^{[l+2]} a[l+2]。这一步骤称为"skip connection",即指 a [ l ] a^{[l]} a[l]跳过一层或好几层,从而将信息传递到神经网络的更深层。所以构建一个ResNet网络就是通过将很多这样的残差块堆积在一起,形成一个深度神经网络。

那么引入残差块为什么有效呢? 一个直观上的理解:

在这里插入图片描述

如图所示,假设我们给我们的神经网络再增加两层,我们要得到 a [ l + 2 ] a^{[l+2]} a[l+2],我们通过增加一个残差块来完成。这时 a [ l + 2 ] = g ( z [ l + 2 ] + a [ l ] ) = g ( w [ l + 2 ] a [ l + 1 ] + a [ l ] ) a^{[l+2]}=g(z^{[l+2]}+a^{[l]})=g(w^{[l+2]}a^{[l+1]}+a^{}[l]) a[l+2]=g(z[l+2]+a[l])=g(w[l+2]a[l+1]+a[l]),如果我们应用了L2正则化,此时权重参数会减小,我们可以极端的假设 w [ l + 2 ] = 0 , b [ l + 2 ] = 0 w^{[l+2]}=0,b^{[l+2]}=0 w[l+2]=0b[l+2]=0,那么得到 a [ l + 2 ] = g ( a [ l ] ) = a [ l ] a^{[l+2]}=g(a^{[l]})=a^{[l]} a[l+2]=g(a[l])=a[l](因为使用的是ReLU激活函数,非负的值激活后为原来的值, a [ l ] a^{[l]} a[l]已经经过ReLU激活过了,所以全为非负值)。这意味着,即使给神经网络增加了两层,它的效果并不逊色于更简单的神经网络。所以给大型的神经网络添加残差块来增加网络深度,并不会影响网络的表现。如果我们增加的这两层碰巧能学习到一些有用的信息,那么它就比原来的神经网络表现的更好。

论文中ResNet层数在34及以下和50及以上时采用的是不同的残差块。下面我们分别介绍:

2.1 ResNet-34

在这里插入图片描述

如上图所示是ResNet-34以下采用的残差块,我们将其称作BasicBlock

ResNet-34的网络结构如下:图中实线表示通道数没有变化,虚线表示通道数发生了变化。

在这里插入图片描述

其具体的网络结构如下表:

在这里插入图片描述

2.2 ResNet-50

在这里插入图片描述

如图所示是ResNet-50以上采用的残差块,我们将其称作Bottleneck,使用了1 × 1的卷积来进行通道数的改变,减小计算量。其具体的网络结构见上面的表。

三、论文部分解读

  • 论文中的第一张图就表明了更深层的“plain”神经网络(即不用Residual Learning)的错误率在训练集和测试集上甚至比层数少的“plain”神经网络还要高,所以就引出了问题:训练很深的网络是一个很难的问题。
    在这里插入图片描述

  • 论文中的这张图就表明了,使用Residual Learning后训练更深层的神经网络效果会变得更好。

    在这里插入图片描述

  • 论文中处理残差连接中输入和输出不对等的解决方法:

    • 添加一些额外的0,使得输入和输出的形状可以对应起来可以做相加。
    • 输入和输出不对等的时候使用1 × 1的卷积操作来做投影(目前都是这种方法)
    • 所有的地方都使用1 × 1的卷积来做投影,计算量太大没必要
  • 论文最主要的是提出了residual结构(残差结构),并搭建超深的网络结构(突破1000层)

  • 使用了大量BN来加速训练(丢弃dropout)

  • 论文中对CIFAR10数据集做了大量实验验证其效果,最后还将ResNet用到了目标检测领域

三、ResNet-18的Pytorch实现

import torch
import torch.nn as nn
import torchsummary


# BasicBlock
class BasicBlock(nn.Module):
    def __init__(self, in_channels, out_channels, stride=1):
        super(BasicBlock, self).__init__()
        
        # 第一个卷积有可能要进行下采样 即将输出通道翻倍 输出数据大小全部减半
        # 所以我们让第一个卷积的stride设置为可传入的参数
        # 如果要进行BN 卷积就不需要加偏置
        self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=stride, padding=1, bias=False)
        self.bn1 = nn.BatchNorm2d(out_channels)
        self.relu = nn.ReLU(inplace=True)

        # 第二个卷积保持尺寸和通道数
        self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=False)
        self.bn2 = nn.BatchNorm2d(out_channels)

        # 如果最后输入和输出的通道数不一样 那么就用1 × 1的卷积调节输入 方便后面能和输出相加
        # shortcut操作也是downsample(下采样) 即将输出通道翻倍 输出数据大小全部减半
        # 这一步主要做的就是为了能让最后的输出数据和输入数据"连接"上 即相加
        self.shortcut = nn.Sequential()
        if stride != 1 or in_channels != out_channels:
            self.shortcut = nn.Sequential(
                nn.Conv2d(in_channels, out_channels, stride=stride, kernel_size=1, bias=False),
                nn.BatchNorm2d(out_channels)
            )

    def forward(self, x):
        # 记录identity
        identity = x

        out = self.conv1(x)
        out = self.bn1(out)
        out = self.relu(out)

        out = self.conv2(out)
        out = self.bn2(out)

        # 进行残差连接
        out += self.shortcut(identity)
        # 残差连接之后激活
        out = self.relu(out)

        return out


# ResNet-18
class ResNet18(nn.Module):
    def __init__(self, num_classes=1000):
        super(ResNet18, self).__init__()
        # output_size = [(input_size - kernel_size + 2padding) / stride] + 1
        # 112 = [(224 - 7 + 2padding) / stride] + 1 -> padding = 3
        self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, bias=False)
        self.bn1 = nn.BatchNorm2d(64)
        self.relu = nn.ReLU(inplace=True)
        # 56 = [(112 - 3 + 2padding) / 2] + 1 -> padding = 1
        self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)

        self.layer1 = self._make_layer(in_channels=64, out_channels=64, blocks=2, stride=1)
        self.layer2 = self._make_layer(in_channels=64, out_channels=128, blocks=2, stride=2)
        self.layer3 = self._make_layer(in_channels=128, out_channels=256, blocks=2, stride=2)
        self.layer4 = self._make_layer(in_channels=256, out_channels=512, blocks=2, stride=2)

        # 平均池化 参数就是out_size
        self.avgpool = nn.AdaptiveAvgPool2d((1, 1))

        self.fc = nn.Linear(512, num_classes)

    def _make_layer(self, in_channels, out_channels, blocks, stride=1):
        layer = []
        # 因为第一个残差块的输入通道可能与输出通道不同 所以单独拿出来赋值
        layer.append(BasicBlock(in_channels, out_channels, stride))
        for _ in range(1, blocks):
            layer.append(BasicBlock(out_channels, out_channels))
        return nn.Sequential(*layer)

    def forward(self, x):
        out = self.conv1(x)
        out = self.bn1(out)
        out = self.relu(out)
        out = self.maxpool(out)

        out = self.layer1(out)
        out = self.layer2(out)
        out = self.layer3(out)
        out = self.layer4(out)

        out = self.avgpool(out)
        out = torch.flatten(out, 1)
        out = self.fc(out)

        return out


if __name__ == '__main__':
    DEVICE = "cuda" if torch.cuda.is_available() else "cpu"

    model = (ResNet18())
    model.to(DEVICE)
    # print(model)

    print(torch.cuda.is_available())

    torchsummary.summary(model, (3, 224, 224), 64)

主要注意点是:

  • BasicBlock(34层以下的残差块)中残差连接的方法,注意输入和输出的通道数,用1×1的卷积做好尺寸和维度对齐。
  • 使用_make_layer()函数批量生成残差块。

在控制台输出网络结构:

ResNet18(
  (conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
  (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (relu): ReLU(inplace=True)
  (maxpool): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)
  (layer1): Sequential(
    (0): BasicBlock(
      (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (shortcut): Sequential()
    )
    (1): BasicBlock(
      (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (shortcut): Sequential()
    )
  )
  (layer2): Sequential(
    (0): BasicBlock(
      (conv1): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (shortcut): Sequential(
        (0): Conv2d(64, 128, kernel_size=(1, 1), stride=(2, 2), bias=False)
        (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (1): BasicBlock(
      (conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (shortcut): Sequential()
    )
  )
  (layer3): Sequential(
    (0): BasicBlock(
      (conv1): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (shortcut): Sequential(
        (0): Conv2d(128, 256, kernel_size=(1, 1), stride=(2, 2), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (1): BasicBlock(
      (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (shortcut): Sequential()
    )
  )
  (layer4): Sequential(
    (0): BasicBlock(
      (conv1): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (shortcut): Sequential(
        (0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)
        (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (1): BasicBlock(
      (conv1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (shortcut): Sequential()
    )
  )
  (avgpool): AdaptiveAvgPool2d(output_size=(1, 1))
  (fc): Linear(in_features=512, out_features=1000, bias=True)
)

使用torchsummary来测试网络:

----------------------------------------------------------------
        Layer (type)               Output Shape         Param #
================================================================
            Conv2d-1         [64, 64, 112, 112]           9,408
       BatchNorm2d-2         [64, 64, 112, 112]             128
              ReLU-3         [64, 64, 112, 112]               0
         MaxPool2d-4           [64, 64, 56, 56]               0
            Conv2d-5           [64, 64, 56, 56]          36,864
       BatchNorm2d-6           [64, 64, 56, 56]             128
              ReLU-7           [64, 64, 56, 56]               0
            Conv2d-8           [64, 64, 56, 56]          36,864
       BatchNorm2d-9           [64, 64, 56, 56]             128
             ReLU-10           [64, 64, 56, 56]               0
       BasicBlock-11           [64, 64, 56, 56]               0
           Conv2d-12           [64, 64, 56, 56]          36,864
      BatchNorm2d-13           [64, 64, 56, 56]             128
             ReLU-14           [64, 64, 56, 56]               0
           Conv2d-15           [64, 64, 56, 56]          36,864
      BatchNorm2d-16           [64, 64, 56, 56]             128
             ReLU-17           [64, 64, 56, 56]               0
       BasicBlock-18           [64, 64, 56, 56]               0
           Conv2d-19          [64, 128, 28, 28]          73,728
      BatchNorm2d-20          [64, 128, 28, 28]             256
             ReLU-21          [64, 128, 28, 28]               0
           Conv2d-22          [64, 128, 28, 28]         147,456
      BatchNorm2d-23          [64, 128, 28, 28]             256
           Conv2d-24          [64, 128, 28, 28]           8,192
      BatchNorm2d-25          [64, 128, 28, 28]             256
             ReLU-26          [64, 128, 28, 28]               0
       BasicBlock-27          [64, 128, 28, 28]               0
           Conv2d-28          [64, 128, 28, 28]         147,456
      BatchNorm2d-29          [64, 128, 28, 28]             256
             ReLU-30          [64, 128, 28, 28]               0
           Conv2d-31          [64, 128, 28, 28]         147,456
      BatchNorm2d-32          [64, 128, 28, 28]             256
             ReLU-33          [64, 128, 28, 28]               0
       BasicBlock-34          [64, 128, 28, 28]               0
           Conv2d-35          [64, 256, 14, 14]         294,912
      BatchNorm2d-36          [64, 256, 14, 14]             512
             ReLU-37          [64, 256, 14, 14]               0
           Conv2d-38          [64, 256, 14, 14]         589,824
      BatchNorm2d-39          [64, 256, 14, 14]             512
           Conv2d-40          [64, 256, 14, 14]          32,768
      BatchNorm2d-41          [64, 256, 14, 14]             512
             ReLU-42          [64, 256, 14, 14]               0
       BasicBlock-43          [64, 256, 14, 14]               0
           Conv2d-44          [64, 256, 14, 14]         589,824
      BatchNorm2d-45          [64, 256, 14, 14]             512
             ReLU-46          [64, 256, 14, 14]               0
           Conv2d-47          [64, 256, 14, 14]         589,824
      BatchNorm2d-48          [64, 256, 14, 14]             512
             ReLU-49          [64, 256, 14, 14]               0
       BasicBlock-50          [64, 256, 14, 14]               0
           Conv2d-51            [64, 512, 7, 7]       1,179,648
      BatchNorm2d-52            [64, 512, 7, 7]           1,024
             ReLU-53            [64, 512, 7, 7]               0
           Conv2d-54            [64, 512, 7, 7]       2,359,296
      BatchNorm2d-55            [64, 512, 7, 7]           1,024
           Conv2d-56            [64, 512, 7, 7]         131,072
      BatchNorm2d-57            [64, 512, 7, 7]           1,024
             ReLU-58            [64, 512, 7, 7]               0
       BasicBlock-59            [64, 512, 7, 7]               0
           Conv2d-60            [64, 512, 7, 7]       2,359,296
      BatchNorm2d-61            [64, 512, 7, 7]           1,024
             ReLU-62            [64, 512, 7, 7]               0
           Conv2d-63            [64, 512, 7, 7]       2,359,296
      BatchNorm2d-64            [64, 512, 7, 7]           1,024
             ReLU-65            [64, 512, 7, 7]               0
       BasicBlock-66            [64, 512, 7, 7]               0
AdaptiveAvgPool2d-67            [64, 512, 1, 1]               0
           Linear-68                 [64, 1000]         513,000
================================================================
Total params: 11,689,512
Trainable params: 11,689,512
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 36.75
Forward/backward pass size (MB): 4018.74
Params size (MB): 44.59
Estimated Total Size (MB): 4100.08
----------------------------------------------------------------

四、ResNet-50的Pytorch实现

import torch
import torch.nn as nn
import torchsummary


# Bottleneck
class Bottleneck(nn.Module):
    # expansion = 4,因为Bottleneck中每个残差结构输出维度都是输入维度的4倍
    expansion = 4

    def __init__(self, in_channels, out_channels, stride=1):
        super(Bottleneck, self).__init__()

        # 注意这里1×1的卷积不用padding
        self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=stride, bias=False)
        self.bn1 = nn.BatchNorm2d(out_channels)
        # 维持特征图尺寸 padding = 1
        self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=False)
        self.bn2 = nn.BatchNorm2d(out_channels)
        # 注意这里1×1的卷积不用padding
        self.conv3 = nn.Conv2d(out_channels, out_channels * self.expansion, kernel_size=1, stride=1, bias=False)
        self.bn3 = nn.BatchNorm2d(out_channels * self.expansion)
        self.relu = nn.ReLU(inplace=True)

        self.shortcut = nn.Sequential()
        if stride != 1 or in_channels != out_channels * self.expansion:
            self.shortcut = nn.Sequential(
                nn.Conv2d(in_channels, out_channels * self.expansion, stride=stride, kernel_size=1, bias=False),
                nn.BatchNorm2d(out_channels * self.expansion)
            )

    def forward(self, x):
        identity = x

        out = self.conv1(x)
        out = self.bn1(out)
        out = self.relu(out)

        out = self.conv2(out)
        out = self.bn2(out)
        out = self.relu(out)

        out = self.conv3(out)
        out = self.bn3(out)

        # 残差连接
        out += self.shortcut(identity)
        out = self.relu(out)

        return out


# ResNet50
class ResNet50(nn.Module):

    def __init__(self, num_classes=1000):
        super(ResNet50, self).__init__()
        # output_size = [(input_size - kernel_size + 2padding) / stride] + 1
        # 112 = [(224 - 7 + 2padding) / stride] + 1 -> padding = 3
        self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, bias=False)
        self.bn1 = nn.BatchNorm2d(64)
        self.relu = nn.ReLU(inplace=True)
        # 56 = [(112 - 3 + 2padding) / 2] + 1 -> padding = 1
        self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)

        self.layer1 = self._make_layer(64, 64, blocks=3, stride=1)
        self.layer2 = self._make_layer(256, 128, blocks=4, stride=2)
        self.layer3 = self._make_layer(512, 256, blocks=6, stride=2)
        self.layer4 = self._make_layer(1024, 512, blocks=3, stride=2)

        # 平均池化 参数就是out_size
        self.avgpool = nn.AdaptiveAvgPool2d((1, 1))

        self.fc = nn.Linear(2048, num_classes)

    def _make_layer(self, in_channels, out_channels, blocks, stride=1):
        layer = []
        # 因为第一个残差块的输入通道可能与输出通道不同 所以单独拿出来赋值
        layer.append(Bottleneck(in_channels, out_channels, stride))
        for _ in range(1, blocks):
            # 接下来的每一个其输入通道都是输出的四倍
            layer.append(Bottleneck(out_channels * 4, out_channels))
        return nn.Sequential(*layer)

    def forward(self, x):
        out = self.conv1(x)
        out = self.bn1(out)
        out = self.relu(out)
        out = self.maxpool(out)

        out = self.layer1(out)
        out = self.layer2(out)
        out = self.layer3(out)
        out = self.layer4(out)

        out = self.avgpool(out)
        out = torch.flatten(out, 1)
        out = self.fc(out)

        return out

if __name__ == '__main__':
    DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
    model = ResNet50()
    model.to(DEVICE)
    # print(model)

    torchsummary.summary(model, (3, 224, 224), 64)

主要注意点是:

  • Bottleneck(50层以上残差块)中块与块直接连接的通道数问题。在BasicBlock中由于两个相同的块在连接的时候通道数是相同的,而Bottleneck中两个相同的块在连接的时候其通道数相差四倍。即下面这段代码:

        for _ in range(1, blocks):
            # 接下来的每一个其输入通道都是输出的四倍
            layer.append(Bottleneck(out_channels * 4, out_channels))
    
  • 注意最后全连接的通道数,ResNet50以上的最后全连接的in_features为2048。

  • 注意在残差连接的时候,shortcut调整的维度一定要和输出维度对上,即下面这段代码:

    self.shortcut = nn.Sequential()
    if stride != 1 or in_channels != out_channels * self.expansion:
        self.shortcut = nn.Sequential(
            nn.Conv2d(in_channels, out_channels * self.expansion, stride=stride, kernel_size=1, bias=False),
            nn.BatchNorm2d(out_channels * self.expansion)
        )
    
  • 写代码的时候,要注意只有每一堆残差块结构中的第一个残差块的第一个卷积操作的stride为2,其余都为1,(除了第一堆残差块要维持尺度不变),即:

    self.layer1 = self._make_layer(64, 64, blocks=3, stride=1)
    

在控制台输出网络结构:

ResNet50(
  (conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
  (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (relu): ReLU(inplace=True)
  (maxpool): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)
  (layer1): Sequential(
    (0): Bottleneck(
      (conv1): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential(
        (0): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (1): Bottleneck(
      (conv1): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential()
    )
    (2): Bottleneck(
      (conv1): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential()
    )
  )
  (layer2): Sequential(
    (0): Bottleneck(
      (conv1): Conv2d(256, 128, kernel_size=(1, 1), stride=(2, 2), bias=False)
      (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential(
        (0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)
        (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (1): Bottleneck(
      (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential()
    )
    (2): Bottleneck(
      (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential()
    )
    (3): Bottleneck(
      (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential()
    )
  )
  (layer3): Sequential(
    (0): Bottleneck(
      (conv1): Conv2d(512, 256, kernel_size=(1, 1), stride=(2, 2), bias=False)
      (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential(
        (0): Conv2d(512, 1024, kernel_size=(1, 1), stride=(2, 2), bias=False)
        (1): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (1): Bottleneck(
      (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential()
    )
    (2): Bottleneck(
      (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential()
    )
    (3): Bottleneck(
      (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential()
    )
    (4): Bottleneck(
      (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential()
    )
    (5): Bottleneck(
      (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential()
    )
  )
  (layer4): Sequential(
    (0): Bottleneck(
      (conv1): Conv2d(1024, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)
      (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential(
        (0): Conv2d(1024, 2048, kernel_size=(1, 1), stride=(2, 2), bias=False)
        (1): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (1): Bottleneck(
      (conv1): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential()
    )
    (2): Bottleneck(
      (conv1): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
      (shortcut): Sequential()
    )
  )
  (avgpool): AdaptiveAvgPool2d(output_size=(1, 1))
  (fc): Linear(in_features=2048, out_features=1000, bias=True)
)

使用torchsummary来测试网络:

----------------------------------------------------------------
        Layer (type)               Output Shape         Param #
================================================================
            Conv2d-1         [64, 64, 112, 112]           9,408
       BatchNorm2d-2         [64, 64, 112, 112]             128
              ReLU-3         [64, 64, 112, 112]               0
         MaxPool2d-4           [64, 64, 56, 56]               0
            Conv2d-5           [64, 64, 56, 56]           4,096
       BatchNorm2d-6           [64, 64, 56, 56]             128
              ReLU-7           [64, 64, 56, 56]               0
            Conv2d-8           [64, 64, 56, 56]          36,864
       BatchNorm2d-9           [64, 64, 56, 56]             128
             ReLU-10           [64, 64, 56, 56]               0
           Conv2d-11          [64, 256, 56, 56]          16,384
      BatchNorm2d-12          [64, 256, 56, 56]             512
           Conv2d-13          [64, 256, 56, 56]          16,384
      BatchNorm2d-14          [64, 256, 56, 56]             512
             ReLU-15          [64, 256, 56, 56]               0
       Bottleneck-16          [64, 256, 56, 56]               0
           Conv2d-17           [64, 64, 56, 56]          16,384
      BatchNorm2d-18           [64, 64, 56, 56]             128
             ReLU-19           [64, 64, 56, 56]               0
           Conv2d-20           [64, 64, 56, 56]          36,864
      BatchNorm2d-21           [64, 64, 56, 56]             128
             ReLU-22           [64, 64, 56, 56]               0
           Conv2d-23          [64, 256, 56, 56]          16,384
      BatchNorm2d-24          [64, 256, 56, 56]             512
             ReLU-25          [64, 256, 56, 56]               0
       Bottleneck-26          [64, 256, 56, 56]               0
           Conv2d-27           [64, 64, 56, 56]          16,384
      BatchNorm2d-28           [64, 64, 56, 56]             128
             ReLU-29           [64, 64, 56, 56]               0
           Conv2d-30           [64, 64, 56, 56]          36,864
      BatchNorm2d-31           [64, 64, 56, 56]             128
             ReLU-32           [64, 64, 56, 56]               0
           Conv2d-33          [64, 256, 56, 56]          16,384
      BatchNorm2d-34          [64, 256, 56, 56]             512
             ReLU-35          [64, 256, 56, 56]               0
       Bottleneck-36          [64, 256, 56, 56]               0
           Conv2d-37          [64, 128, 28, 28]          32,768
      BatchNorm2d-38          [64, 128, 28, 28]             256
             ReLU-39          [64, 128, 28, 28]               0
           Conv2d-40          [64, 128, 28, 28]         147,456
      BatchNorm2d-41          [64, 128, 28, 28]             256
             ReLU-42          [64, 128, 28, 28]               0
           Conv2d-43          [64, 512, 28, 28]          65,536
      BatchNorm2d-44          [64, 512, 28, 28]           1,024
           Conv2d-45          [64, 512, 28, 28]         131,072
      BatchNorm2d-46          [64, 512, 28, 28]           1,024
             ReLU-47          [64, 512, 28, 28]               0
       Bottleneck-48          [64, 512, 28, 28]               0
           Conv2d-49          [64, 128, 28, 28]          65,536
      BatchNorm2d-50          [64, 128, 28, 28]             256
             ReLU-51          [64, 128, 28, 28]               0
           Conv2d-52          [64, 128, 28, 28]         147,456
      BatchNorm2d-53          [64, 128, 28, 28]             256
             ReLU-54          [64, 128, 28, 28]               0
           Conv2d-55          [64, 512, 28, 28]          65,536
      BatchNorm2d-56          [64, 512, 28, 28]           1,024
             ReLU-57          [64, 512, 28, 28]               0
       Bottleneck-58          [64, 512, 28, 28]               0
           Conv2d-59          [64, 128, 28, 28]          65,536
      BatchNorm2d-60          [64, 128, 28, 28]             256
             ReLU-61          [64, 128, 28, 28]               0
           Conv2d-62          [64, 128, 28, 28]         147,456
      BatchNorm2d-63          [64, 128, 28, 28]             256
             ReLU-64          [64, 128, 28, 28]               0
           Conv2d-65          [64, 512, 28, 28]          65,536
      BatchNorm2d-66          [64, 512, 28, 28]           1,024
             ReLU-67          [64, 512, 28, 28]               0
       Bottleneck-68          [64, 512, 28, 28]               0
           Conv2d-69          [64, 128, 28, 28]          65,536
      BatchNorm2d-70          [64, 128, 28, 28]             256
             ReLU-71          [64, 128, 28, 28]               0
           Conv2d-72          [64, 128, 28, 28]         147,456
      BatchNorm2d-73          [64, 128, 28, 28]             256
             ReLU-74          [64, 128, 28, 28]               0
           Conv2d-75          [64, 512, 28, 28]          65,536
      BatchNorm2d-76          [64, 512, 28, 28]           1,024
             ReLU-77          [64, 512, 28, 28]               0
       Bottleneck-78          [64, 512, 28, 28]               0
           Conv2d-79          [64, 256, 14, 14]         131,072
      BatchNorm2d-80          [64, 256, 14, 14]             512
             ReLU-81          [64, 256, 14, 14]               0
           Conv2d-82          [64, 256, 14, 14]         589,824
      BatchNorm2d-83          [64, 256, 14, 14]             512
             ReLU-84          [64, 256, 14, 14]               0
           Conv2d-85         [64, 1024, 14, 14]         262,144
      BatchNorm2d-86         [64, 1024, 14, 14]           2,048
           Conv2d-87         [64, 1024, 14, 14]         524,288
      BatchNorm2d-88         [64, 1024, 14, 14]           2,048
             ReLU-89         [64, 1024, 14, 14]               0
       Bottleneck-90         [64, 1024, 14, 14]               0
           Conv2d-91          [64, 256, 14, 14]         262,144
      BatchNorm2d-92          [64, 256, 14, 14]             512
             ReLU-93          [64, 256, 14, 14]               0
           Conv2d-94          [64, 256, 14, 14]         589,824
      BatchNorm2d-95          [64, 256, 14, 14]             512
             ReLU-96          [64, 256, 14, 14]               0
           Conv2d-97         [64, 1024, 14, 14]         262,144
      BatchNorm2d-98         [64, 1024, 14, 14]           2,048
             ReLU-99         [64, 1024, 14, 14]               0
      Bottleneck-100         [64, 1024, 14, 14]               0
          Conv2d-101          [64, 256, 14, 14]         262,144
     BatchNorm2d-102          [64, 256, 14, 14]             512
            ReLU-103          [64, 256, 14, 14]               0
          Conv2d-104          [64, 256, 14, 14]         589,824
     BatchNorm2d-105          [64, 256, 14, 14]             512
            ReLU-106          [64, 256, 14, 14]               0
          Conv2d-107         [64, 1024, 14, 14]         262,144
     BatchNorm2d-108         [64, 1024, 14, 14]           2,048
            ReLU-109         [64, 1024, 14, 14]               0
      Bottleneck-110         [64, 1024, 14, 14]               0
          Conv2d-111          [64, 256, 14, 14]         262,144
     BatchNorm2d-112          [64, 256, 14, 14]             512
            ReLU-113          [64, 256, 14, 14]               0
          Conv2d-114          [64, 256, 14, 14]         589,824
     BatchNorm2d-115          [64, 256, 14, 14]             512
            ReLU-116          [64, 256, 14, 14]               0
          Conv2d-117         [64, 1024, 14, 14]         262,144
     BatchNorm2d-118         [64, 1024, 14, 14]           2,048
            ReLU-119         [64, 1024, 14, 14]               0
      Bottleneck-120         [64, 1024, 14, 14]               0
          Conv2d-121          [64, 256, 14, 14]         262,144
     BatchNorm2d-122          [64, 256, 14, 14]             512
            ReLU-123          [64, 256, 14, 14]               0
          Conv2d-124          [64, 256, 14, 14]         589,824
     BatchNorm2d-125          [64, 256, 14, 14]             512
            ReLU-126          [64, 256, 14, 14]               0
          Conv2d-127         [64, 1024, 14, 14]         262,144
     BatchNorm2d-128         [64, 1024, 14, 14]           2,048
            ReLU-129         [64, 1024, 14, 14]               0
      Bottleneck-130         [64, 1024, 14, 14]               0
          Conv2d-131          [64, 256, 14, 14]         262,144
     BatchNorm2d-132          [64, 256, 14, 14]             512
            ReLU-133          [64, 256, 14, 14]               0
          Conv2d-134          [64, 256, 14, 14]         589,824
     BatchNorm2d-135          [64, 256, 14, 14]             512
            ReLU-136          [64, 256, 14, 14]               0
          Conv2d-137         [64, 1024, 14, 14]         262,144
     BatchNorm2d-138         [64, 1024, 14, 14]           2,048
            ReLU-139         [64, 1024, 14, 14]               0
      Bottleneck-140         [64, 1024, 14, 14]               0
          Conv2d-141            [64, 512, 7, 7]         524,288
     BatchNorm2d-142            [64, 512, 7, 7]           1,024
            ReLU-143            [64, 512, 7, 7]               0
          Conv2d-144            [64, 512, 7, 7]       2,359,296
     BatchNorm2d-145            [64, 512, 7, 7]           1,024
            ReLU-146            [64, 512, 7, 7]               0
          Conv2d-147           [64, 2048, 7, 7]       1,048,576
     BatchNorm2d-148           [64, 2048, 7, 7]           4,096
          Conv2d-149           [64, 2048, 7, 7]       2,097,152
     BatchNorm2d-150           [64, 2048, 7, 7]           4,096
            ReLU-151           [64, 2048, 7, 7]               0
      Bottleneck-152           [64, 2048, 7, 7]               0
          Conv2d-153            [64, 512, 7, 7]       1,048,576
     BatchNorm2d-154            [64, 512, 7, 7]           1,024
            ReLU-155            [64, 512, 7, 7]               0
          Conv2d-156            [64, 512, 7, 7]       2,359,296
     BatchNorm2d-157            [64, 512, 7, 7]           1,024
            ReLU-158            [64, 512, 7, 7]               0
          Conv2d-159           [64, 2048, 7, 7]       1,048,576
     BatchNorm2d-160           [64, 2048, 7, 7]           4,096
            ReLU-161           [64, 2048, 7, 7]               0
      Bottleneck-162           [64, 2048, 7, 7]               0
          Conv2d-163            [64, 512, 7, 7]       1,048,576
     BatchNorm2d-164            [64, 512, 7, 7]           1,024
            ReLU-165            [64, 512, 7, 7]               0
          Conv2d-166            [64, 512, 7, 7]       2,359,296
     BatchNorm2d-167            [64, 512, 7, 7]           1,024
            ReLU-168            [64, 512, 7, 7]               0
          Conv2d-169           [64, 2048, 7, 7]       1,048,576
     BatchNorm2d-170           [64, 2048, 7, 7]           4,096
            ReLU-171           [64, 2048, 7, 7]               0
      Bottleneck-172           [64, 2048, 7, 7]               0
AdaptiveAvgPool2d-173           [64, 2048, 1, 1]               0
          Linear-174                 [64, 1000]       2,049,000
================================================================
Total params: 25,557,032
Trainable params: 25,557,032
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 36.75
Forward/backward pass size (MB): 15200.01
Params size (MB): 97.49
Estimated Total Size (MB): 15334.25
----------------------------------------------------------------

参考链接:

  • https://link.zhihu.com/?target=https%3A//arxiv.org/pdf/1512.03385.pdf

  • https://blog.csdn.net/m0_64799972/article/details/132753608

  • https://blog.csdn.net/m0_50127633/article/details/117200212

  • https://www.bilibili.com/video/BV1Bo4y1T7Lc/?spm_id_from=333.999.0.0&vd_source=c7e390079ff3e10b79e23fb333bea49d

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/286378.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

为什么python值得学习,python的应用领域。

文章目录 前言Web 应用开发自动化运维网络爬虫数据分析科学计算人工智能胶水语言Python技术资源分享1、Python所有方向的学习路线2、学习软件3、入门学习视频4、实战案例5、清华编程大佬出品《漫画看学Python》6、Python副业兼职与全职路线 前言 说起编程语言,Pyth…

【电商项目实战】购物车完善

🎉🎉欢迎来到我的CSDN主页!🎉🎉 🏅我是Java方文山,一个在CSDN分享笔记的博主。📚📚 🌟推荐给大家我的专栏《电商项目实战》。🎯🎯 &am…

ElasticSearch的DSL查询语法解析

Elasticsearch提供了基于ISON的DSL (Domain Specific Lanquage)来定义查询。 目录 一、常见查询类型 二、DSLQuery基本语法 三、全文检索查询 3.1 match查询:会对用户输入内容分词,常用于搜索框搜索 ,语法: 3.2 multi match…

基于矩阵乘的CUDA编程优化过程

背景:网上很多关于矩阵乘的编程优化思路,本着看理论分析万遍,不如实际代码写一遍的想法,大概过一下优化思路。 矩阵乘的定义如下,约定矩阵的形状及存储方式为: A[M, K], B[K, N], C[M, N]。 CPU篇 朴素实现方法 按照…

canvas绘制网格线示例

查看专栏目录 canvas示例教程100专栏,提供canvas的基础知识,高级动画,相关应用扩展等信息。canvas作为html的一部分,是图像图标地图可视化的一个重要的基础,学好了canvas,在其他的一些应用上将会起到非常重…

自动化测试:等待方式

在自动化测试中,等待是一个重要的技术,用于处理页面加载、元素定位、元素状态改变等延迟问题。 等待能够确保在条件满足后再进行后续操作,提高自动化测试的稳定性以及可靠性。 等待方式:显示等待、隐式等待、线程睡眠 1. 显式等…

【学习笔记】环论

子环环同态理想单位元(乘法单位元)环与子环的单位元无必然关系,即子环不一定有单位元,有也不一定和环的单位元相同 比如 Z 6 Z_6 Z6​有单位元1,其子环 ( 2 ) (2) (2)单位元为4;Z有单位元1,其子环2Z没有单位元若R有单位…

B站不赚钱、“芒果”赚钱难,视频“后浪”火拼跨年夜

又是一年跨年时。 各大视频平台跨年晚会展开火拼,今年谁是赢家? 作为视频“后浪”,芒果超媒(300413.SZ)、哔哩哔哩(09626.HK,下称“B站”)此前相继公布了2023年三季报,…

什么是缓存、为什么要用缓存、缓存分类、缓存测试、缓存更新、缓存设计考虑点、缓存测试点

一、缓存 缓存是一种将数据存储在高速缓存中的技术,它可以提高应用程序的性能和响应速度。 二、 为什么要用缓存 1. 高性能(主要目的) 查询耗时,但变化少,又有很多读请求情况下,可以将查询结果放到缓存中。减少对数据库的压力&…

2024/1/2作业

成果 代码 main .c #include "sqi.h" #include "si7006.h" unsigned int num[10] {0xFC, 0x60, 0xDA,0xF2,0x66,0xB6,0xBE,0XE0,0xFE,0xF6}; //unsigned int wei[5]{0x10,0x20,0x40,0x80,0xF0}; unsigned short hum; short tem; extern void printf(…

C++day5作业

全局变量,int monster 10000;定义英雄类hero,受保护的属性string name,int hp,int attck;公有的无参构造,有参构造,虚成员函数 void Atk(){blood-0;},法师类继承自英雄类,私有属性 …

HarmonyOS 组件通用属性之通用事件 文档参数讲解(按键事件)

最后 我们来看按键事件 按键事件是指 键盘 遥控器等按键设备交互的时候触发的事件 这边 我们还是以按钮为例 给大家演示一下 我们 event 参数的类型 变成了 KeyEvent 我们还是先看看 里面都有些什么东西 还是打开编辑器文档 组件通用信息 通用事件 下面的 按键事件 首先 这…

RocketMQ(Linux版本5.1.4)

1、停止之前的运行服务 [roottssvr1-c1 rocketmq-all-4.7.0-bin-release]# sh bin/mqshutdown namesrv No mqnamesrv running. [roottssvr1-c1 rocketmq-all-4.7.0-bin-release]# [roottssvr1-c1 rocketmq-all-4.7.0-bin-release]# [roottssvr1-c1 rocketmq-all-4.7.0-bin-r…

探索Java的魅力

从本篇文章开始,小编准备写一个关于java基础学习的系列文章,文章涉及到java语言中的基础组件、实现原理、使用场景、代码案例。看完下面一系列文章,希望能加深你对java的理解。 本篇文章作为本系列的第一篇文章,主要介绍一些java…

【实用工具】FFmpeg常用的命令

前言 FFmpeg是一个强大的多媒体处理工具,可以用于处理音频、视频和图像。 命令格式 ffmpeg {1} {2} -i {3} {4} {5} 上面命令中,五个部分的参数依次如下。 1.全局参数 2.输入文件参数 3.输入文件 4.输出文件参数 5.输出文件 常见命令行参数 -c&…

Power Apps 学习笔记 - IOrganizationService Interface

文章目录 1. IOrganization Interface1.1 基本介绍1.2 方法分析 2. Entity对象2.1 Constructor2.2 Properties2.3 Methods 3. 相关方法3.1 单行查询 Retrive3.2 多行查询 RetriveMultiple3.3 增加 Create3.4 删除 Delete3.5 修改 Update 4. 数据查询的不同实现方式4.1 QueryExp…

vite+Vue3学习笔记(3)——界面设计

1 Element-plus 这是一个基于Vue3的组件库,能够快速构建界面样式。 官网链接: https://element-plus.gitee.io/zh-CN/guide/design.html 1.1 基础组件 1.1.1 安装 项目中的终端输入: npm install --save element-plus 1.1.2 引用 1.1.2.1…

RAG LLM App开发实战

大型语言模型(LLM)无疑改变了我们与信息交互的方式。 然而,对于我们可以向他们提出的要求,它们也有相当多的限制。 LLM(例如 Llama-2-70b、gpt-4 等)仅了解他们接受过训练的信息,当我们要求他们…

Python爬虫---selenium基本使用(支持无界面浏览器PhantomJS和Chrome handless)

为什么使用selenium? 使用urllib.request.urlopen()模拟浏览器有时候获取不到数据,所以使用selenium (1) selenium是一个用于web应用程序测试的工具 (2) selenium 测试直接运行在浏览器中,就像真正的用户在操作一样 (3) 支持通过各种driver (FirfoxDri…

手机摄影学习

手机摄影学习 手机摄影前期知识1,成像基本原理2,什么是焦距3,快门(简称s)4,上面功能之间的相互影响5,焦点6,过爆、欠曝7,cmos(感光芯片)、测光、聚…