VGGNet的名称来源于VisualGeometry Group,它是牛津大学的计算机视觉组。VGGNet的论文题目是:VeryDeep Convolutional Networks For Large-Scale Image Recognition.文章源自联网快讯-https://x1995.cn/3312.html
开发工具仍使用Jupyter,VGGNet使用更小的滤波器和更深的结构,代码如下:文章源自联网快讯-https://x1995.cn/3312.html
- import torch
- import torch.nn as nn
- class VGGNet(nn.Module):
- def __init__(self):
- super(VGGNet,self).__init__()
- self.features=nn.Sequential(
- nn.Conv2d(3,64,3,1,1),
- nn.ReLU(True),
- nn.Conv2d(64,64,3,1,1),
- nn.ReLU(True),
- nn.MaxPool2d(2,2),
- nn.Conv2d(64,128,3,1,1),
- nn.ReLU(True),
- nn.Conv2d(128,128,3,1,1),
- nn.ReLU(True),
- nn.MaxPool2d(2,2),
- nn.Conv2d(128,256,3,1,1),
- nn.ReLU(True),
- nn.Conv2d(256,256,3,1,1),
- nn.ReLU(True),
- nn.Conv2d(256,256,3,1,1),
- nn.ReLU(True),
- nn.MaxPool2d(2,2),
- nn.Conv2d(256,512,3,1,1),
- nn.ReLU(True),
- nn.Conv2d(512,512,3,1,1),
- nn.ReLU(True),
- nn.Conv2d(512,512,3,1,1),
- nn.ReLU(True),
- nn.MaxPool2d(2,2),
- nn.Conv2d(512,512,3,1,1),
- nn.ReLU(True),
- nn.Conv2d(512,512,3,1,1),
- nn.ReLU(True),
- nn.Conv2d(512,512,3,1,1),
- nn.ReLU(True),
- nn.MaxPool2d(2,2)
- )
- self.classifier=nn.Sequential(
- nn.Linear(25088,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
- vggnet=VGGNet()
- print(vggnet)
运行结果如图:
文章源自联网快讯-https://x1995.cn/3312.html
文章源自联网快讯-https://x1995.cn/3312.html
继续阅读
评论