-
Notifications
You must be signed in to change notification settings - Fork 0
/
harnet.py
72 lines (60 loc) · 3.06 KB
/
harnet.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
import torch
import torch.nn as nn
import torch.nn.functional as F
class HARNet(nn.Module):
def __init__(self):
super(HARNet, self).__init__()
self.conv_block = nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=1, bias=True)
model1 = []
for _ in range(19):
model1 += [nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=1, bias=True)]
self.conv_block1 = nn.Sequential(*model1)
model2 = []
for _ in range(19):
model2 += [nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=1, bias=True)]
self.conv_block2 = nn.Sequential(*model2)
model3 = []
for _ in range(19):
model3 += [nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=1, bias=True)]
self.conv_block3 = nn.Sequential(*model3)
model4 = []
for _ in range(19):
model4 += [nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=1, bias=True)]
self.conv_block4 = nn.Sequential(*model4)
self.conv1 = nn.Conv2d(1, 128, kernel_size=3, stride=1, padding=1, bias=True)
self.conv2 = nn.Conv2d(128, 64, kernel_size=3, stride=1, padding=1, bias=True)
self.conv3 = nn.Conv2d(192, 64, kernel_size=3, stride=1, padding=1, bias=True)
self.conv4 = nn.Conv2d(256, 64, kernel_size=3, stride=1, padding=1, bias=True)
self.conv5 = nn.Conv2d(320, 64, kernel_size=3, stride=1, padding=1, bias=True)
self.conv6 = nn.Conv2d(384, 1, kernel_size=3, stride=1, padding=1, bias=True)
self.relu = nn.ReLU()
def forward(self, x):
residual = x
output = self.relu(self.conv1(x)) # (1, 128, 400, 400)
block_residual = output # skip connection
output = self.relu(self.conv2(output)) # (1, 64, 400, 400)
# for _ in range(19):
# output = self.relu(self.conv_block(output)) # (1, 64, 400, 400)
output = self.relu(self.conv_block1(output))
output = torch.cat((output, block_residual), 1) # (1, 192, 400, 400)
block_residual = output
output = self.relu(self.conv3(output)) # (1, 64, 400, 400)
# for _ in range(19):
# output = self.relu(self.conv_block(output)) # (1, 64, 400, 400)
output = self.relu(self.conv_block2(output))
output = torch.cat((output, block_residual), 1) # (1, 256, 400, 400)
block_residual = output
output = self.relu(self.conv4(output)) # (1, 64, 400, 400)
# for _ in range(19):
# output = self.relu(self.conv_block(output)) # (1, 64, 400, 400)
output = self.relu(self.conv_block3(output))
output = torch.cat((output, block_residual), 1) # (1, 320, 400, 400)
block_residual = output
output = self.relu(self.conv5(output)) # (1, 64, 400, 400)
# for _ in range(19):
# output = self.relu(self.conv_block(output)) # (1, 64, 400, 400)
output = self.relu(self.conv_block4(output))
output = torch.cat((output, block_residual), 1) # (1, 384, 400, 400)
output = self.conv6(output)
output += residual
return output