MCPcopy Create free account
hub / github.com/BorealisAI/scaleformer / _TemporalBlock2

Class _TemporalBlock2

models/NHits.py:56–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54 return self.causalconv(x)
55
56class _TemporalBlock2(nn.Module):
57 def __init__(self, n_inputs, n_outputs, kernel_size, stride, dilation, padding, dropout=0.2):
58 super(_TemporalBlock2, self).__init__()
59 self.causalconv1 = CausalConv1d(in_channels=n_inputs, out_channels=n_outputs,
60 kernel_size=kernel_size, stride=stride, padding=padding,
61 dilation=dilation, activation='ReLU', with_weight_norm=True)
62
63 self.causalconv2 = CausalConv1d(in_channels=n_outputs, out_channels=n_outputs,
64 kernel_size=kernel_size, stride=stride, padding=padding,
65 dilation=dilation, activation='ReLU', with_weight_norm=True)
66
67 self.net = nn.Sequential(self.causalconv1, nn.Dropout(dropout),
68 self.causalconv2, nn.Dropout(dropout))
69
70 self.downsample = nn.Conv1d(n_inputs, n_outputs, 1) if n_inputs != n_outputs else None
71 self.relu = nn.ReLU()
72 self.init_weights()
73
74 def init_weights(self):
75 self.causalconv1.conv.weight.data.normal_(0, 0.01)
76 self.causalconv2.conv.weight.data.normal_(0, 0.01)
77 if self.downsample is not None:
78 self.downsample.weight.data.normal_(0, 0.01)
79
80 def forward(self, x):
81 out = self.net(x)
82 res = x if self.downsample is None else self.downsample(x)
83 return self.relu(out + res)
84
85
86class _TemporalConvNet(nn.Module):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected