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

第J9周:Inception v3算法实战与解析(pytorch版)

>- **🍨 本文为[🔗365天深度学习训练营]中的学习记录博客**
>- **🍖 原作者:[K同学啊]**

📌本周任务:📌

  1. 了解并学习InceptionV3相对与InceptionV1有哪些改进的地方

  2. 使用Inception完成天气识别

🏡 我的环境:

  • 语言环境:Python3.8
  • 编译器:Jupyter Notebook
  • 深度学习环境:Pytorch
    • torch==2.3.1+cu118
    • torchvision==0.18.1+cu118

一、理论基础

Inception v3论文:Rethinking the Inception Architecture for Computer Vision

Inception v3由谷歌研究员Christian Szegedy等人在2015年的论文《Rethinking the Inception Architecture for Computer Vision》中提出。Inception v3是Inception网络系列的第三个版本,它在ImageNet图像识别竞赛中取得了优异成绩,尤其是在大规模图像识别任务中表现出色。

Inception v3的主要特点如下:

  1. 更深的网络结构:Inception v3比之前的Inception网络结构更深,包含了48层卷积层。这使得网络可以提取更多层次的特征,从而在图像识别任务上取得更好的效果。
  2. 使用Factorized Convolutions:Inception v3采用了Factorized Convolutions(分解卷积),将较大的卷积核分解为多个较小的卷积核。这种方法可以降低网络的参数数量,减少计算复杂度,同时保持良好的性能。
  3. 使用Batch Normalization:Inception v3在每个卷积层之后都添加了Batch Normalization(BN),这有助于网络的收敛和泛化能力。BN可以减少Internal Covariate Shift(内部协变量偏移)现象,加快训练速度,同时提高模型的鲁棒性。
  4. 辅助分类器:Inception v3引入了辅助分类器,可以在网络训练过程中提供额外的梯度信息,帮助网络更好地学习特征。辅助分类器位于网络的某个中间层,其输出会与主分类器的输出进行加权融合,从而得到最终的预测结果。
  5. 基于RMSProp的优化器:Inception v3使用了RMSProp优化器进行训练。相比于传统的随机梯度下降(SGD)方法,RMSProp可以自适应地调整学习率,使得训练过程更加稳定,收敛速度更快。

Inception v3在图像分类、物体检测和图像分割等计算机视觉任务中均取得了显著的效果。然而,由于其较大的网络结构和计算复杂度,Inception v3在实际应用中可能需要较高的硬件要求。

相对于Inception v1的Inception Module结构,Inception v3中做出了如下改动:

●将 5×5 的卷积分解为两个 3×3 的卷积运算以提升计算速度。尽管这有点违反直觉,但一个 5×5 的卷积在计算成本上是一个 3×3 卷积的 2.78 倍。所以叠加两个 3×3 卷积实际上在性能上会有所提升,如下图所示:

●此外,作者将 n×n 的卷积核尺寸分解为 1×n 和 n×1 两个卷积。例如,一个 3×3 的卷积等价于首先执行一个 1×3 的卷积再执行一个 3×1 的卷积。他们还发现这种方法在成本上要比单个 3×3 的卷积降低 33%,这一结构如下图所示:

此处如果 n=3,则与上一张图像一致。最左侧的 5x5 卷积可被表示为两个 3x3 卷积,它们又可以被表示为 1x3 和 3x1 卷积。
模块中的滤波器组被扩展(即变得更宽而不是更深),以解决表征性瓶颈。如果该模块没有被拓展宽度,而是变得更深,那么维度会过多减少,造成信息损失。如下图所示:

最后实现的inception v3网络是上图结构图如下:

二、前期准备

1. 设置GPU

如果设备上支持GPU就使用GPU,否则使用CPU

import warnings
warnings.filterwarnings("ignore") #忽略警告信息

import torch
device=torch.device("cuda" if torch.cuda.is_available() else "cpu")
device

运行结果:

device(type='cuda')

2. 导入数据

import pathlib
data_dir=r'D:\THE MNIST DATABASE\weather_photos'
data_dir=pathlib.Path(data_dir)

img_count=len(list(data_dir.glob('*/*')))
print("图片总数为:",img_count)

运行结果:

图片总数为: 1125

3. 查看数据集分类

data_paths=list(data_dir.glob('*'))
classNames=[str(path).split('\\')[3] for path in data_paths]
classNames

运行结果:

['cloudy', 'rain', 'shine', 'sunrise']

4. 随机查看图片

随机抽取数据集中的10张图片进行查看

import PIL,random
import matplotlib.pyplot as plt
from PIL import Image
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号

data_paths2=list(data_dir.glob('*/*'))
plt.figure(figsize=(20,8))
#plt.suptitle("OreoCC的案例",fontsize=15)
for i in range(10):
    plt.subplot(2,5,i+1)
    plt.axis("off")
    image=random.choice(data_paths2) #随机选择一个图片
    plt.title(image.parts[-2],fontsize=20) #通过glob对象取出他的文件夹名称,即分类名
    plt.imshow(Image.open(str(image))) #显示图片

运行结果:

5. 图片预处理

import torchvision.transforms as transforms
from torchvision import transforms,datasets

train_transforms=transforms.Compose([
    transforms.Resize([224,224]), #将图片统一尺寸
    transforms.RandomHorizontalFlip(), #将图片随机水平翻转
    transforms.RandomRotation(0.2), #将图片按照0.2的弧度值随机旋转
    transforms.ToTensor(), #将图片转换为tensor
    transforms.Normalize(  #标准化处理->转换为正态分布,使模型更容易收敛
        mean=[0.485,0.456,0.406],
        std=[0.229,0.224,0.225]
    )
])

total_data=datasets.ImageFolder(
    r'D:\THE MNIST DATABASE\weather_photos',
    transform=train_transforms
)
total_data

运行结果:

Dataset ImageFolder
    Number of datapoints: 1125
    Root location: D:\THE MNIST DATABASE\weather_photos
    StandardTransform
Transform: Compose(
               Resize(size=[224, 224], interpolation=bilinear, max_size=None, antialias=True)
               RandomHorizontalFlip(p=0.5)
               RandomRotation(degrees=[-0.2, 0.2], interpolation=nearest, expand=False, fill=0)
               ToTensor()
               Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
           )

将数据集分类情况进行映射输出:

total_data.class_to_idx

运行结果:

{'cloudy': 0, 'rain': 1, 'shine': 2, 'sunrise': 3}

6. 划分数据集

train_size=int(0.8*len(total_data))
test_size=len(total_data)-train_size

train_dataset,test_dataset=torch.utils.data.random_split(
    total_data,[train_size,test_size]
)
train_dataset,test_dataset

运行结果:

(<torch.utils.data.dataset.Subset at 0x1f39bf80a90>,
 <torch.utils.data.dataset.Subset at 0x1f3bc462210>)

查看训练集和测试集的数据数量:

train_size,test_size

运行结果:

(900, 225)

7. 加载数据集

batch_size=8
train_dl=torch.utils.data.DataLoader(
    train_dataset,
    batch_size=batch_size,
    shuffle=True,
    num_workers=1
)
test_dl=torch.utils.data.DataLoader(
    test_dataset,
    batch_size=batch_size,
    shuffle=True,
    num_workers=1
)

查看测试集的情况:

for x,y in train_dl:
    print("Shape of x [N,C,H,W]:",x.shape)
    print("Shape of y:",y.shape,y.dtype)
    break

运行结果:

Shape of x [N,C,H,W]: torch.Size([8, 3, 224, 224])
Shape of y: torch.Size([8]) torch.int64

三、手动搭建网络模型

1. BasicConv2d模块

import torch.nn as nn
import torch.nn.functional as F

class BasicConv2d(nn.Module):
    def __init__(self,in_channels,out_channels,**kwargs):
        super(BasicConv2d,self).__init__()
        
        self.conv=nn.Conv2d(in_channels,out_channels,bias=False,**kwargs)
        self.bn=nn.BatchNorm2d(out_channels,eps=0.001)
        self.relu=nn.ReLU(inplace=True)
        
    def forward(self,x):
        x=self.conv(x)
        x=self.bn(x)
        x=self.relu(x)
        return x

2. Inception-A

class InceptionA(nn.Module):
    def __init__(self,in_channels,pool_features):
        super(InceptionA,self).__init__()
        
        self.branch1x1=BasicConv2d(in_channels,64,kernel_size=1)
        
        self.branch5x5_1=BasicConv2d(in_channels,48,kernel_size=1)
        self.branch5x5_2=BasicConv2d(48,64,kernel_size=5,padding=2)
        
        self.branch3x3dbl_1=BasicConv2d(in_channels,64,kernel_size=1)
        self.branch3x3dbl_2=BasicConv2d(64,96,kernel_size=3,padding=1)
        self.branch3x3dbl_3=BasicConv2d(96,96,kernel_size=3,padding=1)
        
        self.branch_pool=BasicConv2d(in_channels,pool_features,kernel_size=1)
        
    def forward(self,x):
        branch1x1=self.branch1x1(x)
        
        branch5x5=self.branch5x5_1(x)
        branch5x5=self.branch5x5_2(branch5x5)
        
        branch3x3dbl=self.branch3x3dbl_1(x)
        branch3x3dbl=self.branch3x3dbl_2(branch3x3dbl)
        branch3x3dbl=self.branch3x3dbl_3(branch3x3dbl)
        
        branch_pool=F.avg_pool2d(x,kernel_size=3,stride=1,padding=1)
        branch_pool=self.branch_pool(branch_pool)
        
        outputs=[branch1x1,branch5x5,branch3x3dbl,branch_pool]
        return torch.cat(outputs,1)

InceptionA模块包含四个分支,每个分支使用不同的卷积核大小和参数。其中branch1x1、branch5x5_2、branch3x3dbl_3使用较小的卷积核,可以减少参数数量和计算量,提高网络效率。branch_pool使用平均池化的方式进行特征提取和降维。最后,将四个分支的结果在通道维度上进行拼接,输出InceptionA的结果。 

3. Inception-B

class InceptionB(nn.Module):
    def __init__(self,in_channels,channels_7x7):
        super(InceptionB,self).__init__()
        
        self.branch1x1=BasicConv2d(in_channels,192,kernel_size=1)
        
        c7=channels_7x7
        self.branch7x7_1=BasicConv2d(in_channels,c7,kernel_size=1)
        self.branch7x7_2=BasicConv2d(c7,c7,kernel_size=(1,7),padding=(0,3))
        self.branch7x7_3=BasicConv2d(c7,192,kernel_size=(7,1),padding=(3,0))
        
        self.branch7x7dbl_1=BasicConv2d(in_channels,c7,kernel_size=1)
        self.branch7x7dbl_2=BasicConv2d(c7,c7,kernel_size=(7,1),padding=(3,0))
        self.branch7x7dbl_3=BasicConv2d(c7,c7,kernel_size=(1,7),padding=(0,3))
        self.branch7x7dbl_4=BasicConv2d(c7,c7,kernel_size=(7,1),padding=(3,0))
        self.branch7x7dbl_5=BasicConv2d(c7,192,kernel_size=(1,7),padding=(0,3))
        
        self.branch_pool=BasicConv2d(in_channels,192,kernel_size=1)
        
    def forward(self,x):
        branch1x1=self.branch1x1(x)
        
        branch7x7=self.branch7x7_1(x)
        branch7x7=self.branch7x7_2(branch7x7)
        branch7x7=self.branch7x7_3(branch7x7)
        
        branch7x7dbl=self.branch7x7dbl_1(x)
        branch7x7dbl=self.branch7x7dbl_2(branch7x7dbl)
        branch7x7dbl=self.branch7x7dbl_3(branch7x7dbl)
        branch7x7dbl=self.branch7x7dbl_4(branch7x7dbl)
        branch7x7dbl=self.branch7x7dbl_5(branch7x7dbl)
        
        branch_pool=F.avg_pool2d(x,kernel_size=3,stride=1,padding=1)
        branch_pool=self.branch_pool(branch_pool)
        
        outputs=[branch1x1,branch7x7,branch7x7dbl,branch_pool]
        return torch.cat(outputs,1)

InceptionB模块包含四个分支,其中branch7x7_2和branch7x7_3使用不同大小的卷积核进行多次卷积,可以提高特征的表达能力。branch7x7dbl_2、branch7x7dbl_3、branch7x7dbl_4、branch7x7dbl_5也类似地使用多个不同大小的卷积核进行多次卷积,提高了特征的表达能力,并且较好地保留了空间尺寸。branch_pool仍然使用平均池化的方式进行特征提取和降维。最后,将四个分支的结果在通道维度上进行拼接,输出InceptionB的结果。

4. Inception-C

class InceptionC(nn.Module):
    def __init__(self,in_channels):
        super(InceptionC,self).__init__()
        
        self.branch1x1=BasicConv2d(in_channels,320,kernel_size=1)
        
        self.branch3x3_1=BasicConv2d(in_channels,384,kernel_size=1)
        self.branch3x3_2a=BasicConv2d(384,384,kernel_size=(1,3),padding=(0,1))
        self.branch3x3_2b=BasicConv2d(384,384,kernel_size=(3,1),padding=(1,0))
        
        self.branch3x3dbl_1=BasicConv2d(in_channels,448,kernel_size=1)
        self.branch3x3dbl_2=BasicConv2d(448,384,kernel_size=3,padding=1)
        self.branch3x3dbl_3a=BasicConv2d(384,384,kernel_size=(1,3),padding=(0,1))
        self.branch3x3dbl_3b=BasicConv2d(384,384,kernel_size=(3,1),padding=(1,0))
        
        self.branch_pool=BasicConv2d(in_channels,192,kernel_size=1)
        
    def forward(self,x):
        branch1x1=self.branch1x1(x)
        
        branch3x3=self.branch3x3_1(x)
        branch3x3=[self.branch3x3_2a(branch3x3),
                   self.branch3x3_2b(branch3x3),]
        branch3x3=torch.cat(branch3x3,1)
        
        branch3x3dbl=self.branch3x3dbl_1(x)
        branch3x3dbl=self.branch3x3dbl_2(branch3x3dbl)
        branch3x3dbl=[self.branch3x3dbl_3a(branch3x3dbl),
                      self.branch3x3dbl_3b(branch3x3dbl),]
        branch3x3dbl=torch.cat(branch3x3dbl,1)
        
        branch_pool=F.avg_pool2d(x,kernel_size=3,stride=1,padding=1)
        branch_pool=self.branch_pool(branch_pool)
        
        outputs=[branch1x1,branch3x3,branch3x3dbl,branch_pool]
        return torch.cat(outputs,1)

InceptionC模块同样包含三个分支,其中branch3x3_2b和branch3x3dbl_2使用大小为3x3的卷积核,并且padding=1,dilation=1,可以一定程度上扩大感受野。这两个分支多次卷积,可以提高特征的表达能力。branch_pool仍然使用平均池化的方式进行特征提取和降维。最后,将三个分支的结果在通道维度上进行拼接,输出InceptionB的结果。

5、Reduction-A

class ReductionA(nn.Module):
    def __init__(self,in_channels):
        super(ReductionA,self).__init__()
        
        self.branch3x3=BasicConv2d(in_channels,384,kernel_size=3,stride=2)
        
        self.branch3x3dbl_1=BasicConv2d(in_channels,64,kernel_size=1)
        self.branch3x3dbl_2=BasicConv2d(64,96,kernel_size=3,padding=1)
        self.branch3x3dbl_3=BasicConv2d(96,96,kernel_size=3,stride=2)
        
    def forward(self,x):
        branch3x3=self.branch3x3(x)
        
        branch3x3dbl=self.branch3x3dbl_1(x)
        branch3x3dbl=self.branch3x3dbl_2(branch3x3dbl)
        branch3x3dbl=self.branch3x3dbl_3(branch3x3dbl)
        
        branch_pool=F.max_pool2d(x,kernel_size=3,stride=2)
        
        outputs=[branch3x3,branch3x3dbl,branch_pool]
        return torch.cat(outputs,1)

ReductionA模块包含三个分支,其中branch3x3_1使用3x3的卷积核进行卷积,通过stride=2来降维,同时提取特征。branch3x3_2a、branch3x3_2b、branch3x3_2c使用多层卷积对特征进行提取和表达,同时通过stride=2来降维和压缩特征,减少计算量。branch_pool使用max pooling的方式进行特征提取和降维,与其他模块类似。最后,将三个分支的结果在通道维度上进行拼接,输出ReductionA的结果。

6、Reduction-B

class ReductionB(nn.Module):
    def __init__(self,in_channels):
        super(ReductionB,self).__init__()
        
        self.branch3x3_1=BasicConv2d(in_channels,192,kernel_size=1)
        self.branch3x3_2=BasicConv2d(192,320,kernel_size=3,stride=2)
        
        self.branch7x7x3_1=BasicConv2d(in_channels,192,kernel_size=1)
        self.branch7x7x3_2=BasicConv2d(192,192,kernel_size=(1,7),padding=(0,3))
        self.branch7x7x3_3=BasicConv2d(192,192,kernel_size=(7,1),padding=(3,0))
        self.branch7x7x3_4=BasicConv2d(192,192,kernel_size=3,stride=2)
        
    def forward(self,x):
        branch3x3=self.branch3x3_1(x)
        branch3x3=self.branch3x3_2(branch3x3)
        
        branch7x7x3=self.branch7x7x3_1(x)
        branch7x7x3=self.branch7x7x3_2(branch7x7x3)
        branch7x7x3=self.branch7x7x3_3(branch7x7x3)
        branch7x7x3=self.branch7x7x3_4(branch7x7x3)
        
        branch_pool=F.max_pool2d(x,kernel_size=3,stride=2)
        outputs=[branch3x3,branch7x7x3,branch_pool]
        return torch.cat(outputs,1)

 7、辅助分支

class InceptionAux(nn.Module):   
    def __init__(self,in_channels,num_classes):
        super(InceptionAux,self).__init__()
        
        self.conv0=BasicConv2d(in_channels,128,kernel_size=1)
        self.conv1=BasicConv2d(128,768,kernel_size=5)
        self.conv1.stddev=0.01
        self.fc=nn.Linear(768,num_classes)
        self.fc.stddev=0.001
        
    def forward(self,x):
        #17x17x768
        x=F.avg_pool2d(x,kernel_size=5,stride=3)
        # 5x5x768
        x=self.conv0(x)
        # 5x5x128
        x=self.conv1(x)
        # 1x1x768
        x=x.view(x.size(0),-1)
        # 768
        x=self.fc(x)
        # 1000
        return x

8、InceptionV3实现

