espnet2.enh.layers.ncsnpp_utils.up_or_down_sampling.upsample_conv_2d
Less than 1 minute
espnet2.enh.layers.ncsnpp_utils.up_or_down_sampling.upsample_conv_2d
espnet2.enh.layers.ncsnpp_utils.up_or_down_sampling.upsample_conv_2d(x, w, k=None, factor=2, gain=1)
Fused upsample_2d() followed by tf.nn.conv2d().
Padding is performed only once at the beginning, not between the operations. The fused operation is considerably more efficient than performing the same calculation using standard TensorFlow ops. It supports gradients of arbitrary order.
- Parameters:
- x – Input tensor of the shape [N, C, H, W] or [N, H, W, C].
- w – Weight tensor of the shape [filterH, filterW, inChannels, outChannels]. Grouped convolution can be performed by inChannels = x.shape[0] // numGroups.
- k – FIR filter of the shape [firH, firW] or [firN] (separable). The default is [1] * factor, which corresponds to nearest-neighbor upsampling.
- factor – Integer upsampling factor (default: 2).
- gain – Scaling factor for signal magnitude (default: 1.0).
- Returns: Tensor of the shape [N, C, H * factor, W * factor] or [N, H * factor, W * factor, C], and same datatype as x.
Examples
>>> x = torch.randn(1, 3, 4, 4) # A batch of 1 image with 3 channels
>>> w = torch.randn(3, 3, 3, 3) # Example weight tensor
>>> output = upsample_conv_2d(x, w, factor=2) # Upsampling by a factor of 2
NOTE
Ensure that the input tensor x and weight tensor w are correctly shaped for the operation to work without errors.
- Raises:
- AssertionError – If factor is not an integer greater than or
- equal to 1**, or** if the weight tensor w does not have 4 dimensions. –