VGGNet搭建

2018年10月7日09:33:27VGGNet搭建已关闭评论 549

VGGNet的名称来源于VisualGeometry Group,它是牛津大学的计算机视觉组。VGGNet的论文题目是:VeryDeep Convolutional Networks For Large-Scale Image Recognition.

开发工具仍使用Jupyter,VGGNet使用更小的滤波器和更深的结构,代码如下:

  1. import torch
  2. import torch.nn as nn
  3. class VGGNet(nn.Module):
  4.     def __init__(self):
  5.         super(VGGNet,self).__init__()
  6.         self.features=nn.Sequential(
  7.             nn.Conv2d(3,64,3,1,1),
  8.             nn.ReLU(True),
  9.             nn.Conv2d(64,64,3,1,1),
  10.             nn.ReLU(True),
  11.             nn.MaxPool2d(2,2),
  12.             nn.Conv2d(64,128,3,1,1),
  13.             nn.ReLU(True),
  14.             nn.Conv2d(128,128,3,1,1),
  15.             nn.ReLU(True),
  16.             nn.MaxPool2d(2,2),
  17.             nn.Conv2d(128,256,3,1,1),
  18.             nn.ReLU(True),
  19.             nn.Conv2d(256,256,3,1,1),
  20.             nn.ReLU(True),
  21.             nn.Conv2d(256,256,3,1,1),
  22.             nn.ReLU(True),
  23.             nn.MaxPool2d(2,2),
  24.             nn.Conv2d(256,512,3,1,1),
  25.             nn.ReLU(True),
  26.             nn.Conv2d(512,512,3,1,1),
  27.             nn.ReLU(True),
  28.             nn.Conv2d(512,512,3,1,1),
  29.             nn.ReLU(True),
  30.             nn.MaxPool2d(2,2),
  31.             nn.Conv2d(512,512,3,1,1),
  32.             nn.ReLU(True),
  33.             nn.Conv2d(512,512,3,1,1),
  34.             nn.ReLU(True),
  35.             nn.Conv2d(512,512,3,1,1),
  36.             nn.ReLU(True),
  37.             nn.MaxPool2d(2,2)
  38.         )
  39.         self.classifier=nn.Sequential(
  40.             nn.Linear(25088,4096),
  41.             nn.ReLU(True),
  42.             nn.Dropout(0.5),
  43.             nn.Linear(4096,4096),
  44.             nn.ReLU(True),
  45.             nn.Dropout(0.5),
  46.             nn.Linear(4096,1000)
  47.         )
  48.     def forward(self,x):
  49.         x=self.features(x)
  50.         x=x.view(x.size(0),-1)
  51.         x=self.classifier(x)
  52.         return  x
  53. vggnet=VGGNet()
  54. print(vggnet)

运行结果如图:
VGGNet搭建
VGGNet搭建

 

历史上的今天: