espnet2.enh.layers.ncsnpp_utils.layers.ncsn_conv1x1
Less than 1 minute
espnet2.enh.layers.ncsnpp_utils.layers.ncsn_conv1x1
espnet2.enh.layers.ncsnpp_utils.layers.ncsn_conv1x1(in_planes, out_planes, stride=1, bias=True, dilation=1, init_scale=1.0, padding=0)
1x1 convolution. Same as NCSNv1/v2.
This function creates a 1x1 convolutional layer with specified parameters and initializes its weights and biases. The initialization is scaled by the init_scale parameter. If init_scale is zero, it defaults to a very small value to avoid zero initialization.
- Parameters:
- in_planes (int) – Number of input channels.
- out_planes (int) – Number of output channels.
- stride (int , optional) – Stride of the convolution. Default is 1.
- bias (bool , optional) – If True, adds a learnable bias to the output. Default is True.
- dilation (int , optional) – Spacing between kernel elements. Default is 1.
- init_scale (float , optional) – Scale factor for weight initialization. Default is 1.0.
- padding (int , optional) – Implicit zero padding to be added on both sides. Default is 0.
- Returns: A 1x1 convolutional layer with initialized weights and biases.
- Return type: torch.nn.Conv2d
Examples
>>> conv_layer = ncsn_conv1x1(in_planes=64, out_planes=128, stride=1)
>>> print(conv_layer)
Conv2d(64, 128, kernel_size=(1, 1), stride=(1, 1))
NOTE
The weight and bias are initialized to init_scale. If init_scale is set to zero, it is overridden to a very small value (1e-10) to prevent zero initialization.
- Raises:ValueError – If any argument is invalid (not applicable in this case).