class InceptionV3(nn.Module):
    def __init__(self,num_classes=1000,aux_logits=False,transform_input=False):
        super(InceptionV3,self).__init__()
        
        self.aux_logits=aux_logits
        self.transform_input=transform_input
        self.Conv2d_1a_3x3=BasicConv2d(3,32,kernel_size=3,stride=2)
        self.Conv2d_2a_3x3=BasicConv2d(32,32,kernel_size=3)
        self.Conv2d_2b_3x3=BasicConv2d(32,64,kernel_size=3,padding=1)
        self.Conv2d_3b_1x1=BasicConv2d(64,80,kernel_size=1)
        self.Conv2d_4a_3x3=BasicConv2d(80,192,kernel_size=3)
        self.Mixed_5b=InceptionA(192,pool_features=32)
        self.Mixed_5c=InceptionA(256,pool_features=64)
        self.Mixed_5d=InceptionA(288,pool_features=64)
        self.Mixed_6a=ReductionA(288)
        self.Mixed_6b=InceptionB(768,channels_7x7=128)
        self.Mixed_6c=InceptionB(768,channels_7x7=160)
        self.Mixed_6d=InceptionB(768,channels_7x7=160)
        self.Mixed_6e=InceptionB(768,channels_7x7=192)
        if aux_logits:
            self.AuxLogits=InceptionAux(768,num_classes)
        self.Mixed_7a=ReductionB(768)
        self.Mixed_7b=InceptionC(1280)
        self.Mixed_7c=InceptionC(2048)
        self.fc=nn.Linear(2048,num_classes)
        
    def forward(self,x):
        if self.transform_input:
            x=x.clone()
            x[:,0]=x[:,0]*(0.229/0.5)+(0.485-0.5)/0.5
            x[:,1]=x[:,1]*(0.224/0.5)+(0.456-0.5)/0.5
            x[:,2]=x[:,2]*(0.225/0.5)+(0.406-0.5)/0.5
        # 229x229x3
        x=self.Conv2d_1a_3x3(x)
        # 149x149x32
        x=self.Conv2d_2a_3x3(x)
        # 147x147x32
        x=self.Conv2d_2b_3x3(x)
        # 147x147x64
        x=F.max_pool2d(x,kernel_size=3,stride=2)
        # 73x73x64
        x=self.Conv2d_3b_1x1(x)
        # 73x73x80
        x=self.Conv2d_4a_3x3(x)
        # 71x71x192
        x=F.max_pool2d(x,kernel_size=3,stride=2)
        # 35x35x192
        x=self.Mixed_5b(x)
        # 35x35x256
        x=self.Mixed_5c(x)
        # 35x35x288
        x=self.Mixed_5d(x)
        # 35x35x288
        x=self.Mixed_6a(x)
        # 17x17x768
        x=self.Mixed_6b(x)
        # 17x17x768
        x=self.Mixed_6c(x)
        # 17x17x768
        x=self.Mixed_6d(x)
        # 17x17x768
        x=self.Mixed_6e(x)
        # 17x17x768
        if self.training and self.aux_logits:
            aux=self.AuxLogits(x)
        # 17x17x768
        x=self.Mixed_7a(x)
        # 8x8x1280
        x=self.Mixed_7b(x)
        # 8x8x2048
        x=self.Mixed_7c(x)
        # 8x8x2048
        x=F.avg_pool2d(x,kernel_size=5)
        # 1x1x2048
        x=F.dropout(x,training=self.training)
        # 1x1x2048
        x=x.view(x.size(0),-1)
        # 2048
        x=self.fc(x)
        # 1000(num_classes)
        if self.training and self.aux_logits:
            return x,aux
        return x
model=InceptionV3(num_classes=4).to(device)
model

运行结果:

InceptionV3(
  (Conv2d_1a_3x3): BasicConv2d(
    (conv): Conv2d(3, 32, kernel_size=(3, 3), stride=(2, 2), bias=False)
    (bn): BatchNorm2d(32, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
  )
  (Conv2d_2a_3x3): BasicConv2d(
    (conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), bias=False)
    (bn): BatchNorm2d(32, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
  )
  (Conv2d_2b_3x3): BasicConv2d(
    (conv): Conv2d(32, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn): BatchNorm2d(64, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
  )
  (Conv2d_3b_1x1): BasicConv2d(
    (conv): Conv2d(64, 80, kernel_size=(1, 1), stride=(1, 1), bias=False)
    (bn): BatchNorm2d(80, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
  )
  (Conv2d_4a_3x3): BasicConv2d(
    (conv): Conv2d(80, 192, kernel_size=(3, 3), stride=(1, 1), bias=False)
    (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
  )
  (Mixed_5b): InceptionA(
    (branch1x1): BasicConv2d(
      (conv): Conv2d(192, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(64, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch5x5_1): BasicConv2d(
      (conv): Conv2d(192, 48, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(48, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch5x5_2): BasicConv2d(
      (conv): Conv2d(48, 64, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), bias=False)
      (bn): BatchNorm2d(64, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_1): BasicConv2d(
      (conv): Conv2d(192, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(64, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_2): BasicConv2d(
      (conv): Conv2d(64, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn): BatchNorm2d(96, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_3): BasicConv2d(
      (conv): Conv2d(96, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn): BatchNorm2d(96, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch_pool): BasicConv2d(
      (conv): Conv2d(192, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(32, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
  )
  (Mixed_5c): InceptionA(
    (branch1x1): BasicConv2d(
      (conv): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(64, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch5x5_1): BasicConv2d(
      (conv): Conv2d(256, 48, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(48, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch5x5_2): BasicConv2d(
      (conv): Conv2d(48, 64, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), bias=False)
      (bn): BatchNorm2d(64, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_1): BasicConv2d(
      (conv): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(64, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_2): BasicConv2d(
      (conv): Conv2d(64, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn): BatchNorm2d(96, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_3): BasicConv2d(
      (conv): Conv2d(96, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn): BatchNorm2d(96, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch_pool): BasicConv2d(
      (conv): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(64, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
  )
  (Mixed_5d): InceptionA(
    (branch1x1): BasicConv2d(
      (conv): Conv2d(288, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(64, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch5x5_1): BasicConv2d(
      (conv): Conv2d(288, 48, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(48, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch5x5_2): BasicConv2d(
      (conv): Conv2d(48, 64, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), bias=False)
      (bn): BatchNorm2d(64, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_1): BasicConv2d(
      (conv): Conv2d(288, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(64, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_2): BasicConv2d(
      (conv): Conv2d(64, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn): BatchNorm2d(96, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_3): BasicConv2d(
      (conv): Conv2d(96, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn): BatchNorm2d(96, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch_pool): BasicConv2d(
      (conv): Conv2d(288, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(64, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
  )
  (Mixed_6a): ReductionA(
    (branch3x3): BasicConv2d(
      (conv): Conv2d(288, 384, kernel_size=(3, 3), stride=(2, 2), bias=False)
      (bn): BatchNorm2d(384, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_1): BasicConv2d(
      (conv): Conv2d(288, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(64, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_2): BasicConv2d(
      (conv): Conv2d(64, 96, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn): BatchNorm2d(96, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_3): BasicConv2d(
      (conv): Conv2d(96, 96, kernel_size=(3, 3), stride=(2, 2), bias=False)
      (bn): BatchNorm2d(96, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
  )
  (Mixed_6b): InceptionB(
    (branch1x1): BasicConv2d(
      (conv): Conv2d(768, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7_1): BasicConv2d(
      (conv): Conv2d(768, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(128, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7_2): BasicConv2d(
      (conv): Conv2d(128, 128, kernel_size=(1, 7), stride=(1, 1), padding=(0, 3), bias=False)
      (bn): BatchNorm2d(128, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7_3): BasicConv2d(
      (conv): Conv2d(128, 192, kernel_size=(7, 1), stride=(1, 1), padding=(3, 0), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_1): BasicConv2d(
      (conv): Conv2d(768, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(128, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_2): BasicConv2d(
      (conv): Conv2d(128, 128, kernel_size=(7, 1), stride=(1, 1), padding=(3, 0), bias=False)
      (bn): BatchNorm2d(128, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_3): BasicConv2d(
      (conv): Conv2d(128, 128, kernel_size=(1, 7), stride=(1, 1), padding=(0, 3), bias=False)
      (bn): BatchNorm2d(128, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_4): BasicConv2d(
      (conv): Conv2d(128, 128, kernel_size=(7, 1), stride=(1, 1), padding=(3, 0), bias=False)
      (bn): BatchNorm2d(128, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_5): BasicConv2d(
      (conv): Conv2d(128, 192, kernel_size=(1, 7), stride=(1, 1), padding=(0, 3), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch_pool): BasicConv2d(
      (conv): Conv2d(768, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
  )
  (Mixed_6c): InceptionB(
    (branch1x1): BasicConv2d(
      (conv): Conv2d(768, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7_1): BasicConv2d(
      (conv): Conv2d(768, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(160, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7_2): BasicConv2d(
      (conv): Conv2d(160, 160, kernel_size=(1, 7), stride=(1, 1), padding=(0, 3), bias=False)
      (bn): BatchNorm2d(160, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7_3): BasicConv2d(
      (conv): Conv2d(160, 192, kernel_size=(7, 1), stride=(1, 1), padding=(3, 0), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_1): BasicConv2d(
      (conv): Conv2d(768, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(160, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_2): BasicConv2d(
      (conv): Conv2d(160, 160, kernel_size=(7, 1), stride=(1, 1), padding=(3, 0), bias=False)
      (bn): BatchNorm2d(160, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_3): BasicConv2d(
      (conv): Conv2d(160, 160, kernel_size=(1, 7), stride=(1, 1), padding=(0, 3), bias=False)
      (bn): BatchNorm2d(160, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_4): BasicConv2d(
      (conv): Conv2d(160, 160, kernel_size=(7, 1), stride=(1, 1), padding=(3, 0), bias=False)
      (bn): BatchNorm2d(160, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_5): BasicConv2d(
      (conv): Conv2d(160, 192, kernel_size=(1, 7), stride=(1, 1), padding=(0, 3), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch_pool): BasicConv2d(
      (conv): Conv2d(768, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
  )
  (Mixed_6d): InceptionB(
    (branch1x1): BasicConv2d(
      (conv): Conv2d(768, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7_1): BasicConv2d(
      (conv): Conv2d(768, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(160, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7_2): BasicConv2d(
      (conv): Conv2d(160, 160, kernel_size=(1, 7), stride=(1, 1), padding=(0, 3), bias=False)
      (bn): BatchNorm2d(160, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7_3): BasicConv2d(
      (conv): Conv2d(160, 192, kernel_size=(7, 1), stride=(1, 1), padding=(3, 0), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_1): BasicConv2d(
      (conv): Conv2d(768, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(160, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_2): BasicConv2d(
      (conv): Conv2d(160, 160, kernel_size=(7, 1), stride=(1, 1), padding=(3, 0), bias=False)
      (bn): BatchNorm2d(160, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_3): BasicConv2d(
      (conv): Conv2d(160, 160, kernel_size=(1, 7), stride=(1, 1), padding=(0, 3), bias=False)
      (bn): BatchNorm2d(160, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_4): BasicConv2d(
      (conv): Conv2d(160, 160, kernel_size=(7, 1), stride=(1, 1), padding=(3, 0), bias=False)
      (bn): BatchNorm2d(160, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_5): BasicConv2d(
      (conv): Conv2d(160, 192, kernel_size=(1, 7), stride=(1, 1), padding=(0, 3), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch_pool): BasicConv2d(
      (conv): Conv2d(768, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
  )
  (Mixed_6e): InceptionB(
    (branch1x1): BasicConv2d(
      (conv): Conv2d(768, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7_1): BasicConv2d(
      (conv): Conv2d(768, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7_2): BasicConv2d(
      (conv): Conv2d(192, 192, kernel_size=(1, 7), stride=(1, 1), padding=(0, 3), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7_3): BasicConv2d(
      (conv): Conv2d(192, 192, kernel_size=(7, 1), stride=(1, 1), padding=(3, 0), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_1): BasicConv2d(
      (conv): Conv2d(768, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_2): BasicConv2d(
      (conv): Conv2d(192, 192, kernel_size=(7, 1), stride=(1, 1), padding=(3, 0), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_3): BasicConv2d(
      (conv): Conv2d(192, 192, kernel_size=(1, 7), stride=(1, 1), padding=(0, 3), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_4): BasicConv2d(
      (conv): Conv2d(192, 192, kernel_size=(7, 1), stride=(1, 1), padding=(3, 0), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7dbl_5): BasicConv2d(
      (conv): Conv2d(192, 192, kernel_size=(1, 7), stride=(1, 1), padding=(0, 3), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch_pool): BasicConv2d(
      (conv): Conv2d(768, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
  )
  (Mixed_7a): ReductionB(
    (branch3x3_1): BasicConv2d(
      (conv): Conv2d(768, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3_2): BasicConv2d(
      (conv): Conv2d(192, 320, kernel_size=(3, 3), stride=(2, 2), bias=False)
      (bn): BatchNorm2d(320, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7x3_1): BasicConv2d(
      (conv): Conv2d(768, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7x3_2): BasicConv2d(
      (conv): Conv2d(192, 192, kernel_size=(1, 7), stride=(1, 1), padding=(0, 3), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7x3_3): BasicConv2d(
      (conv): Conv2d(192, 192, kernel_size=(7, 1), stride=(1, 1), padding=(3, 0), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch7x7x3_4): BasicConv2d(
      (conv): Conv2d(192, 192, kernel_size=(3, 3), stride=(2, 2), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
  )
  (Mixed_7b): InceptionC(
    (branch1x1): BasicConv2d(
      (conv): Conv2d(1280, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(320, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3_1): BasicConv2d(
      (conv): Conv2d(1280, 384, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(384, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3_2a): BasicConv2d(
      (conv): Conv2d(384, 384, kernel_size=(1, 3), stride=(1, 1), padding=(0, 1), bias=False)
      (bn): BatchNorm2d(384, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3_2b): BasicConv2d(
      (conv): Conv2d(384, 384, kernel_size=(3, 1), stride=(1, 1), padding=(1, 0), bias=False)
      (bn): BatchNorm2d(384, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_1): BasicConv2d(
      (conv): Conv2d(1280, 448, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(448, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_2): BasicConv2d(
      (conv): Conv2d(448, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn): BatchNorm2d(384, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_3a): BasicConv2d(
      (conv): Conv2d(384, 384, kernel_size=(1, 3), stride=(1, 1), padding=(0, 1), bias=False)
      (bn): BatchNorm2d(384, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_3b): BasicConv2d(
      (conv): Conv2d(384, 384, kernel_size=(3, 1), stride=(1, 1), padding=(1, 0), bias=False)
      (bn): BatchNorm2d(384, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch_pool): BasicConv2d(
      (conv): Conv2d(1280, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
  )
  (Mixed_7c): InceptionC(
    (branch1x1): BasicConv2d(
      (conv): Conv2d(2048, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(320, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3_1): BasicConv2d(
      (conv): Conv2d(2048, 384, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(384, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3_2a): BasicConv2d(
      (conv): Conv2d(384, 384, kernel_size=(1, 3), stride=(1, 1), padding=(0, 1), bias=False)
      (bn): BatchNorm2d(384, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3_2b): BasicConv2d(
      (conv): Conv2d(384, 384, kernel_size=(3, 1), stride=(1, 1), padding=(1, 0), bias=False)
      (bn): BatchNorm2d(384, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_1): BasicConv2d(
      (conv): Conv2d(2048, 448, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(448, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_2): BasicConv2d(
      (conv): Conv2d(448, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn): BatchNorm2d(384, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_3a): BasicConv2d(
      (conv): Conv2d(384, 384, kernel_size=(1, 3), stride=(1, 1), padding=(0, 1), bias=False)
      (bn): BatchNorm2d(384, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch3x3dbl_3b): BasicConv2d(
      (conv): Conv2d(384, 384, kernel_size=(3, 1), stride=(1, 1), padding=(1, 0), bias=False)
      (bn): BatchNorm2d(384, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
    (branch_pool): BasicConv2d(
      (conv): Conv2d(2048, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
      (bn): BatchNorm2d(192, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
      (relu): ReLU(inplace=True)
    )
  )
  (fc): Linear(in_features=2048, out_features=4, bias=True)
)

9. 查看模型详情

import torchsummary as summary
summary.summary(model,(3,299,299))

运行结果:

----------------------------------------------------------------
        Layer (type)               Output Shape         Param #
================================================================
            Conv2d-1         [-1, 32, 149, 149]             864
       BatchNorm2d-2         [-1, 32, 149, 149]              64
              ReLU-3         [-1, 32, 149, 149]               0
       BasicConv2d-4         [-1, 32, 149, 149]               0
            Conv2d-5         [-1, 32, 147, 147]           9,216
       BatchNorm2d-6         [-1, 32, 147, 147]              64
              ReLU-7         [-1, 32, 147, 147]               0
       BasicConv2d-8         [-1, 32, 147, 147]               0
            Conv2d-9         [-1, 64, 147, 147]          18,432
      BatchNorm2d-10         [-1, 64, 147, 147]             128
             ReLU-11         [-1, 64, 147, 147]               0
      BasicConv2d-12         [-1, 64, 147, 147]               0
           Conv2d-13           [-1, 80, 73, 73]           5,120
      BatchNorm2d-14           [-1, 80, 73, 73]             160
             ReLU-15           [-1, 80, 73, 73]               0
      BasicConv2d-16           [-1, 80, 73, 73]               0
           Conv2d-17          [-1, 192, 71, 71]         138,240
      BatchNorm2d-18          [-1, 192, 71, 71]             384
             ReLU-19          [-1, 192, 71, 71]               0
      BasicConv2d-20          [-1, 192, 71, 71]               0
           Conv2d-21           [-1, 64, 35, 35]          12,288
      BatchNorm2d-22           [-1, 64, 35, 35]             128
             ReLU-23           [-1, 64, 35, 35]               0
      BasicConv2d-24           [-1, 64, 35, 35]               0
           Conv2d-25           [-1, 48, 35, 35]           9,216
      BatchNorm2d-26           [-1, 48, 35, 35]              96
             ReLU-27           [-1, 48, 35, 35]               0
      BasicConv2d-28           [-1, 48, 35, 35]               0
           Conv2d-29           [-1, 64, 35, 35]          76,800
      BatchNorm2d-30           [-1, 64, 35, 35]             128
             ReLU-31           [-1, 64, 35, 35]               0
      BasicConv2d-32           [-1, 64, 35, 35]               0
           Conv2d-33           [-1, 64, 35, 35]          12,288
      BatchNorm2d-34           [-1, 64, 35, 35]             128
             ReLU-35           [-1, 64, 35, 35]               0
      BasicConv2d-36           [-1, 64, 35, 35]               0
           Conv2d-37           [-1, 96, 35, 35]          55,296
      BatchNorm2d-38           [-1, 96, 35, 35]             192
             ReLU-39           [-1, 96, 35, 35]               0
      BasicConv2d-40           [-1, 96, 35, 35]               0
           Conv2d-41           [-1, 96, 35, 35]          82,944
      BatchNorm2d-42           [-1, 96, 35, 35]             192
             ReLU-43           [-1, 96, 35, 35]               0
      BasicConv2d-44           [-1, 96, 35, 35]               0
           Conv2d-45           [-1, 32, 35, 35]           6,144
      BatchNorm2d-46           [-1, 32, 35, 35]              64
             ReLU-47           [-1, 32, 35, 35]               0
      BasicConv2d-48           [-1, 32, 35, 35]               0
       InceptionA-49          [-1, 256, 35, 35]               0
           Conv2d-50           [-1, 64, 35, 35]          16,384
      BatchNorm2d-51           [-1, 64, 35, 35]             128
             ReLU-52           [-1, 64, 35, 35]               0
      BasicConv2d-53           [-1, 64, 35, 35]               0
           Conv2d-54           [-1, 48, 35, 35]          12,288
      BatchNorm2d-55           [-1, 48, 35, 35]              96
             ReLU-56           [-1, 48, 35, 35]               0
      BasicConv2d-57           [-1, 48, 35, 35]               0
           Conv2d-58           [-1, 64, 35, 35]          76,800
      BatchNorm2d-59           [-1, 64, 35, 35]             128
             ReLU-60           [-1, 64, 35, 35]               0
      BasicConv2d-61           [-1, 64, 35, 35]               0
           Conv2d-62           [-1, 64, 35, 35]          16,384
      BatchNorm2d-63           [-1, 64, 35, 35]             128
             ReLU-64           [-1, 64, 35, 35]               0
      BasicConv2d-65           [-1, 64, 35, 35]               0
           Conv2d-66           [-1, 96, 35, 35]          55,296
      BatchNorm2d-67           [-1, 96, 35, 35]             192
             ReLU-68           [-1, 96, 35, 35]               0
      BasicConv2d-69           [-1, 96, 35, 35]               0
           Conv2d-70           [-1, 96, 35, 35]          82,944
      BatchNorm2d-71           [-1, 96, 35, 35]             192
             ReLU-72           [-1, 96, 35, 35]               0
      BasicConv2d-73           [-1, 96, 35, 35]               0
           Conv2d-74           [-1, 64, 35, 35]          16,384
      BatchNorm2d-75           [-1, 64, 35, 35]             128
             ReLU-76           [-1, 64, 35, 35]               0
      BasicConv2d-77           [-1, 64, 35, 35]               0
       InceptionA-78          [-1, 288, 35, 35]               0
           Conv2d-79           [-1, 64, 35, 35]          18,432
      BatchNorm2d-80           [-1, 64, 35, 35]             128
             ReLU-81           [-1, 64, 35, 35]               0
      BasicConv2d-82           [-1, 64, 35, 35]               0
           Conv2d-83           [-1, 48, 35, 35]          13,824
      BatchNorm2d-84           [-1, 48, 35, 35]              96
             ReLU-85           [-1, 48, 35, 35]               0
      BasicConv2d-86           [-1, 48, 35, 35]               0
           Conv2d-87           [-1, 64, 35, 35]          76,800
      BatchNorm2d-88           [-1, 64, 35, 35]             128
             ReLU-89           [-1, 64, 35, 35]               0
      BasicConv2d-90           [-1, 64, 35, 35]               0
           Conv2d-91           [-1, 64, 35, 35]          18,432
      BatchNorm2d-92           [-1, 64, 35, 35]             128
             ReLU-93           [-1, 64, 35, 35]               0
      BasicConv2d-94           [-1, 64, 35, 35]               0
           Conv2d-95           [-1, 96, 35, 35]          55,296
      BatchNorm2d-96           [-1, 96, 35, 35]             192
             ReLU-97           [-1, 96, 35, 35]               0
      BasicConv2d-98           [-1, 96, 35, 35]               0
           Conv2d-99           [-1, 96, 35, 35]          82,944
     BatchNorm2d-100           [-1, 96, 35, 35]             192
            ReLU-101           [-1, 96, 35, 35]               0
     BasicConv2d-102           [-1, 96, 35, 35]               0
          Conv2d-103           [-1, 64, 35, 35]          18,432
     BatchNorm2d-104           [-1, 64, 35, 35]             128
            ReLU-105           [-1, 64, 35, 35]               0
     BasicConv2d-106           [-1, 64, 35, 35]               0
      InceptionA-107          [-1, 288, 35, 35]               0
          Conv2d-108          [-1, 384, 17, 17]         995,328
     BatchNorm2d-109          [-1, 384, 17, 17]             768
            ReLU-110          [-1, 384, 17, 17]               0
     BasicConv2d-111          [-1, 384, 17, 17]               0
          Conv2d-112           [-1, 64, 35, 35]          18,432
     BatchNorm2d-113           [-1, 64, 35, 35]             128
            ReLU-114           [-1, 64, 35, 35]               0
     BasicConv2d-115           [-1, 64, 35, 35]               0
          Conv2d-116           [-1, 96, 35, 35]          55,296
     BatchNorm2d-117           [-1, 96, 35, 35]             192
            ReLU-118           [-1, 96, 35, 35]               0
     BasicConv2d-119           [-1, 96, 35, 35]               0
          Conv2d-120           [-1, 96, 17, 17]          82,944
     BatchNorm2d-121           [-1, 96, 17, 17]             192
            ReLU-122           [-1, 96, 17, 17]               0
     BasicConv2d-123           [-1, 96, 17, 17]               0
      ReductionA-124          [-1, 768, 17, 17]               0
          Conv2d-125          [-1, 192, 17, 17]         147,456
     BatchNorm2d-126          [-1, 192, 17, 17]             384
            ReLU-127          [-1, 192, 17, 17]               0
     BasicConv2d-128          [-1, 192, 17, 17]               0
          Conv2d-129          [-1, 128, 17, 17]          98,304
     BatchNorm2d-130          [-1, 128, 17, 17]             256
            ReLU-131          [-1, 128, 17, 17]               0
     BasicConv2d-132          [-1, 128, 17, 17]               0
          Conv2d-133          [-1, 128, 17, 17]         114,688
     BatchNorm2d-134          [-1, 128, 17, 17]             256
            ReLU-135          [-1, 128, 17, 17]               0
     BasicConv2d-136          [-1, 128, 17, 17]               0
          Conv2d-137          [-1, 192, 17, 17]         172,032
     BatchNorm2d-138          [-1, 192, 17, 17]             384
            ReLU-139          [-1, 192, 17, 17]               0
     BasicConv2d-140          [-1, 192, 17, 17]               0
          Conv2d-141          [-1, 128, 17, 17]          98,304
     BatchNorm2d-142          [-1, 128, 17, 17]             256
            ReLU-143          [-1, 128, 17, 17]               0
     BasicConv2d-144          [-1, 128, 17, 17]               0
          Conv2d-145          [-1, 128, 17, 17]         114,688
     BatchNorm2d-146          [-1, 128, 17, 17]             256
            ReLU-147          [-1, 128, 17, 17]               0
     BasicConv2d-148          [-1, 128, 17, 17]               0
          Conv2d-149          [-1, 128, 17, 17]         114,688
     BatchNorm2d-150          [-1, 128, 17, 17]             256
            ReLU-151          [-1, 128, 17, 17]               0
     BasicConv2d-152          [-1, 128, 17, 17]               0
          Conv2d-153          [-1, 128, 17, 17]         114,688
     BatchNorm2d-154          [-1, 128, 17, 17]             256
            ReLU-155          [-1, 128, 17, 17]               0
     BasicConv2d-156          [-1, 128, 17, 17]               0
          Conv2d-157          [-1, 192, 17, 17]         172,032
     BatchNorm2d-158          [-1, 192, 17, 17]             384
            ReLU-159          [-1, 192, 17, 17]               0
     BasicConv2d-160          [-1, 192, 17, 17]               0
          Conv2d-161          [-1, 192, 17, 17]         147,456
     BatchNorm2d-162          [-1, 192, 17, 17]             384
            ReLU-163          [-1, 192, 17, 17]               0
     BasicConv2d-164          [-1, 192, 17, 17]               0
      InceptionB-165          [-1, 768, 17, 17]               0
          Conv2d-166          [-1, 192, 17, 17]         147,456
     BatchNorm2d-167          [-1, 192, 17, 17]             384
            ReLU-168          [-1, 192, 17, 17]               0
     BasicConv2d-169          [-1, 192, 17, 17]               0
          Conv2d-170          [-1, 160, 17, 17]         122,880
     BatchNorm2d-171          [-1, 160, 17, 17]             320
            ReLU-172          [-1, 160, 17, 17]               0
     BasicConv2d-173          [-1, 160, 17, 17]               0
          Conv2d-174          [-1, 160, 17, 17]         179,200
     BatchNorm2d-175          [-1, 160, 17, 17]             320
            ReLU-176          [-1, 160, 17, 17]               0
     BasicConv2d-177          [-1, 160, 17, 17]               0
          Conv2d-178          [-1, 192, 17, 17]         215,040
     BatchNorm2d-179          [-1, 192, 17, 17]             384
            ReLU-180          [-1, 192, 17, 17]               0
     BasicConv2d-181          [-1, 192, 17, 17]               0
          Conv2d-182          [-1, 160, 17, 17]         122,880
     BatchNorm2d-183          [-1, 160, 17, 17]             320
            ReLU-184          [-1, 160, 17, 17]               0
     BasicConv2d-185          [-1, 160, 17, 17]               0
          Conv2d-186          [-1, 160, 17, 17]         179,200
     BatchNorm2d-187          [-1, 160, 17, 17]             320
            ReLU-188          [-1, 160, 17, 17]               0
     BasicConv2d-189          [-1, 160, 17, 17]               0
          Conv2d-190          [-1, 160, 17, 17]         179,200
     BatchNorm2d-191          [-1, 160, 17, 17]             320
            ReLU-192          [-1, 160, 17, 17]               0
     BasicConv2d-193          [-1, 160, 17, 17]               0
          Conv2d-194          [-1, 160, 17, 17]         179,200
     BatchNorm2d-195          [-1, 160, 17, 17]             320
            ReLU-196          [-1, 160, 17, 17]               0
     BasicConv2d-197          [-1, 160, 17, 17]               0
          Conv2d-198          [-1, 192, 17, 17]         215,040
     BatchNorm2d-199          [-1, 192, 17, 17]             384
            ReLU-200          [-1, 192, 17, 17]               0
     BasicConv2d-201          [-1, 192, 17, 17]               0
          Conv2d-202          [-1, 192, 17, 17]         147,456
     BatchNorm2d-203          [-1, 192, 17, 17]             384
            ReLU-204          [-1, 192, 17, 17]               0
     BasicConv2d-205          [-1, 192, 17, 17]               0
      InceptionB-206          [-1, 768, 17, 17]               0
          Conv2d-207          [-1, 192, 17, 17]         147,456
     BatchNorm2d-208          [-1, 192, 17, 17]             384
            ReLU-209          [-1, 192, 17, 17]               0
     BasicConv2d-210          [-1, 192, 17, 17]               0
          Conv2d-211          [-1, 160, 17, 17]         122,880
     BatchNorm2d-212          [-1, 160, 17, 17]             320
            ReLU-213          [-1, 160, 17, 17]               0
     BasicConv2d-214          [-1, 160, 17, 17]               0
          Conv2d-215          [-1, 160, 17, 17]         179,200
     BatchNorm2d-216          [-1, 160, 17, 17]             320
            ReLU-217          [-1, 160, 17, 17]               0
     BasicConv2d-218          [-1, 160, 17, 17]               0
          Conv2d-219          [-1, 192, 17, 17]         215,040
     BatchNorm2d-220          [-1, 192, 17, 17]             384
            ReLU-221          [-1, 192, 17, 17]               0
     BasicConv2d-222          [-1, 192, 17, 17]               0
          Conv2d-223          [-1, 160, 17, 17]         122,880
     BatchNorm2d-224          [-1, 160, 17, 17]             320
            ReLU-225          [-1, 160, 17, 17]               0
     BasicConv2d-226          [-1, 160, 17, 17]               0
          Conv2d-227          [-1, 160, 17, 17]         179,200
     BatchNorm2d-228          [-1, 160, 17, 17]             320
            ReLU-229          [-1, 160, 17, 17]               0
     BasicConv2d-230          [-1, 160, 17, 17]               0
          Conv2d-231          [-1, 160, 17, 17]         179,200
     BatchNorm2d-232          [-1, 160, 17, 17]             320
            ReLU-233          [-1, 160, 17, 17]               0
     BasicConv2d-234          [-1, 160, 17, 17]               0
          Conv2d-235          [-1, 160, 17, 17]         179,200
     BatchNorm2d-236          [-1, 160, 17, 17]             320
            ReLU-237          [-1, 160, 17, 17]               0
     BasicConv2d-238          [-1, 160, 17, 17]               0
          Conv2d-239          [-1, 192, 17, 17]         215,040
     BatchNorm2d-240          [-1, 192, 17, 17]             384
            ReLU-241          [-1, 192, 17, 17]               0
     BasicConv2d-242          [-1, 192, 17, 17]               0
          Conv2d-243          [-1, 192, 17, 17]         147,456
     BatchNorm2d-244          [-1, 192, 17, 17]             384
            ReLU-245          [-1, 192, 17, 17]               0
     BasicConv2d-246          [-1, 192, 17, 17]               0
      InceptionB-247          [-1, 768, 17, 17]               0
          Conv2d-248          [-1, 192, 17, 17]         147,456
     BatchNorm2d-249          [-1, 192, 17, 17]             384
            ReLU-250          [-1, 192, 17, 17]               0
     BasicConv2d-251          [-1, 192, 17, 17]               0
          Conv2d-252          [-1, 192, 17, 17]         147,456
     BatchNorm2d-253          [-1, 192, 17, 17]             384
            ReLU-254          [-1, 192, 17, 17]               0
     BasicConv2d-255          [-1, 192, 17, 17]               0
          Conv2d-256          [-1, 192, 17, 17]         258,048
     BatchNorm2d-257          [-1, 192, 17, 17]             384
            ReLU-258          [-1, 192, 17, 17]               0
     BasicConv2d-259          [-1, 192, 17, 17]               0
          Conv2d-260          [-1, 192, 17, 17]         258,048
     BatchNorm2d-261          [-1, 192, 17, 17]             384
            ReLU-262          [-1, 192, 17, 17]               0
     BasicConv2d-263          [-1, 192, 17, 17]               0
          Conv2d-264          [-1, 192, 17, 17]         147,456
     BatchNorm2d-265          [-1, 192, 17, 17]             384
            ReLU-266          [-1, 192, 17, 17]               0
     BasicConv2d-267          [-1, 192, 17, 17]               0
          Conv2d-268          [-1, 192, 17, 17]         258,048
     BatchNorm2d-269          [-1, 192, 17, 17]             384
            ReLU-270          [-1, 192, 17, 17]               0
     BasicConv2d-271          [-1, 192, 17, 17]               0
          Conv2d-272          [-1, 192, 17, 17]         258,048
     BatchNorm2d-273          [-1, 192, 17, 17]             384
            ReLU-274          [-1, 192, 17, 17]               0
     BasicConv2d-275          [-1, 192, 17, 17]               0
          Conv2d-276          [-1, 192, 17, 17]         258,048
     BatchNorm2d-277          [-1, 192, 17, 17]             384
            ReLU-278          [-1, 192, 17, 17]               0
     BasicConv2d-279          [-1, 192, 17, 17]               0
          Conv2d-280          [-1, 192, 17, 17]         258,048
     BatchNorm2d-281          [-1, 192, 17, 17]             384
            ReLU-282          [-1, 192, 17, 17]               0
     BasicConv2d-283          [-1, 192, 17, 17]               0
          Conv2d-284          [-1, 192, 17, 17]         147,456
     BatchNorm2d-285          [-1, 192, 17, 17]             384
            ReLU-286          [-1, 192, 17, 17]               0
     BasicConv2d-287          [-1, 192, 17, 17]               0
      InceptionB-288          [-1, 768, 17, 17]               0
          Conv2d-289          [-1, 192, 17, 17]         147,456
     BatchNorm2d-290          [-1, 192, 17, 17]             384
            ReLU-291          [-1, 192, 17, 17]               0
     BasicConv2d-292          [-1, 192, 17, 17]               0
          Conv2d-293            [-1, 320, 8, 8]         552,960
     BatchNorm2d-294            [-1, 320, 8, 8]             640
            ReLU-295            [-1, 320, 8, 8]               0
     BasicConv2d-296            [-1, 320, 8, 8]               0
          Conv2d-297          [-1, 192, 17, 17]         147,456
     BatchNorm2d-298          [-1, 192, 17, 17]             384
            ReLU-299          [-1, 192, 17, 17]               0
     BasicConv2d-300          [-1, 192, 17, 17]               0
          Conv2d-301          [-1, 192, 17, 17]         258,048
     BatchNorm2d-302          [-1, 192, 17, 17]             384
            ReLU-303          [-1, 192, 17, 17]               0
     BasicConv2d-304          [-1, 192, 17, 17]               0
          Conv2d-305          [-1, 192, 17, 17]         258,048
     BatchNorm2d-306          [-1, 192, 17, 17]             384
            ReLU-307          [-1, 192, 17, 17]               0
     BasicConv2d-308          [-1, 192, 17, 17]               0
          Conv2d-309            [-1, 192, 8, 8]         331,776
     BatchNorm2d-310            [-1, 192, 8, 8]             384
            ReLU-311            [-1, 192, 8, 8]               0
     BasicConv2d-312            [-1, 192, 8, 8]               0
      ReductionB-313           [-1, 1280, 8, 8]               0
          Conv2d-314            [-1, 320, 8, 8]         409,600
     BatchNorm2d-315            [-1, 320, 8, 8]             640
            ReLU-316            [-1, 320, 8, 8]               0
     BasicConv2d-317            [-1, 320, 8, 8]               0
          Conv2d-318            [-1, 384, 8, 8]         491,520
     BatchNorm2d-319            [-1, 384, 8, 8]             768
            ReLU-320            [-1, 384, 8, 8]               0
     BasicConv2d-321            [-1, 384, 8, 8]               0
          Conv2d-322            [-1, 384, 8, 8]         442,368
     BatchNorm2d-323            [-1, 384, 8, 8]             768
            ReLU-324            [-1, 384, 8, 8]               0
     BasicConv2d-325            [-1, 384, 8, 8]               0
          Conv2d-326            [-1, 384, 8, 8]         442,368
     BatchNorm2d-327            [-1, 384, 8, 8]             768
            ReLU-328            [-1, 384, 8, 8]               0
     BasicConv2d-329            [-1, 384, 8, 8]               0
          Conv2d-330            [-1, 448, 8, 8]         573,440
     BatchNorm2d-331            [-1, 448, 8, 8]             896
            ReLU-332            [-1, 448, 8, 8]               0
     BasicConv2d-333            [-1, 448, 8, 8]               0
          Conv2d-334            [-1, 384, 8, 8]       1,548,288
     BatchNorm2d-335            [-1, 384, 8, 8]             768
            ReLU-336            [-1, 384, 8, 8]               0
     BasicConv2d-337            [-1, 384, 8, 8]               0
          Conv2d-338            [-1, 384, 8, 8]         442,368
     BatchNorm2d-339            [-1, 384, 8, 8]             768
            ReLU-340            [-1, 384, 8, 8]               0
     BasicConv2d-341            [-1, 384, 8, 8]               0
          Conv2d-342            [-1, 384, 8, 8]         442,368
     BatchNorm2d-343            [-1, 384, 8, 8]             768
            ReLU-344            [-1, 384, 8, 8]               0
     BasicConv2d-345            [-1, 384, 8, 8]               0
          Conv2d-346            [-1, 192, 8, 8]         245,760
     BatchNorm2d-347            [-1, 192, 8, 8]             384
            ReLU-348            [-1, 192, 8, 8]               0
     BasicConv2d-349            [-1, 192, 8, 8]               0
      InceptionC-350           [-1, 2048, 8, 8]               0
          Conv2d-351            [-1, 320, 8, 8]         655,360
     BatchNorm2d-352            [-1, 320, 8, 8]             640
            ReLU-353            [-1, 320, 8, 8]               0
     BasicConv2d-354            [-1, 320, 8, 8]               0
          Conv2d-355            [-1, 384, 8, 8]         786,432
     BatchNorm2d-356            [-1, 384, 8, 8]             768
            ReLU-357            [-1, 384, 8, 8]               0
     BasicConv2d-358            [-1, 384, 8, 8]               0
          Conv2d-359            [-1, 384, 8, 8]         442,368
     BatchNorm2d-360            [-1, 384, 8, 8]             768
            ReLU-361            [-1, 384, 8, 8]               0
     BasicConv2d-362            [-1, 384, 8, 8]               0
          Conv2d-363            [-1, 384, 8, 8]         442,368
     BatchNorm2d-364            [-1, 384, 8, 8]             768
            ReLU-365            [-1, 384, 8, 8]               0
     BasicConv2d-366            [-1, 384, 8, 8]               0
          Conv2d-367            [-1, 448, 8, 8]         917,504
     BatchNorm2d-368            [-1, 448, 8, 8]             896
            ReLU-369            [-1, 448, 8, 8]               0
     BasicConv2d-370            [-1, 448, 8, 8]               0
          Conv2d-371            [-1, 384, 8, 8]       1,548,288
     BatchNorm2d-372            [-1, 384, 8, 8]             768
            ReLU-373            [-1, 384, 8, 8]               0
     BasicConv2d-374            [-1, 384, 8, 8]               0
          Conv2d-375            [-1, 384, 8, 8]         442,368
     BatchNorm2d-376            [-1, 384, 8, 8]             768
            ReLU-377            [-1, 384, 8, 8]               0
     BasicConv2d-378            [-1, 384, 8, 8]               0
          Conv2d-379            [-1, 384, 8, 8]         442,368
     BatchNorm2d-380            [-1, 384, 8, 8]             768
            ReLU-381            [-1, 384, 8, 8]               0
     BasicConv2d-382            [-1, 384, 8, 8]               0
          Conv2d-383            [-1, 192, 8, 8]         393,216
     BatchNorm2d-384            [-1, 192, 8, 8]             384
            ReLU-385            [-1, 192, 8, 8]               0
     BasicConv2d-386            [-1, 192, 8, 8]               0
      InceptionC-387           [-1, 2048, 8, 8]               0
          Linear-388                    [-1, 4]           8,196
================================================================
Total params: 21,793,764
Trainable params: 21,793,764
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 1.02
Forward/backward pass size (MB): 292.53
Params size (MB): 83.14
Estimated Total Size (MB): 376.69
----------------------------------------------------------------

三、 训练模型

1. 编写训练函数

def train(dataloader,model,loss_fn,optimizer):
    size=len(dataloader.dataset) #训练集的大小
    num_batches=len(dataloader) #批次数目
    
    train_loss,train_acc=0,0 #初始化训练损失和正确率
    
    for x,y in dataloader: #获取图片及其标签
        x,y=x.to(device),y.to(device)
        
        #计算预测误差
        pred=model(x) #网络输出
        loss=loss_fn(pred,y) #计算网络输出和真实值之间的差距,二者差值即为损失
        
        #反向传播
        optimizer.zero_grad() #grad属性归零
        loss.backward() #反向传播
        optimizer.step() #每一步自动更新
        
        #记录acc与loss
        train_acc+=(pred.argmax(1)==y).type(torch.float).sum().item()
        train_loss+=loss.item()
        
    train_acc/=size
    train_loss/=num_batches
    
    return train_acc,train_loss

2. 编写测试函数

测试函数和训练函数大致相同,但是由于不进行梯度下降对网络权重进行更新,所以不需要传入优化器

#测试函数
def test(dataloader,model,loss_fn):
    size=len(dataloader.dataset) #测试集的大小
    num_batches=len(dataloader) #批次数目
    test_loss,test_acc=0,0
    
    #当不进行训练时,停止梯度更新,节省计算内存消耗
    with torch.no_grad():
        for imgs,target in dataloader:
            imgs,target=imgs.to(device),target.to(device)
            
            #计算loss
            target_pred=model(imgs)
            loss=loss_fn(target_pred,target)
            
            test_loss+=loss.item()
            test_acc+=(target_pred.argmax(1)==target).type(torch.float).sum().item()
            
    test_acc/=size
    test_loss/=num_batches
    
    return test_acc,test_loss

3. 正式训练

import copy
opt=torch.optim.Adam(model.parameters(),lr=1e-4) #创建优化器,并设置学习率
loss_fn=nn.CrossEntropyLoss() #创建损失函数
 
epochs=50
 
train_loss=[]
train_acc=[]
test_loss=[]
test_acc=[]
 
best_acc=0 #设置一个最佳准确率,作为最佳模型的判别指标
 
for epoch in range(epochs):
    
    model.train()
    epoch_train_acc,epoch_train_loss=train(train_dl,model,loss_fn,opt)
    
    model.eval()
    epoch_test_acc,epoch_test_loss=test(test_dl,model,loss_fn)
    
    #保存最佳模型到J9_model
    if epoch_test_acc>best_acc:
        best_acc=epoch_test_acc
        J9_model=copy.deepcopy(model)
        
    train_acc.append(epoch_train_acc)
    train_loss.append(epoch_train_loss)
    test_acc.append(epoch_test_acc)
    test_loss.append(epoch_test_loss)
    
    #获取当前学习率
    lr=opt.state_dict()['param_groups'][0]['lr']
    
    template=('Epoch:{:2d},Train_acc:{:.1f}%,Train_loss:{:.3f},Test_acc:{:.1f}%,Test_loss:{:.3f},Lr:{:.2E}')
    print(template.format(epoch+1,epoch_train_acc*100,epoch_train_loss,
                           epoch_test_acc*100,epoch_test_loss,lr))
    
#保存最佳模型到文件中
PATH=r'D:\THE MNIST DATABASE\J-series\J9_model.pth'
torch.save(model.state_dict(),PATH)

运行结果:

Epoch: 1,Train_acc:77.2%,Train_loss:0.634,Test_acc:89.3%,Test_loss:0.443,Lr:1.00E-04
Epoch: 2,Train_acc:78.3%,Train_loss:0.596,Test_acc:88.9%,Test_loss:0.346,Lr:1.00E-04
Epoch: 3,Train_acc:82.3%,Train_loss:0.477,Test_acc:68.9%,Test_loss:1.772,Lr:1.00E-04
Epoch: 4,Train_acc:83.1%,Train_loss:0.510,Test_acc:88.0%,Test_loss:0.358,Lr:1.00E-04
Epoch: 5,Train_acc:84.8%,Train_loss:0.443,Test_acc:91.1%,Test_loss:0.213,Lr:1.00E-04
Epoch: 6,Train_acc:83.9%,Train_loss:0.432,Test_acc:88.4%,Test_loss:0.301,Lr:1.00E-04
Epoch: 7,Train_acc:87.8%,Train_loss:0.368,Test_acc:88.4%,Test_loss:0.300,Lr:1.00E-04
Epoch: 8,Train_acc:87.9%,Train_loss:0.371,Test_acc:90.2%,Test_loss:0.358,Lr:1.00E-04
Epoch: 9,Train_acc:88.6%,Train_loss:0.361,Test_acc:92.9%,Test_loss:0.183,Lr:1.00E-04
Epoch:10,Train_acc:88.9%,Train_loss:0.310,Test_acc:91.6%,Test_loss:0.277,Lr:1.00E-04
Epoch:11,Train_acc:89.8%,Train_loss:0.306,Test_acc:94.2%,Test_loss:0.174,Lr:1.00E-04
Epoch:12,Train_acc:88.0%,Train_loss:0.357,Test_acc:92.0%,Test_loss:0.301,Lr:1.00E-04
Epoch:13,Train_acc:92.1%,Train_loss:0.246,Test_acc:92.9%,Test_loss:0.266,Lr:1.00E-04
Epoch:14,Train_acc:91.2%,Train_loss:0.269,Test_acc:94.2%,Test_loss:0.163,Lr:1.00E-04
Epoch:15,Train_acc:90.8%,Train_loss:0.294,Test_acc:87.1%,Test_loss:0.331,Lr:1.00E-04
Epoch:16,Train_acc:91.4%,Train_loss:0.251,Test_acc:93.8%,Test_loss:0.177,Lr:1.00E-04
Epoch:17,Train_acc:92.9%,Train_loss:0.214,Test_acc:90.7%,Test_loss:0.276,Lr:1.00E-04
Epoch:18,Train_acc:88.9%,Train_loss:0.315,Test_acc:92.9%,Test_loss:0.215,Lr:1.00E-04
Epoch:19,Train_acc:92.2%,Train_loss:0.231,Test_acc:91.6%,Test_loss:0.251,Lr:1.00E-04
Epoch:20,Train_acc:92.9%,Train_loss:0.228,Test_acc:91.1%,Test_loss:0.229,Lr:1.00E-04
Epoch:21,Train_acc:93.0%,Train_loss:0.211,Test_acc:90.7%,Test_loss:0.245,Lr:1.00E-04
Epoch:22,Train_acc:93.2%,Train_loss:0.235,Test_acc:94.2%,Test_loss:0.150,Lr:1.00E-04
Epoch:23,Train_acc:91.6%,Train_loss:0.259,Test_acc:83.1%,Test_loss:0.375,Lr:1.00E-04
Epoch:24,Train_acc:93.2%,Train_loss:0.209,Test_acc:93.3%,Test_loss:0.219,Lr:1.00E-04
Epoch:25,Train_acc:93.2%,Train_loss:0.183,Test_acc:94.2%,Test_loss:0.181,Lr:1.00E-04
Epoch:26,Train_acc:91.4%,Train_loss:0.242,Test_acc:92.9%,Test_loss:0.249,Lr:1.00E-04
Epoch:27,Train_acc:92.0%,Train_loss:0.220,Test_acc:93.3%,Test_loss:0.234,Lr:1.00E-04
Epoch:28,Train_acc:94.0%,Train_loss:0.195,Test_acc:94.7%,Test_loss:0.141,Lr:1.00E-04
Epoch:29,Train_acc:93.1%,Train_loss:0.189,Test_acc:95.1%,Test_loss:0.191,Lr:1.00E-04
Epoch:30,Train_acc:93.2%,Train_loss:0.226,Test_acc:95.6%,Test_loss:0.204,Lr:1.00E-04
Epoch:31,Train_acc:94.3%,Train_loss:0.147,Test_acc:93.8%,Test_loss:0.219,Lr:1.00E-04
Epoch:32,Train_acc:95.4%,Train_loss:0.150,Test_acc:93.3%,Test_loss:0.225,Lr:1.00E-04
Epoch:33,Train_acc:94.9%,Train_loss:0.165,Test_acc:95.6%,Test_loss:0.169,Lr:1.00E-04
Epoch:34,Train_acc:95.4%,Train_loss:0.150,Test_acc:94.7%,Test_loss:0.193,Lr:1.00E-04
Epoch:35,Train_acc:95.7%,Train_loss:0.100,Test_acc:93.8%,Test_loss:0.145,Lr:1.00E-04
Epoch:36,Train_acc:94.4%,Train_loss:0.198,Test_acc:92.9%,Test_loss:0.167,Lr:1.00E-04
Epoch:37,Train_acc:95.3%,Train_loss:0.163,Test_acc:94.7%,Test_loss:0.110,Lr:1.00E-04
Epoch:38,Train_acc:96.1%,Train_loss:0.120,Test_acc:93.3%,Test_loss:0.177,Lr:1.00E-04
Epoch:39,Train_acc:94.6%,Train_loss:0.197,Test_acc:94.2%,Test_loss:0.196,Lr:1.00E-04
Epoch:40,Train_acc:95.4%,Train_loss:0.132,Test_acc:96.0%,Test_loss:0.117,Lr:1.00E-04
Epoch:41,Train_acc:96.6%,Train_loss:0.115,Test_acc:96.9%,Test_loss:0.116,Lr:1.00E-04
Epoch:42,Train_acc:96.1%,Train_loss:0.113,Test_acc:95.6%,Test_loss:0.119,Lr:1.00E-04
Epoch:43,Train_acc:97.1%,Train_loss:0.103,Test_acc:93.3%,Test_loss:0.218,Lr:1.00E-04
Epoch:44,Train_acc:94.9%,Train_loss:0.168,Test_acc:89.3%,Test_loss:0.251,Lr:1.00E-04
Epoch:45,Train_acc:97.3%,Train_loss:0.094,Test_acc:93.3%,Test_loss:0.180,Lr:1.00E-04
Epoch:46,Train_acc:97.4%,Train_loss:0.086,Test_acc:94.7%,Test_loss:0.210,Lr:1.00E-04
Epoch:47,Train_acc:95.3%,Train_loss:0.125,Test_acc:95.1%,Test_loss:0.200,Lr:1.00E-04
Epoch:48,Train_acc:95.9%,Train_loss:0.131,Test_acc:94.7%,Test_loss:0.159,Lr:1.00E-04
Epoch:49,Train_acc:95.0%,Train_loss:0.147,Test_acc:93.8%,Test_loss:0.218,Lr:1.00E-04
Epoch:50,Train_acc:97.6%,Train_loss:0.076,Test_acc:95.6%,Test_loss:0.172,Lr:1.00E-04

四、 结果可视化

1. Loss与Accuracy图

import matplotlib.pyplot as plt
#隐藏警告
import warnings
warnings.filterwarnings("ignore")   #忽略警告信息
plt.rcParams['font.sans-serif']=['SimHei']   #正常显示中文标签
plt.rcParams['axes.unicode_minus']=False   #正常显示负号
plt.rcParams['figure.dpi']=300   #分辨率
 
epochs_range=range(epochs)
plt.figure(figsize=(12,3))
 
plt.subplot(1,2,1)
plt.plot(epochs_range,train_acc,label='Training Accuracy')
plt.plot(epochs_range,test_acc,label='Test Accuracy')
plt.legend(loc='lower right')
plt.title('Training and Validation Accuracy')
 
plt.subplot(1,2,2)
plt.plot(epochs_range,train_loss,label='Training Loss')
plt.plot(epochs_range,test_loss,label='Test Loss')
plt.legend(loc='upper right')
plt.title('Training and Validation Loss')
plt.show()

运行结果:

2. 指定图片进行预测  

from PIL import Image
 
classes=list(total_data.class_to_idx)
 
def predict_one_image(image_path,model,transform,classes):
    
    test_img=Image.open(image_path).convert('RGB')
    plt.imshow(test_img)   #展示预测的图片
    
    test_img=transform(test_img)
    img=test_img.to(device).unsqueeze(0)
    
    model.eval()
    output=model(img)
    
    _,pred=torch.max(output,1)
    pred_class=classes[pred]
    print(f'预测结果是:{pred_class}')

预测图片:

#预测训练集中的某张照片
predict_one_image(image_path=r'D:\THE MNIST DATABASE\weather_photos\shine\shine15.jpg',
                  model=model,transform=train_transforms,classes=classes)

运行结果:

预测结果是:shine

五、心得体会  

在本周的项目训练中,手动搭建了InceptionV3模型,加深了对该模型的理解。


http://www.kler.cn/a/383025.html

相关文章:

  • 【基于Zynq FPGA对雷龙SD NAND的测试】
  • 【ROS2】接口(话题、服务、动作)的创建,编译后生成的C++代码详解
  • 提升网站安全性 HTTPS的重要性与应用指南
  • spring-boot(整合aop)
  • 汇聚全球前沿科技产品,北京智能科技产业展览会·世亚智博会
  • ECC校验算法的验证
  • MySQL的sql练习,适合初学者
  • 共同探索未来科技新境界 冠捷科技集团及腾讯云AI智能战略合作签约会
  • 开源的 API 学习平台「GitHub 热点速览」
  • 全面解析:网络协议及其应用
  • asp.net文件防盗链
  • 理解spring中的AOP
  • git 提交代码流程
  • 递归 != 递龟
  • 和合共赢 丨 广州探迹科技有限公司与泰迪智能科技战略合作签约仪式圆满结束
  • Redis常见面试题(二)
  • 蓝牙协议的前世今生
  • 猫用空气净化器哪个牌子好?求除毛好、噪音小的宠物空气净化器!
  • 华为eNSP:QinQ
  • RTDE确保整个机械臂(包括关节和连杆)都不会进入预设的不安全空间范围
  • 02 高效调优:Oracle内存体系的精细化管理实践
  • 聚观早报 | 比亚迪腾势D9登陆泰国;苹果 iOS 18.2 将发布
  • HDFS和HBase跨集群数据迁移 源码
  • 【PGCCC】Postgresql slru 缓存和存储
  • 基于 Vue3、Vite 和 TypeScript 实现开发环境下解决跨域问题,实现前后端数据传递
  • 【人工智能】图神经网络(GNN)的原理与实现:Python与PyTorch Geometric在社交网络与化学分子建模中的应用