编译环境为Jupyter,代码如下:文章源自联网快讯-https://x1995.cn/3301.html
- #AlexNet 搭建
- import torch
- import torch.nn as nn
- class AlexNet(nn.Module):
- def __init__(self):
- super(AlexNet,self).__init__()
- self.features=nn.Sequential(
- nn.Conv2d(3,96,11,4,0),
- nn.ReLU(True),
- nn.MaxPool2d(3,2),
- nn.Conv2d(96,256,5,1,2),
- nn.ReLU(True),
- nn.MaxPool2d(3,2),
- nn.Conv2d(256,384,3,1,1),
- nn.ReLU(True),
- nn.Conv2d(384,384,3,1,1),
- nn.ReLU(True),
- nn.Conv2d(384,256,3,1,1),
- nn.ReLU(True),
- nn.MaxPool2d(3,2)
- )
- self.classifier=nn.Sequential(
- nn.Linear(9216,4096),
- nn.ReLU(True),
- nn.Dropout(0.5),
- nn.Linear(4096,4096),
- nn.ReLU(True),
- nn.Dropout(0.5),
- nn.Linear(4096,1000)
- )
- def forward(self,x):
- x=self.features(x)
- x=x.view(x.size(0),-1)
- x=self.classifier(x)
- return x
- alexnet=AlexNet()
- print(alexnet)
运行后网络结构:
文章源自联网快讯-https://x1995.cn/3301.html
继续阅读
评论