forked from ivanzzh/admm_uav_regression
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
157 lines (118 loc) · 4.89 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
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
class mainnet(nn.Module):
def __init__(self):
super(mainnet, self).__init__()
self.out1 = 64
self.out2 = 128
self.out3 = 256
self.relu = nn.ReLU(inplace=True)
# 3D Conv Operation
# self.bn3d_sub_1 = nn.BatchNorm3d(self.out1)
# self.bn3d_sub_2 = nn.BatchNorm3d(self.out2)
# self.bn3d_sub_3 = nn.BatchNorm3d(self.out3)
# 2D Conv Operation
self.bn3d_sub_1 = nn.BatchNorm2d(self.out1)
self.bn3d_sub_2 = nn.BatchNorm2d(self.out2)
self.bn3d_sub_3 = nn.BatchNorm2d(self.out3)
self.bn2d_main_1 = nn.BatchNorm2d(self.out1)
self.bn2d_main_2 = nn.BatchNorm2d(self.out2)
self.bn2d_main_3 = nn.BatchNorm2d(self.out3)
self.bn2d_dev_1 = nn.BatchNorm2d(self.out3)
self.bn2d_dev_2 = nn.BatchNorm2d(self.out2)
self.bn2d_dev_3 = nn.BatchNorm2d(self.out1)
self.bn1d_cat_1 = nn.BatchNorm1d(64*22*22)
self.max_pool1 = nn.MaxPool2d(kernel_size=2, stride=2)
# 3D Conv Operation
# self.max_pool_3d1 = nn.MaxPool3d(kernel_size=2, stride=2)
# 2D Conv Operation
self.max_pool_3d1 = nn.MaxPool2d(kernel_size=2, stride=2)
# 3D Conv Operation
# self.sub_conv1 = nn.Conv3d(in_channels=1, out_channels=self.out1, kernel_size=(4,4,10), stride=(2, 2, 2))
# self.sub_conv2 = nn.Conv3d(in_channels=self.out1, out_channels=self.out2, kernel_size=(2,2,5), stride=(1, 1, 2))
# self.sub_conv3 = nn.Conv3d(in_channels=self.out2, out_channels=self.out3, kernel_size=(2,2,5), stride=(1, 1, 2))
# 2D Conv Operation
self.sub_conv1 = nn.Conv2d(in_channels=60, out_channels=self.out1, kernel_size=(4,4), stride=(2, 2))
self.sub_conv2 = nn.Conv2d(in_channels=self.out1, out_channels=self.out2, kernel_size=(2,2), stride=(1, 1))
self.sub_conv3 = nn.Conv2d(in_channels=self.out2, out_channels=self.out3, kernel_size=(2,2), stride=(1, 1))
self.main_conv1 = nn.Conv2d(in_channels=1, out_channels=self.out1, kernel_size=2)
self.main_conv2 = nn.Conv2d(in_channels=self.out1, out_channels=self.out2, kernel_size=2)
self.main_conv3 = nn.Conv2d(in_channels=self.out2, out_channels=self.out3, kernel_size=2)
self.deconv1 = nn.ConvTranspose2d(512, 256, (3, 3), stride=(1, 1))
self.deconv2 = nn.ConvTranspose2d(256, 128, (2, 2), stride=(2, 2))
self.deconv3 = nn.ConvTranspose2d(128, 64, (2, 2), stride=(2, 2))
self.deconv4 = nn.ConvTranspose2d(64, 1, (1, 1), stride=(1, 1))
def deconv(self, x):
x = self.deconv1(x)
x = self.bn2d_dev_1(x)
x = self.relu(x)
# print("deconv1", x.shape)
x = self.deconv2(x)
x = self.bn2d_dev_2(x)
x = self.relu(x)
# print("deconv2", x.shape)
x = self.deconv3(x)
x = self.bn2d_dev_3(x)
x = self.relu(x)
# print("deconv3", x.shape)
x = self.deconv4(x)
# print("deconv4", x.shape)
return x
def subnet(self,x):
# 2D Conv Operation
x = torch.squeeze(x)
# 3D Conv Operation
# x = x.view(4, 1, 60, 100, 100)
# x = x.permute(0,1,3,4,2)
# x = x.permute(0, 3, 1, 2)
x = self.sub_conv1(x)
x = self.bn3d_sub_1(x)
x = self.relu(x)
x = self.sub_conv2(x)
x = self.bn3d_sub_2(x)
x = self.relu(x)
# print("conv2", x.shape)
x = self.max_pool_3d1(x)
# print("pool 1", x.shape)
x = self.sub_conv3(x)
x = self.bn3d_sub_3(x)
x = self.relu(x)
# print("conv3", x.shape)
return x
def mainnet(self, x):
x = self.main_conv1(x)
# print("conv1", x.shape)
x = self.bn2d_main_1(x)
x = self.relu(x)
x = self.max_pool1(x)
# print("pool 1", x.shape)
x = self.main_conv2(x)
# print("main conv2", x.shape)
x = self.bn2d_main_2(x)
x = self.relu(x)
x = self.max_pool1(x)
# print("pool 1", x.shape)
x = self.main_conv3(x)
x = self.bn2d_main_3(x)
x = self.relu(x)
# print("main conv3", x.shape)
# x = self.max_pool2(x)
#print("pool 2", x.shape)
return x
def forward(self, subx, mainx):
subx = self.subnet(subx)
subx = torch.squeeze(subx)
mainx = self.mainnet(mainx)
# print("subx", subx.shape)
# print("mainx", mainx.shape)
x = torch.cat((subx, mainx), 1)
x = self.deconv(x)
x = x.view(-1,100,100)
return x
if __name__ == "__main__":
subx = torch.rand(2,1, 100, 100,60)
mainx = torch.rand(2,1,100, 100)
net = mainnet()
output = net(subx, mainx)
print(output.shape)
#[2, 256, 23, 23]