-
Notifications
You must be signed in to change notification settings - Fork 7
/
model_trial.py
158 lines (141 loc) · 5.46 KB
/
model_trial.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import torch
import torch.nn as nn
import torch.nn.init as init
# For 4 channel Dataset
class rdcnn(nn.Module):
def __init__(self, drop_rate):
super(rdcnn, self).__init__()
self.discriminator = nn.Sequential(
nn.Conv2d(4, 16, 3, stride=2, padding=0), # 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.generator = nn.Sequential(
nn.ConvTranspose2d(8, 16, 3, stride=2), # b, 16, 5, 5
nn.ReLU(True),
nn.ConvTranspose2d(16, 8, 2, stride=2), # b, 8, 10, 10
nn.ReLU(True),
nn.ConvTranspose2d(8, 1, 3, stride=2), # b, 1, 21, 21
nn.Tanh()
)
self.dropout = nn.Dropout(drop_rate)
def forward(self, x):
x = self.discriminator(x)
x = self.generator(x)
x = self.dropout(x)
return x
# ReLU activation
class rdcnn_2(nn.Module):
def __init__(self, drop_rate):
super(rdcnn_2, self).__init__()
self.discriminator = nn.Sequential(
nn.Conv2d(4, 40, 3, stride=2, padding=1), # b, 40, 11, 11
nn.ReLU(True),
nn.Dropout(drop_rate) ,
nn.Conv2d(40, 20, 3, stride=2, padding=1), # b, 20, 6, 6
nn.ReLU(True),
nn.Dropout(drop_rate) ,
nn.MaxPool2d(2, stride=1), # b, 20, 5, 5
nn.Conv2d(20, 10, 3, stride=2, padding=1), # b, 10, 3, 3
nn.ReLU(True),
nn.Dropout(drop_rate) ,
nn.MaxPool2d(2, stride=1), # b, 10, 2, 2
nn.Dropout(drop_rate) ,
)
self.generator = nn.Sequential(
nn.ConvTranspose2d(10, 40, 3, stride=2, padding=1), # b, 40, 3, 3
nn.ReLU(True),
nn.ConvTranspose2d(40, 20, 2, stride=2), # b, 20, 6, 6
nn.ReLU(True),
nn.ConvTranspose2d(20, 10, 2, stride=2), # b, 10, 12, 12
nn.ReLU(True),
nn.ConvTranspose2d(10, 1, 3, stride=2,padding=2), # b, 1, 21, 21
nn.ReLU(True)
)
def forward(self, x):
x = self.discriminator(x)
x = self.generator(x)
return x
class rdcnn_2_oldlarge(nn.Module):
def __init__(self, drop_rate):
super(rdcnn_2_oldlarge, self).__init__()
self.encoder = nn.Sequential(
nn.Conv2d(4, 84, 3, stride=2, padding=1), # b, 84, 11, 11
nn.BatchNorm2d(84),
nn.ReLU(True),
nn.Dropout(drop_rate) ,
nn.Conv2d(84, 168, 3, stride=2, padding=1), # b, 168, 6, 6
nn.BatchNorm2d(168),
nn.ReLU(True),
nn.Dropout(drop_rate) ,
nn.MaxPool2d(2, stride=1), # b, 168, 5, 5
nn.Conv2d(168, 336, 3, stride=2, padding=1), # b, 336, 3, 3
nn.BatchNorm2d(336),
nn.ReLU(True),
nn.Dropout(drop_rate) ,
nn.Conv2d(336, 672, 2, stride=1, padding=0), # b, 672, 2, 2
nn.BatchNorm2d(672),
nn.ReLU(True),
nn.Dropout(drop_rate) ,
nn.MaxPool2d(2, stride=1), # b, 672, 1, 1
)
self.decoder = nn.Sequential(
nn.ConvTranspose2d(672, 1344, 2, stride=1, padding=0), # b, 1344, 2, 2
nn.BatchNorm2d(1344),
nn.ReLU(True),
nn.ConvTranspose2d(1344, 672, 3, stride=2, padding=1), # b, 672, 3, 3
nn.BatchNorm2d(672),
nn.ReLU(True),
nn.ConvTranspose2d(672, 336, 2, stride=2), # b, 336, 6, 6
nn.BatchNorm2d(336),
nn.ReLU(True),
nn.ConvTranspose2d(336, 84, 2, stride=2), # b, 84, 12, 12
nn.BatchNorm2d(84),
nn.ReLU(True),
nn.ConvTranspose2d(84, 1, 3, stride=2,padding=2), # b, 1, 21, 21
nn.BatchNorm2d(1),
nn.ReLU(True)
)
def forward(self, x):
x = self.encoder(x)
x = self.decoder(x)
return x
class rdcnn_2_larger(nn.Module):
def __init__(self, drop_rate):
super(rdcnn_2_larger, self).__init__()
self.encoder = nn.Sequential(
nn.Conv2d(4, 84, 3, stride=2, padding=1), # b, 84, 11, 11
nn.BatchNorm2d(84),
nn.ReLU(True),
nn.Dropout(drop_rate) ,
nn.Conv2d(84, 168, 3, stride=2, padding=1), # b, 168, 6, 6
nn.BatchNorm2d(168),
nn.ReLU(True),
nn.Dropout(drop_rate) ,
nn.MaxPool2d(2, stride=1), # b, 168, 5, 5
nn.Conv2d(168, 336, 3, stride=2, padding=1), # b, 336, 3, 3
nn.BatchNorm2d(336),
nn.ReLU(True),
nn.Dropout(drop_rate) ,
nn.MaxPool2d(2, stride=1), # b, 336, 2, 2
nn.Dropout(drop_rate) ,
)
self.decoder = nn.Sequential(
nn.ConvTranspose2d(336, 672, 3, stride=2, padding=1), # b, 672, 3, 3
nn.BatchNorm2d(672),
nn.ReLU(True),
nn.ConvTranspose2d(672, 336, 2, stride=2), # b, 336, 6, 6
nn.BatchNorm2d(336),
nn.ReLU(True),
nn.ConvTranspose2d(336, 84, 2, stride=2), # b, 84, 12, 12
nn.BatchNorm2d(84),
nn.ReLU(True),
nn.ConvTranspose2d(84, 1, 3, stride=2,padding=2), # b, 1, 21, 21
)
def forward(self, x):
x = self.encoder(x)
x = self.decoder(x)
return x