-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwo_stage_model.py
87 lines (70 loc) · 2.18 KB
/
two_stage_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from Basic_blocks import *
class encoder_C(nn.Module):
def __init__(self,in_channels,out_channels):
super(encoder_C,self).__init__()
self.block1 = nn.Sequential(
nn.Conv2d(in_channels, 16, 3, 1),
nn.BatchNorm2d(16),
nn.ReLU(True))
self.block2 = nn.Sequential(
BasicBlock(16, 32, False),
BasicBlock(32, 64, False),
BasicBlock(64, 64, False),
)
self.Linear_down = nn.Linear(64 * 4 * 4, out_channels)
def forward(self,x):
x=self.block1(x)
x=self.block2(x)
x = x.view(x.shape[0], -1)
out = self.Linear_down(x)
return out
class decoder_C(nn.Module):
def __init__(self,in_channels):
super(decoder_C,self).__init__()
self.Linear_up = nn.Linear(in_channels, 64*4*4)
self.deconvBlock1 = nn.Sequential(
DecodeBlock(64, 64)
)
self.deconvBlock2 = nn.Sequential(
DecodeBlock(64, 32)
)
self.deconvBlock3 = nn.Sequential(
DecodeBlock(32, 16)
)
self.conv1 = nn.Conv2d(16, 1, 1)
def forward(self,x):
x = self.Linear_up(x)
x = x.view(-1,64,4,4)
x = self.deconvBlock1(x)
x = self.deconvBlock2(x)
x = self.deconvBlock3(x)
x = self.conv1(x)
return x
class encoder_L(nn.Module):
def __init__(self,in_channels,out_channels):
super(encoder_L,self).__init__()
self.block1 = nn.Sequential(
nn.Linear(in_channels,400),
nn.ReLU(True)
)
self.Linear_down = nn.Linear(400, out_channels)
def forward(self,x):
x=x.view(-1,28*28)
x=self.block1(x)
out = self.Linear_down(x)
return out
class decoder_L(nn.Module):
def __init__(self,in_channels):
super(decoder_L,self).__init__()
self.deconvBlock1 = nn.Sequential(
nn.Linear(in_channels, 400),
nn.ReLU()
)
self.deconvBlock2 = nn.Sequential(
nn.Linear(400, 28*28),
nn.Sigmoid()
)
def forward(self,x):
x = self.deconvBlock1(x)
x = self.deconvBlock2(x)
return x