-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_nn_module.py
More file actions
57 lines (39 loc) · 1.68 KB
/
class_nn_module.py
File metadata and controls
57 lines (39 loc) · 1.68 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
#####################################################################
#####################################################################
#####################################################################
class Swish(nn.Module):
def __init__(self, name=None):
super().__init__()
self.name = name
def forward(self, x):
return x * torch.sigmoid(x)
#####################################################################
class Attention_block(nn.Module):
def __init__(self,F_g,F_l,F_int):
super(Attention_block,self).__init__()
self.W_g = nn.Sequential(
nn.Conv2d(F_g, F_int, kernel_size=1,stride=1,padding=0,bias=True),
nn.BatchNorm2d(F_int)
)
self.W_xa = nn.Sequential(
nn.Conv2d(F_l, F_int, kernel_size=1,stride=1,padding=0,bias=True),
nn.BatchNorm2d(F_int)
)
self.psi = nn.Sequential(
nn.Conv2d(F_int, 1, kernel_size=1,stride=1,padding=0,bias=True),
nn.BatchNorm2d(1),
nn.Sigmoid()
)
self.relu = nn.ReLU(inplace=True)
def forward(self,g,xa):
g1 = self.W_g(g)
x1 = self.W_xa(xa)
psi = self.relu(g1+x1)
psi = self.psi(psi)
return xa*psi
#####################################################################
def get_efficientunet_b0(out_channels=2, concat_input=True, pretrained=True):
encoder = EfficientNet.encoder('efficientnet-b0', pretrained=pretrained)
model = EfficientUnet(encoder, out_channels=out_channels, concat_input=concat_input)
return model
#####################################################################