MCPcopy Create free account
hub / github.com/RolnickLab/climart / Multiscale_Module

Class Multiscale_Module

climart/models/modules/additional_layers.py:12–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12class Multiscale_Module(nn.Module):
13
14 def __init__(self, in_channels=None, channels_per_layer=None, out_shape=None,
15 dil_rate=1, use_act=False, *args, **kwargs):
16 super().__init__()
17 self.out_shape = out_shape
18 self.use_act = use_act
19
20 self.multi_3 = nn.Conv1d(in_channels=in_channels, out_channels=channels_per_layer,
21 kernel_size=5, stride=1, dilation=dil_rate)
22 self.multi_5 = nn.Conv1d(in_channels=in_channels, out_channels=channels_per_layer,
23 kernel_size=6, stride=1, dilation=dil_rate)
24 self.multi_7 = nn.Conv1d(in_channels=in_channels, out_channels=channels_per_layer,
25 kernel_size=9, stride=1, dilation=dil_rate)
26 self.after_concat = nn.Conv1d(in_channels=int(channels_per_layer * 3),
27 out_channels=int(channels_per_layer / 2), kernel_size=1, stride=1)
28 self.gap = GAP()
29
30 def forward(self, x):
31 x_3 = self.multi_3(x)
32 x_5 = self.multi_5(x)
33 x_7 = self.multi_7(x)
34 x_3 = F.adaptive_max_pool1d(x_3, self.out_shape)
35 x_5 = F.adaptive_max_pool1d(x_5, self.out_shape)
36 x_7 = F.adaptive_max_pool1d(x_7, self.out_shape)
37 x_concat = torch.cat((x_3, x_5, x_7), 1)
38 x_concat = self.after_concat(x_concat)
39
40 if self.use_act:
41 return torch.sigmoid(self.gap(x)) * x_concat
42 else:
43 return x_concat
44
45
46class GAP():

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected