-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
63 lines (47 loc) · 1.92 KB
/
model.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
import torch.nn as nn
class VAT(nn.Module):
def __init__(self, top_bn=True):
super(VAT, self).__init__()
self.top_bn = top_bn
self.main = nn.Sequential(
nn.Conv2d(3, 128, 3, 1, 1, bias=False),
nn.BatchNorm2d(128),
nn.LeakyReLU(0.1),
nn.Conv2d(128, 128, 3, 1, 1, bias=False),
nn.BatchNorm2d(128),
nn.LeakyReLU(0.1),
nn.Conv2d(128, 128, 3, 1, 1, bias=False),
nn.BatchNorm2d(128),
nn.LeakyReLU(0.1),
nn.MaxPool2d(2, 2, 1),
nn.Dropout2d(),
nn.Conv2d(128, 256, 3, 1, 1, bias=False),
nn.BatchNorm2d(256),
nn.LeakyReLU(0.1),
nn.Conv2d(256, 256, 3, 1, 1, bias=False),
nn.BatchNorm2d(256),
nn.LeakyReLU(0.1),
nn.Conv2d(256, 256, 3, 1, 1, bias=False),
nn.BatchNorm2d(256),
nn.LeakyReLU(0.1),
nn.MaxPool2d(2, 2, 1),
nn.Dropout2d(),
nn.Conv2d(256, 512, 3, 1, 0, bias=False),
nn.BatchNorm2d(512),
nn.LeakyReLU(0.1),
nn.Conv2d(512, 256, 1, 1, 1, bias=False),
nn.BatchNorm2d(256),
nn.LeakyReLU(0.1),
nn.Conv2d(256, 128, 1, 1, 1, bias=False),
nn.BatchNorm2d(128),
nn.LeakyReLU(0.1),
nn.AdaptiveAvgPool2d((1, 1))
)
self.linear = nn.Linear(128, 10)
self.bn = nn.BatchNorm1d(10)
def forward(self, input):
output = self.main(input)
output = self.linear(output.view(input.size()[0], -1))
if self.top_bn:
output = self.bn(output)
return output