Convolutional 1D (Conv1D)#
API#
- class warp_nn.modules.layers.Conv1D(
- in_channels: int,
- out_channels: int,
- kernel_size: int,
- *,
- stride: int = 1,
- padding: int = 0,
- dilation: int = 1,
- groups: int = 1,
- bias: bool = True,
- initialize_parameters: bool = True,
- requires_grad: bool = True,
Bases:
ModuleApply a 1D convolution.
\[\text{Conv1D}(x)_{i, j} = b_j + \sum_{c = 0}^{C_{in} - 1} W_{j, c} \star x_{i, c}\]where \(\star\) is the valid cross-correlation operator, \(i\) indexes the batch dimension, \(j\) the output channel, \(c\) the input channel (for
groups = 1), and \(C_{in}\) isin_channels.
Learnable parameters:
Name
Shape
Description
\(W\)
weight(out_channels, in_channels / groups, kernel_size)Weights
\(b\)
bias(out_channels, 1)Bias. Only if
biasis trueThe parameters are initialized from the uniform distribution \(u(-k, k)\) where \(k = \sqrt{\frac{groups}{\text{in\_channels * kernel\_size}}}\)
- Parameters:
in_channels – The number of input channels.
out_channels – The number of output channels.
kernel_size – The size of the kernel.
stride – The stride of the convolution.
padding – The padding of the convolution.
dilation – The dilation of the convolution.
groups – The number of groups. Both, the
in_channelsand theout_channelsarguments must be divisible bygroups.bias – Whether to include a bias term.
initialize_parameters – Whether to initialize the parameters with their default/initial values. If false, the parameters are left as uninitialized memory, and reading them (e.g. during a forward pass) before loading their values (e.g. from a state dictionary) is undefined behavior.
requires_grad – Whether the parameters and the cached output arrays of the module require gradients.
- __call__(
- input: array,
Forward pass of the module.
- Parameters:
input – The input array, with shape
(batch_size, in_channels, in_signal_length).- Returns:
The output array, with shape
(batch_size, out_channels, out_signal_length)where:
\[L_{out} = \left\lfloor \frac{L_{in} + 2 \, \text{padding} - \text{dilation} \, (\text{kernel\_size} - 1) - 1}{\text{stride}} \right\rfloor + 1\]