-
Notifications
You must be signed in to change notification settings - Fork 0
/
networks.py
65 lines (46 loc) · 1.88 KB
/
networks.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
import torch.nn.functional as F
from torch.nn import Conv2d, Dropout, MaxPool2d, Linear, ConvTranspose2d, UpsamplingNearest2d, Module
class BasicCNN(Module):
def __init__(self, num_classes):
super(BasicCNN, self).__init__()
self.pool = MaxPool2d(kernel_size=2, stride=2)
self.drop = Dropout(0.8)
self.cv1 = Conv2d(1, 32, kernel_size=3, stride=1)
self.cv2 = Conv2d(32, 64, kernel_size=3, stride=1)
self.cv3 = Conv2d(64, 64, kernel_size=3, stride=1)
self.cv4 = Conv2d(64, 64, kernel_size=3, stride=1)
self.fc1 = Linear(4224, 256)
self.out = Linear(256, num_classes)
def forward(self, x):
x = self.pool(F.relu(self.cv1(x)))
x = self.pool(F.relu(self.cv2(x)))
x = self.pool(F.relu(self.cv3(x)))
x = self.pool(F.relu(self.cv4(x)))
x = x.view(x.size(0), -1)
x = F.relu(self.fc1(x))
x = self.drop(x)
x = self.out(x)
return x
class BasicAutoEncoder(Module):
def __init__(self):
super(BasicAutoEncoder, self).__init__()
self.pool = MaxPool2d(kernel_size=2, stride=2)
self.poolt = UpsamplingNearest2d(scale_factor=2)
self.cv1 = Conv2d(1, 64, kernel_size=4, stride=1)
self.cv2 = Conv2d(64, 32, kernel_size=3, stride=1)
self.cv3 = Conv2d(32, 16, kernel_size=3, stride=1)
self.cv1t = ConvTranspose2d(16, 32, kernel_size=3, stride=1)
self.cv2t = ConvTranspose2d(32, 64, kernel_size=3, stride=1)
self.cv3t = ConvTranspose2d(64, 1, kernel_size=4, stride=1)
def forward(self, x):
x = F.relu(self.cv1(x))
x = self.pool(x)
x = F.relu(self.cv2(x))
x = self.pool(x)
x = F.relu(self.cv3(x))
x = F.relu(self.cv1t(x))
x = self.poolt(x)
x = F.relu(self.cv2t(x))
x = self.poolt(x)
x = F.relu(self.cv3t(x))
return x