AlexNet,VGG,NiN,GoogleNet,批量归一化
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |
学着学着突然发现数据分析numpymatplotlibpandas这一部分内容没学完还有pytorch的一些代码没有学完所以在看像AlexNet这一些代码实现的时候很多都看不懂也得慢慢的补上来了hhh。
这一周花了一些时间学习了数据分析的一些内容然后继续学习深度学习。
AlexNet
AlexNet比LeNet复杂一点先是11*11的卷积层然后是一个最大池化层再是5*5的卷积层然后又是一个最大池化层接下来是3个卷积层一个最大池化层最后是三个全连接层。
import torch
from torch import nn
from d2l import torch as d2l
net = nn.Sequential(
nn.Conv2d(1, 96, kernel_size=11, stride=4, padding=1), nn.ReLU(),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Conv2d(96, 256, kernel_size=5, padding=2), nn.ReLU(),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Conv2d(256, 384, kernel_size=3, padding=1), nn.ReLU(),
nn.Conv2d(384, 384, kernel_size=3, padding=1), nn.ReLU(),
nn.Conv2d(384, 256, kernel_size=3, padding=1), nn.ReLU(),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Flatten(),
nn.Linear(6400, 4096), nn.ReLU(),
nn.Dropout(p=0.5),
nn.Linear(4096, 4096), nn.ReLU(),
nn.Dropout(p=0.5),
nn.Linear(4096, 10))
ALexNet相比于LeNet来说是更大更深的一种网络新进入了丢弃法ReLU最大池化层和数据增强。
VGG
VGG使用可重复使用的卷积块来构建深度卷积神经网络。
VGG网络可以分为2部分第一部分主要由卷积层和汇聚层组成第二部分由全连接层组成。
VGG-11第一个模块有64个输出通道每个后续模块将输出通道数量翻倍直到该数字达到512。8个卷积层3个全连接层。
import torch
from torch import nn
from d2l import torch as d2l
# 卷积层的数量和输出通道的数量
def vgg_block(num_convs, in_channels, out_channels):
layers = []
for _ in range(num_convs):
layers.append(nn.Conv2d(in_channels, out_channels,kernel_size=3, padding=1))
layers.append(nn.ReLU())
in_channels = out_channels
layers.append(nn.MaxPool2d(kernel_size=2,stride=2))
return nn.Sequential(*layers)
conv_arch = ((1, 64), (1, 128), (2, 256), (2, 512), (2, 512))
def vgg(conv_arch):
conv_blks = []
in_channels = 1
# 卷积层部分
for (num_convs, out_channels) in conv_arch:
conv_blks.append(vgg_block(num_convs, in_channels, out_channels))
in_channels = out_channels
return nn.Sequential(
*conv_blks, nn.Flatten(),
# 全连接层部分
nn.Linear(out_channels * 7 * 7, 4096), nn.ReLU(), nn.Dropout(0.5),
nn.Linear(4096, 4096), nn.ReLU(), nn.Dropout(0.5),
nn.Linear(4096, 10))
net = vgg(conv_arch)
NiN、GoogleNet
NiN块一个卷积层后跟两个全连接层步幅为1无填充输出形状跟卷积层输出一样起到全连接层的作用
NiN架构无全连接层交替使用NiN块和步幅为2的最大池化层逐步减小高度和增大通道数最后使用全局平均池化层得到输出输入通道数是类别数。
NiN块使用卷积层加两个1*1卷积层NiN使用全局平均池化层来替代VGG和AlexNet中的全连接层不容易过拟合参数更少。
GoogleNetInception块用4条有不同超参数的卷积层和池化层的路来抽取不同的信息它的模型参数小计算复杂度低GoogleNet有9个Inception块是第一个达到上百层的网络。
批量归一化
两个元素可学习的参数γ和β
作用在全连接层和卷积层输出上激活函数之前或者全连接层和卷积层输入上。对于全连接层作用在特征维对于卷积层作用在通道维。
批量归一化固定小批量中的均值和方差然后学习出合适的偏移和缩放可以加快收敛速度一般不改变模型精度。