-
Notifications
You must be signed in to change notification settings - Fork 0
/
encDecMask.py
56 lines (51 loc) · 1.8 KB
/
encDecMask.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
from torch import nn
class encDecMask(nn.Module):
def __init__(self):
super().__init__()
self.encoder = nn.Sequential(
nn.Conv2d(3, 16, 3, stride=3, padding=1), # b, 16, 10, 10
nn.ReLU(True),
nn.MaxPool2d(2, stride=2), # b, 16, 5, 5
nn.Conv2d(16, 8, 3, stride=2, padding=1), # b, 8, 3, 3
nn.ReLU(True),
nn.MaxPool2d(2, stride=1) # b, 8, 2, 2
)
self.decoder = nn.Sequential(
nn.ConvTranspose2d(8, 16, 3, stride=2), # b, 16, 5, 5
nn.ReLU(True),
nn.ConvTranspose2d(16, 8, 5, stride=3, padding=1), # b, 8, 15, 15
nn.ReLU(True),
nn.ConvTranspose2d(8, 3, 2, stride=2, padding=1), # b, 1, 28, 28
#nn.Tanh()
)
def forward(self, x):
x = self.encoder(x)
x = self.decoder(x)
return x
# from torch import nn
#
#
# class encDec(nn.Module):
# def __init__(self):
# super().__init__()
# self.encoder = nn.Sequential(
# nn.Conv2d(1, 16, 3, stride=3, padding=1), # b, 16, 10, 10
# nn.ReLU(True),
# nn.MaxPool2d(2, stride=2), # b, 16, 5, 5
# nn.Conv2d(16, 8, 3, stride=2, padding=1), # b, 8, 3, 3
# nn.ReLU(True),
# nn.MaxPool2d(2, stride=1) # b, 8, 2, 2
# )
# self.decoder = nn.Sequential(
# nn.ConvTranspose2d(8, 16, 3, stride=2), # b, 16, 5, 5
# nn.ReLU(True),
# nn.ConvTranspose2d(16, 8, 5, stride=3, padding=1), # b, 8, 15, 15
# nn.ReLU(True),
# nn.ConvTranspose2d(8, 1, 2, stride=2, padding=1), # b, 1, 28, 28
# nn.Tanh()
# )
#
# def forward(self, x):
# x = self.encoder(x)
# x = self.decoder(x)
# return x