这篇内容并未debug
知识点1、GoogleNet的结构
知识点2、写大型网络的技巧
知识点3、batchnorm
知识点4、不改变图像长宽的s k p
知识点5、 torch.cat((), dim=1) 构造并联网络
知识点1
google net 的结构像是 电路中的 几个并联的串联
知识点2
对于一个大型的网络(GoogleNet),可以先拆分为几个小的网络(inception),先编好小的网络(inception),然后用小的网络(inception)组成大网络(GoogleNet)。为了变好小网络(inception),可以先编写一个更基础的小小网络(conv_relu),以便可以灵活的调用小网络(inception)
import torch
import numpy as np
from torch.autograd import Variable
from torchvision.datasets import CIFAR10
from torch import nn
知识点3
nn.BatchNorm 批标准化,可以理解为对channel之间的数据处理方式
def conv_relu(in_channel, out_channel, kernel, stride=1, padding=0):
layer = nn.Sequential(
nn.conv2d(in_channel, out_channel, kernel, stride, padding),
nn.BatchNorm(out_channel, out_channel, eps=1e-3),
nn.ReLU(True)
)
return layer
知识点4
s = 1 时 k = 1 / k = 3 , padding=1 / k = 5, padding=2 这些情况下的卷积池化不改变图片高宽
知识点5
用out = torch.cat((f1, f2, f3, f4), dim=1) 这种方式 构造“并联”的网络, 记住
class inception(nn.Module):
def __init__(self, in_channels, out1_1, out2_1, out2_3, out3_1, out3_5, out4_1):
super(inception, self).__init__()
self.branch1x1 = conv_relu(in_channels, out1_1, 1)
self.branch2x2 = nn.Sequential(
conv_relu(in_channels, out2_1, 1),
conv_relu(out2_1, out2_3, 3, padding=1)
)
self.branch3x3 = nn.Sequential(
conv_relu(in_channel, out3_1, 1),
conv_relu(out3_1, out3_5, 5, padding=2)
)
self.branch_pool = nn.Sequential(
nn.MaxPool2d(3, stride=1, padding=1),
nn.conv_relu(in_channels, out4_1, 1)
)
def forward(self, x):
f1 = self.branch1x1(x)
f2 = self.branch2x2(x)
f3 = self.branch3x3(x)
f4 = self.branch_pool(x)
ou