-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvis_decoder.py
More file actions
58 lines (40 loc) · 1.69 KB
/
vis_decoder.py
File metadata and controls
58 lines (40 loc) · 1.69 KB
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
import torch
import torch.nn as nn
import torchvision
class Doubleconv(nn.Module):
def __init__(self, in_channels, out_channels, mid_channels=None):
super().__init__()
if not mid_channels:
mid_channels = out_channels
self.double_conv = nn.Sequential(
nn.Conv2d(in_channels, mid_channels, kernel_size=3, padding=1, bias=False),
nn.ReLU(inplace=True),
nn.Conv2d(mid_channels, out_channels, kernel_size=3, padding=1, bias=False),
nn.ReLU(inplace=True)
)
def forward(self, x):
return self.double_conv(x)
class Decoder(nn.Module):
def __init__(self):
super(Decoder, self).__init__()
self.layer1 = Doubleconv(in_channels=1792, out_channels=512)
self.up1 = nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True)
self.layer2 = Doubleconv(in_channels=512, out_channels=256)
self.up2 = nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True)
self.layer3 = Doubleconv(in_channels=256, out_channels=128)
self.layer4 = Doubleconv(in_channels=128, out_channels=64)
self.ouput_layer = nn.Sequential(nn.Conv2d(64, 3, kernel_size=3, padding=1, bias=False))
def forward(self, input_):
out1 = self.layer1(input_)
out1 = self.up1(out1)
out2 = self.layer2(out1)
out2 = self.up2(out2)
out3 = self.layer3(out2)
out4 = self.layer4(out3)
out5 = self.ouput_layer(out4)
return out5
if __name__ =="__main__":
image = torch.rand(1,1792,64,64)
model = Decoder()
output = model(image)
print(output.shape)