Author:张一极 2020-0323-00:27
结构:
多个卷积多尺度的堆叠。
Code:
541class vgg(nn.Module):
2 def __init__(self,input_channel,num_classes):
3 super(vgg,self).__init__()
4 self.head_layer = conv_(3,64,kernel_size = 1,stride =1,padding=0)
5 self.layer_2 = conv_(64,64,kernel_size = 3,stride = 1,padding = 1)
6 self.layer_3 = nn.MaxPool2d(2,stride = 2,padding = 0)
7 self.layer_4 = conv_(64,128,kernel_size= 3,stride= 1,padding = 1)
8 self.layer_5 = conv_(128,128,kernel_size = 3,stride = 1,padding = 1)
9 self.layer_6 = nn.MaxPool2d(2,stride = 2)
10 self.layer_7 = conv_(128,256,kernel_size = 3,stride = 1,padding = 1)
11 self.layer_8 = conv_(256,256,kernel_size = 3,stride = 1,padding = 1)
12 self.layer_9 = conv_(256,256,kernel_size = 3,stride = 1,padding = 1)
13 self.layer_10 = nn.MaxPool2d(2,stride = 2)
14 self.layer_11 = conv_(256,512,kernel_size = 3,stride = 1,padding = 1)
15 self.layer_12 = conv_(512,512,kernel_size = 3,stride = 1,padding = 1)
16 self.layer_13 = conv_(512,512,kernel_size = 3,stride = 1,padding = 1)
17 self.layer_14 = nn.MaxPool2d(2,stride = 2)
18 self.layer_15 = conv_(512,512,kernel_size = 3,stride = 1,padding = 1)
19 self.layer_16 = conv_(512,512,kernel_size = 3,stride = 1,padding = 1)
20 self.layer_17 = conv_(512,512,kernel_size = 3,stride = 1,padding = 1)
21 self.layer_18 = nn.MaxPool2d(2,stride = 2)
22 self.dense = nn.Sequential(
23 nn.Linear(25088,4096),
24 nn.ReLU(True),
25 nn.Dropout(0.5),
26 nn.Linear(4096,4096),
27 nn.ReLU(True),
28 nn.Dropout(0.5),
29 nn.Linear(4096,10)
30 )
31 def forward(self,x):
32 x = self.head_layer(x)
33 x = self.layer_2(x)
34 x = self.layer_3(x)
35 x = self.layer_4(x)
36 x = self.layer_5(x)
37 x = self.layer_6(x)
38 x = self.layer_7(x)
39 x = self.layer_8(x)
40 x = self.layer_9(x)
41 x = self.layer_10(x)
42 x = self.layer_11(x)
43 x = self.layer_12(x)
44 x = self.layer_13(x)
45 x = self.layer_14(x)
46 x = self.layer_15(x)
47 x = self.layer_16(x)
48 x = self.layer_17(x)
49 x = self.layer_18(x)
50 x = x.view(x.shape[0], -1)
51 print(x.shape)
52 logits = self.dense(x)
53 probas = F.softmax(x, dim=1)
54 return logits,probas
实验🧪going