1.引入库
import torch
from torch import nn
2.AlexNet网络
class AlexNet(nn.Module):
def __init__(self,number_classes):#number_classes种类
super(AlexNet,self).__init__()
self.conv1 = nn.Sequential(
nn.Conv2d(in_channels=3,out_channels=96,kernel_size=11,stride=4),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3,stride=2),
# nn.LocalResponseNorm(size=5, alpha=0.0001, beta=0.75, k=2)
)
self.conv2 = nn.Sequential(
nn.Conv2d(in_channels=96,out_channels=256,kernel_size=5,groups=2,padding=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3,stride=2),
# nn.LocalResponseNorm(size=5, alpha=0.0001, beta=0.75, k=2)
)
self.conv3 = nn.Sequential(
nn.Conv2d(in_channels=256,out_channels=384,kernel_size=3,padding=1),
nn.ReLU(inplace=True)
)
self.conv4 = nn.Sequential(
nn.Conv2d(in_channels=384,out_channels=384,kernel_size=3,padding=1),
nn.ReLU(inplace=True)
)
self.conv5 = nn.Sequential(
nn.Conv2d(in_channels=384,out_channels=256,kernel_size=3,padding=1),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3,stride=2)
)
self.fc1 = nn.Sequential(
nn.Linear(in_features=6*6*256,out_features=4096),
nn.ReLU(inplace=True),
nn.Dropout(p=0.5)
)
self.fc2 = nn.Sequential(
nn.Linear(in_features=4096,out_features=4096),
nn.ReLU(inplace=True),
nn.Dropout(p=0.5)
)
self.fc3 = nn.Linear(in_features=4096,out_features=number_classes)
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 = self.conv5(self.conv4(self.conv3(self.conv2(self.conv1(x)))))
print(x)
x = x.view(-1,6*6*256) #展开
# x = self.fc1(x)
# x = self.fc2(x)
# x = self.fc3(x)
x = self.fc3(self.fc2(self.fc1(x)))
return x
该处使用的url网络请求的数据。
3.参考网址
[1] https://zhuanlan.zhihu.com/p/29786939
[2] https://zhuanlan.zhihu.com/p/349527410
[3] https://blog.csdn.net/weixin_40330033/article/details/105628753?utm_medium=distribute.pc_relevant.none-task-blog-2defaultCTRLISTdefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2defaultCTRLISTdefault-2.no_search_link
[4.] AlexNet论文原文
http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf
[5.] AlexNet论文翻译https://blog.csdn.net/hongbin_xu/article/details/80271291