AlexNet:
AlexNet是2012年ImageNet竞赛冠军获得者Hinton和他的学生Alex Krizhevsky设计的。也是在那年之后,更多的更深的神经网络被提出,比如优秀的vgg,GoogLeNet。 这对于传统的机器学习分类算法而言,已经相当的出色。其结构如下
AlexNet网络相对于Lenet层数更深,同时第一次引入了激活函数ReLU,在全连接层引入了Dropout层防止过拟合。Dropout就是随机使一些神经元失效不参与网络的计算。
pytorch 网络代码:
import torch
import torch.nn as nn
class _AlexNet(nn.Module):
def __init__(self):
super(_AlexNet,self).__init__()
self.conv1=nn.Sequential(
nn.Conv2d(in_chananels=3,out_channels=64,kernel_size=11,stride=4,padding=2),#in 3*223*223 out 64*55*55
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3,stride=2),
)
self.conv2=nn.Sequential(
nn.Conv2d(in_channels=64,out_channels=192,kernel_size=5,padding=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3,stride=2),
)
self.conv3=nn.Sequential(
nn.Conv2d(in_channels=192,out_channels=384,kernel_size=3,padding=1),
nn.ReLU(inplace=True),
)
self.conv4=nn.Sequential(
nn.Conv2d(in_channels=384,out_channels=256,kernel_size=3,padding=1),
nn.ReLU(inplace=True),
)
self.conv5=nn.Sequential(
nn.Conv2d(in_channels=256,out_channels=256,kernel_size=3,padding=1),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3,stride=2)
)
self.classifier=nn.Sequential(
nn.Dropout(),
nn.Liner(256*6*6,4096),
nn.ReLU(inplace=True),
nn.Dropout(),
nn.Liner(4096,4096),
nn.ReLU(inplace=True),
nn.Liner(4096,10)
)
def forward(self,x):
x=self.conv1(x)
x=self.conv2(x)
x=self.conv3(x)
x=self.conv4(x)
x=self.conv5(x)
#x=x.view(x.size(0),-1)
x=x.view(x.size(0),256*6*6)
output=self.classifier(x)
return output
AlexNet=_AlexNet()
AlexNet.cuda()
optimizer=torch.optim.Adam(_AlexNet.parameters(),lr=LR)
loss_func=nn.CrossEntropyLoss()