-
Notifications
You must be signed in to change notification settings - Fork 0
/
vgg.py
93 lines (79 loc) · 2.8 KB
/
vgg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import torch.nn as nn
import torch
from torch.autograd import Variable
class vgg16_conv(nn.Module):
def __init__(self):
super(vgg16_conv, self).__init__()
# conv1
self.conv1_1 = nn.Conv2d(3, 64, 3, padding=1)
self.relu1_1 = nn.ReLU(inplace=True)
self.conv1_2 = nn.Conv2d(64, 64, 3, padding=1)
self.relu1_2 = nn.ReLU(inplace=True)
self.pool1 = nn.MaxPool2d(2, stride=2)
#conv2
self.conv2_1 = nn.Conv2d(64, 128, 3, padding=1)
self.relu2_1 = nn.ReLU(inplace=True)
self.conv2_2 = nn.Conv2d(128, 128, 3, padding=1)
self.relu2_2 = nn.ReLU(inplace=True)
self.pool2 = nn.MaxPool2d(2, stride=2)
#conv3
self.conv3_1 = nn.Conv2d(128, 256, 3, padding=1)
self.relu3_1 = nn.ReLU(inplace=True)
self.conv3_2 = nn.Conv2d(256, 256, 3, padding=1)
self.relu3_2 = nn.ReLU(inplace=True)
self.conv3_3 = nn.Conv2d(256, 256, 3, padding=1)
self.relu3_3 = nn.ReLU(inplace=True)
self.pool3 = nn.MaxPool2d(2, stride=2)
#conv4
self.conv4_1 = nn.Conv2d(256, 512, 3, padding=1)
self.relu4_1 = nn.ReLU(inplace=True)
self.conv4_2 = nn.Conv2d(512, 512, 3, padding=1)
self.relu4_2 = nn.ReLU(inplace=True)
self.conv4_3 = nn.Conv2d(512, 512, 3, padding=1)
self.relu4_3 = nn.ReLU(inplace=True)
self.pool4 = nn.MaxPool2d(2, stride=2)
#conv5
self.conv5_1 = nn.Conv2d(512, 512, 3, padding=2, dilation=2)
self.relu5_1 = nn.ReLU(inplace=True)
self.conv5_2 = nn.Conv2d(512, 512, 3, padding=2, dilation=2)
self.relu5_2 = nn.ReLU(inplace=True)
self.conv5_3 = nn.Conv2d(512, 512, 3, padding=2, dilation=2)
self.relu5_3 = nn.ReLU(inplace=True)
def forward(self, x):
x = self.conv1_1(x)
x = self.relu1_1(x)
x = self.conv1_2(x)
x = self.relu1_2(x)
x = self.pool1(x)
x = self.conv2_1(x)
x = self.relu2_1(x)
x = self.conv2_2(x)
x = self.relu2_2(x)
x = self.pool2(x)
x = self.conv3_1(x)
x = self.relu3_1(x)
x = self.conv3_2(x)
x = self.relu3_2(x)
x = self.conv3_3(x)
x = self.relu3_3(x)
x = self.pool3(x)
x = self.conv4_1(x)
x = self.relu4_1(x)
x = self.conv4_2(x)
x = self.relu4_2(x)
x = self.conv4_3(x)
x = self.relu4_3(x)
x = self.pool4(x)
x = self.conv5_1(x)
x = self.relu5_1(x)
x = self.conv5_2(x)
x = self.relu5_2(x)
x = self.conv5_3(x)
x = self.relu5_3(x)
return x
if __name__ == '__main__':
net = vgg16_conv()
input = Variable(torch.FloatTensor(2, 3, 256, 256))
output = net(input)
print('net output size:')
print(output.shape)