-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_2.py
92 lines (74 loc) · 2.35 KB
/
model_2.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
import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
# add DenseNet structure
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
# self.x = x
self.block0 = nn.Sequential(
# input image 96x96
nn.ReLU(),
nn.Conv2d(3, 64, (5, 5), (1, 1), (2, 2)),
nn.LeakyReLU(0.1),
nn.BatchNorm2d(64),
)
self.block1 = nn.Sequential(
nn.Conv2d(64, 64, (3, 3), (1, 1), (1, 1)),
nn.LeakyReLU(0.1),
nn.BatchNorm2d(64),
)
self.block2 = nn.Sequential(
nn.Conv2d(64, 64, (3, 3), (1, 1), (1, 1)),
nn.LeakyReLU(0.1),
nn.BatchNorm2d(64),
)
self.block3 = nn.Sequential(
nn.Conv2d(64, 32, (3, 3), (1, 1), (1, 1)),
nn.LeakyReLU(0.1),
nn.BatchNorm2d(32),
nn.Conv2d(32, 4, (1, 1), (1, 1)),
nn.LeakyReLU(0.1),
nn.BatchNorm2d(4),
)
self.side0_3 = nn.Sequential(
nn.Conv2d(64, 4, (1, 1), (1, 1)),
nn.LeakyReLU(0.1),
nn.BatchNorm2d(4),
)
self.side1_3 = nn.Sequential(
nn.Conv2d(64, 4, (1, 1), (1, 1)),
nn.LeakyReLU(0.1),
nn.BatchNorm2d(4),
)
self.side2_3 = nn.Sequential(
nn.Conv2d(64, 4, (1, 1), (1, 1)),
nn.LeakyReLU(0.1),
nn.BatchNorm2d(4),
)
self.fc = nn.Sequential(
nn.Conv2d(4, 1, (1, 1), (1, 1)),
nn.LeakyReLU(0.1),
nn.BatchNorm2d(1),
nn.Sigmoid()
)
def forward(self, x):
x=x.float()
out = self.block0(x) # 64x96x96
res0_1 = out
res0_2 = out
res0_3 = self.side0_3(out)
out = self.block1(out) # 64x96x96
res1_2 = out
res1_3 = self.side1_3(out)
out = out + res0_1
out = self.block2(out) # 64x96x96
res2_3 = self.side2_3(out)
out = out + res0_2 + res1_2
out = self.block3(out) # 4x96x96
out = out + res0_3 + res1_3 + res2_3
out = self.fc(out)
return out
def _initialize_weights(self):
pass