in src/hyperconv.py [0:0]
def __init__(self, input_size, ch_in, ch_out, kernel_size, dilation=1):
'''
HyperConv implements a temporal convolution that has different convolution weights for each time step.
:param input_size: (int) dimension of the weight generating input variable
:param ch_in: (int) number of input channels of the temporal convolution
:param ch_out: (int) number of output channels of the temporal convolution
:param kernel_size: (int) kernel size of the temporal convolution
:param dilation: (int) dilation of the temporal convolution
'''
super().__init__()
weight_regressor_hidden_size = 32
self.ch_in = ch_in
self.ch_out = ch_out
self.kernel_size = kernel_size
self.dilation = dilation
self.weight_model = nn.Sequential(
nn.Conv1d(input_size, weight_regressor_hidden_size, kernel_size=1),
nn.ReLU(),
nn.Conv1d(weight_regressor_hidden_size, ch_in * ch_out * kernel_size, kernel_size=1)
)
self.bias_model = nn.Sequential(
nn.Conv1d(input_size, weight_regressor_hidden_size, kernel_size=1),
nn.ReLU(),
nn.Conv1d(weight_regressor_hidden_size, ch_out, kernel_size=1)
)
# initialize weights such that regressed weights are distributed in a suitable way for sine activations
self.weight_model[0].weight.data.zero_()
self.weight_model[0].bias.data.zero_()
self.weight_model[-1].bias.data.uniform_(-np.sqrt(6.0/(self.ch_in*self.kernel_size)),
np.sqrt(6.0/(self.ch_in*self.kernel_size)))