论文原文https://arxiv.org/pdf/1409.4842.pdf
代码参考了网上流传的博客,但是原始出处没有找到。
使用的数据集下载:https://pan.baidu.com/s/1rPZzQTE00r8lnc9Ott9j2Q?pwd=n5im
GoogLeNet相比VGG与AlexNet更加有创新,因此不能直接贴出结构就立马复现,必须先了解其特性,当然,第一次见到GoogLeNet时需要先看结构。
实力有限,理解不到位处请见谅,望指正。
个人理解:previous layer送来了上一层的多维张量,随后在incecption模块中,分为4个copy并行(这里并行是从网络结构来谈的,而不是计算机运算)被上图中对应节点处理,随后直接合并为一个大张量(Filter concatenation),比如3x3x9 和3x3x10合并为了3x3x19,而为了能够合并,要注意图中的1x1,3x3,5x5等卷积操作必须设置合适的步长与padding确保输出的前两维相同。其次,这样的“并联“结构没有把复杂的网络并联,而是将卷积和池化操作这种卷积神经网络的基本操作并联,感觉像是让网络在训练时自行挑选每一次最需要的操作。
网络最后采用了average pooling(平均池化)来代替全连接层,该想法来自NIN(Network in Network),事实证明这样可以将准确率提高0.6%,最大池化往往更容易把图像中的”边缘“特征筛选出,而平均池化更考虑到背景信息
这里参考https://blog.csdn.net/qq_42308217/article/details/110350914
假设现在有一个特征矩阵是512,如果不使用1×1的卷积核,直接使用64个5×5的卷积核进行卷积的话,那么总参数为5×5×512×64=819200,如果使用24个1×1卷积核进行降维,再使用64个5×5的卷积核进行卷积,则所需要的参数就会变为50688
图像过深往往引起梯度消失,梯度爆炸的问题,GoogLeNet网络结构挺深,但是使用了辅助分类器解决问题(详见下面2.0部分的网络结构图)
网络训练过程中,inception模块连接处直接分出一层,加上全连接输出到softmax进行分类!然后根据loss向前面网络的更新权重。
网络用于预测时,不使用辅助分类器,辅助分类器进行分类只是为了在训练时更新前面的网络的权重。
本代码实现的网络结构
----------------------------------------------------------------
Layer (type) Output Shape Param #
================================================================
Conv2d-1 [-1, 64, 41, 41] 9,472
ReLU-2 [-1, 64, 41, 41] 0
BasicConv2d-3 [-1, 64, 41, 41] 0
MaxPool2d-4 [-1, 64, 20, 20] 0
Conv2d-5 [-1, 64, 20, 20] 4,160
ReLU-6 [-1, 64, 20, 20] 0
BasicConv2d-7 [-1, 64, 20, 20] 0
Conv2d-8 [-1, 192, 20, 20] 110,784
ReLU-9 [-1, 192, 20, 20] 0
BasicConv2d-10 [-1, 192, 20, 20] 0
MaxPool2d-11 [-1, 192, 10, 10] 0
Conv2d-12 [-1, 64, 10, 10] 12,352
ReLU-13 [-1, 64, 10, 10] 0
BasicConv2d-14 [-1, 64, 10, 10] 0
Conv2d-15 [-1, 96, 10, 10] 18,528
ReLU-16 [-1, 96, 10, 10] 0
BasicConv2d-17 [-1, 96, 10, 10] 0
Conv2d-18 [-1, 128, 10, 10] 110,720
ReLU-19 [-1, 128, 10, 10] 0
BasicConv2d-20 [-1, 128, 10, 10] 0
Conv2d-21 [-1, 16, 10, 10] 3,088
ReLU-22 [-1, 16, 10, 10] 0
BasicConv2d-23 [-1, 16, 10, 10] 0
Conv2d-24 [-1, 32, 10, 10] 12,832
ReLU-25 [-1, 32, 10, 10] 0
BasicConv2d-26 [-1, 32, 10, 10] 0
MaxPool2d-27 [-1, 192, 10, 10] 0
Conv2d-28 [-1, 32, 10, 10] 6,176
ReLU-29 [-1, 32, 10, 10] 0
BasicConv2d-30 [-1, 32, 10, 10] 0
Inception-31 [-1, 256, 10, 10] 0
Conv2d-32 [-1, 128, 10, 10] 32,896
ReLU-33 [-1, 128, 10, 10] 0
BasicConv2d-34 [-1, 128, 10, 10] 0
Conv2d-35 [-1, 128, 10, 10] 32,896
ReLU-36 [-1, 128, 10, 10] 0
BasicConv2d-37 [-1, 128, 10, 10] 0
Conv2d-38 [-1, 192, 10, 10] 221,376
ReLU-39 [-1, 192, 10, 10] 0
BasicConv2d-40 [-1, 192, 10, 10] 0
Conv2d-41 [-1, 32, 10, 10] 8,224
ReLU-42 [-1, 32, 10, 10] 0
BasicConv2d-43 [-1, 32, 10, 10] 0
Conv2d-44 [-1, 96, 10, 10] 76,896
ReLU-45 [-1, 96, 10, 10] 0
BasicConv2d-46 [-1, 96, 10, 10] 0
MaxPool2d-47 [-1, 256, 10, 10] 0
Conv2d-48 [-1, 64, 10, 10] 16,448
ReLU-49 [-1, 64, 10, 10] 0
BasicConv2d-50 [-1, 64, 10, 10] 0
Inception-51 [-1, 480, 10, 10] 0
MaxPool2d-52 [-1, 480, 5, 5] 0
Conv2d-53 [-1, 192, 5, 5] 92,352
ReLU-54 [-1, 192, 5, 5] 0
BasicConv2d-55 [-1, 192, 5, 5] 0
Conv2d-56 [-1, 96, 5, 5] 46,176
ReLU-57 [-1, 96, 5, 5] 0
BasicConv2d-58 [-1, 96, 5, 5] 0
Conv2d-59 [-1, 208, 5, 5] 179,920
ReLU-60 [-1, 208, 5, 5] 0
BasicConv2d-61 [-1, 208, 5, 5] 0
Conv2d-62 [-1, 16, 5, 5] 7,696
ReLU-63 [-1, 16, 5, 5] 0
BasicConv2d-64 [-1, 16, 5, 5] 0
Conv2d-65 [-1, 48, 5, 5] 19,248
ReLU-66 [-1, 48, 5, 5] 0
BasicConv2d-67 [-1, 48, 5, 5] 0
MaxPool2d-68 [-1, 480, 5, 5] 0
Conv2d-69 [-1, 64, 5, 5] 30,784
ReLU-70 [-1, 64, 5, 5] 0
BasicConv2d-71 [-1, 64, 5, 5] 0
Inception-72 [-1, 512, 5, 5] 0
AvgPool2d-73 [-1, 512, 4, 4] 0
Conv2d-74 [-1, 128, 4, 4] 65,664
ReLU-75 [-1, 128, 4, 4] 0
BasicConv2d-76 [-1, 128, 4, 4] 0
Linear-77 [-1, 1024] 2,098,176
Linear-78 [-1, 2] 2,050
InceptionAux-79 [-1, 2] 0
Conv2d-80 [-1, 160, 5, 5] 82,080
ReLU-81 [-1, 160, 5, 5] 0
BasicConv2d-82 [-1, 160, 5, 5] 0
Conv2d-83 [-1, 112, 5, 5] 57,456
ReLU-84 [-1, 112, 5, 5] 0
BasicConv2d-85 [-1, 112, 5, 5] 0
Conv2d-86 [-1, 224, 5, 5] 226,016
ReLU-87 [-1, 224, 5, 5] 0
BasicConv2d-88 [-1, 224, 5, 5] 0
Conv2d-89 [-1, 24, 5, 5] 12,312
ReLU-90 [-1, 24, 5, 5] 0
BasicConv2d-91 [-1, 24, 5, 5] 0
Conv2d-92 [-1, 64, 5, 5] 38,464
ReLU-93 [-1, 64, 5, 5] 0
BasicConv2d-94 [-1, 64, 5, 5] 0
MaxPool2d-95 [-1, 512, 5, 5] 0
Conv2d-96 [-1, 64, 5, 5] 32,832
ReLU-97 [-1, 64, 5, 5] 0
BasicConv2d-98 [-1, 64, 5, 5] 0
Inception-99 [-1, 512, 5, 5] 0
Conv2d-100 [-1, 128, 5, 5] 65,664
ReLU-101 [-1, 128, 5, 5] 0
BasicConv2d-102 [-1, 128, 5, 5] 0
Conv2d-103 [-1, 128, 5, 5] 65,664
ReLU-104 [-1, 128, 5, 5] 0
BasicConv2d-105 [-1, 128, 5, 5] 0
Conv2d-106 [-1, 256, 5, 5] 295,168
ReLU-107 [-1, 256, 5, 5] 0
BasicConv2d-108 [-1, 256, 5, 5] 0
Conv2d-109 [-1, 24, 5, 5] 12,312
ReLU-110 [-1, 24, 5, 5] 0
BasicConv2d-111 [-1, 24, 5, 5] 0
Conv2d-112 [-1, 64, 5, 5] 38,464
ReLU-113 [-1, 64, 5, 5] 0
BasicConv2d-114 [-1, 64, 5, 5] 0
MaxPool2d-115 [-1, 512, 5, 5] 0
Conv2d-116 [-1, 64, 5, 5] 32,832
ReLU-117 [-1, 64, 5, 5] 0
BasicConv2d-118 [-1, 64, 5, 5] 0
Inception-119 [-1, 512, 5, 5] 0
Conv2d-120 [-1, 112, 5, 5] 57,456
ReLU-121 [-1, 112, 5, 5] 0
BasicConv2d-122 [-1, 112, 5, 5] 0
Conv2d-123 [-1, 144, 5, 5] 73,872
ReLU-124 [-1, 144, 5, 5] 0
BasicConv2d-125 [-1, 144, 5, 5] 0
Conv2d-126 [-1, 288, 5, 5] 373,536
ReLU-127 [-1, 288, 5, 5] 0
BasicConv2d-128 [-1, 288, 5, 5] 0
Conv2d-129 [-1, 32, 5, 5] 16,416
ReLU-130 [-1, 32, 5, 5] 0
BasicConv2d-131 [-1, 32, 5, 5] 0
Conv2d-132 [-1, 64, 5, 5] 51,264
ReLU-133 [-1, 64, 5, 5] 0
BasicConv2d-134 [-1, 64, 5, 5] 0
MaxPool2d-135 [-1, 512, 5, 5] 0
Conv2d-136 [-1, 64, 5, 5] 32,832
ReLU-137 [-1, 64, 5, 5] 0
BasicConv2d-138 [-1, 64, 5, 5] 0
Inception-139 [-1, 528, 5, 5] 0
AvgPool2d-140 [-1, 528, 4, 4] 0
Conv2d-141 [-1, 128, 4, 4] 67,712
ReLU-142 [-1, 128, 4, 4] 0
BasicConv2d-143 [-1, 128, 4, 4] 0
Linear-144 [-1, 1024] 2,098,176
Linear-145 [-1, 2] 2,050
InceptionAux-146 [-1, 2] 0
Conv2d-147 [-1, 256, 5, 5] 135,424
ReLU-148 [-1, 256, 5, 5] 0
BasicConv2d-149 [-1, 256, 5, 5] 0
Conv2d-150 [-1, 160, 5, 5] 84,640
ReLU-151 [-1, 160, 5, 5] 0
BasicConv2d-152 [-1, 160, 5, 5] 0
Conv2d-153 [-1, 320, 5, 5] 461,120
ReLU-154 [-1, 320, 5, 5] 0
BasicConv2d-155 [-1, 320, 5, 5] 0
Conv2d-156 [-1, 32, 5, 5] 16,928
ReLU-157 [-1, 32, 5, 5] 0
BasicConv2d-158 [-1, 32, 5, 5] 0
Conv2d-159 [-1, 128, 5, 5] 102,528
ReLU-160 [-1, 128, 5, 5] 0
BasicConv2d-161 [-1, 128, 5, 5] 0
MaxPool2d-162 [-1, 528, 5, 5] 0
Conv2d-163 [-1, 128, 5, 5] 67,712
ReLU-164 [-1, 128, 5, 5] 0
BasicConv2d-165 [-1, 128, 5, 5] 0
Inception-166 [-1, 832, 5, 5] 0
MaxPool2d-167 [-1, 832, 3, 3] 0
Conv2d-168 [-1, 256, 3, 3] 213,248
ReLU-169 [-1, 256, 3, 3] 0
BasicConv2d-170 [-1, 256, 3, 3] 0
Conv2d-171 [-1, 160, 3, 3] 133,280
ReLU-172 [-1, 160, 3, 3] 0
BasicConv2d-173 [-1, 160, 3, 3] 0
Conv2d-174 [-1, 320, 3, 3] 461,120
ReLU-175 [-1, 320, 3, 3] 0
BasicConv2d-176 [-1, 320, 3, 3] 0
Conv2d-177 [-1, 32, 3, 3] 26,656
ReLU-178 [-1, 32, 3, 3] 0
BasicConv2d-179 [-1, 32, 3, 3] 0
Conv2d-180 [-1, 128, 3, 3] 102,528
ReLU-181 [-1, 128, 3, 3] 0
BasicConv2d-182 [-1, 128, 3, 3] 0
MaxPool2d-183 [-1, 832, 3, 3] 0
Conv2d-184 [-1, 128, 3, 3] 106,624
ReLU-185 [-1, 128, 3, 3] 0
BasicConv2d-186 [-1, 128, 3, 3] 0
Inception-187 [-1, 832, 3, 3] 0
Conv2d-188 [-1, 384, 3, 3] 319,872
ReLU-189 [-1, 384, 3, 3] 0
BasicConv2d-190 [-1, 384, 3, 3] 0
Conv2d-191 [-1, 192, 3, 3] 159,936
ReLU-192 [-1, 192, 3, 3] 0
BasicConv2d-193 [-1, 192, 3, 3] 0
Conv2d-194 [-1, 384, 3, 3] 663,936
ReLU-195 [-1, 384, 3, 3] 0
BasicConv2d-196 [-1, 384, 3, 3] 0
Conv2d-197 [-1, 48, 3, 3] 39,984
ReLU-198 [-1, 48, 3, 3] 0
BasicConv2d-199 [-1, 48, 3, 3] 0
Conv2d-200 [-1, 128, 3, 3] 153,728
ReLU-201 [-1, 128, 3, 3] 0
BasicConv2d-202 [-1, 128, 3, 3] 0
MaxPool2d-203 [-1, 832, 3, 3] 0
Conv2d-204 [-1, 128, 3, 3] 106,624
ReLU-205 [-1, 128, 3, 3] 0
BasicConv2d-206 [-1, 128, 3, 3] 0
Inception-207 [-1, 1024, 3, 3] 0
AdaptiveAvgPool2d-208 [-1, 1024, 1, 1] 0
Dropout-209 [-1, 1024] 0
Linear-210 [-1, 2] 2,050
================================================================
Total params: 10,309,430
Trainable params: 10,309,430
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 0.08
Forward/backward pass size (MB): 12.61
Params size (MB): 39.33
Estimated Total Size (MB): 52.01
----------------------------------------------------------------