VGG
1.网络结构
如图可见,VGG网络的构造很简单,通过不断地卷积,池化,扩大通道数,降低宽高,最终平展为一维数据再进行softmax分类。相较于AlexNet而言,VGG最大的特征就是降低了卷积核尺寸,增加了卷积核的深度层数,拥有更多的非线性变换,增加了CNN对特征的学习能力。
2.pytorch网络设计
这里采用的数据集为FashionMNIST数据集,慢慢地往后的文章也会引入更多的数据集使用,Fashion MNIST包含了10种类别70000个不同时尚穿戴品的图像,整体数据结构上跟MNIST完全一致。每张图像的尺寸同样是28*28,但下载下来的数据通道数为1。
#定义块
def vgg_block(num_convs, in_channels, num_channels):
layers = []
for i in range(num_convs):
layers += [nn.Conv2d(in_channels=in_channels, out_channels=num_channels, kernel_size=3, padding=1)]
in_channels = num_channels
layers += [nn.ReLU()]
layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
return nn.Sequential(*layers)
# 网络定义
class VGG(nn.Module):
def __init__(self):
super(VGG, self).__init__()
# 这里适配输入为3x224x224的图片
self.conv_arch = ((1, 3, 64), (1,