espnet2.enh.layers.ncsnpp_utils.up_or_down_sampling.naive_upsample_2d
Less than 1 minute
espnet2.enh.layers.ncsnpp_utils.up_or_down_sampling.naive_upsample_2d
espnet2.enh.layers.ncsnpp_utils.up_or_down_sampling.naive_upsample_2d(x, factor=2)
Perform naive 2D upsampling on a tensor.
This function takes an input tensor representing a batch of 2D images and upsamples each image by the specified factor using nearest-neighbor interpolation. The output tensor will have its height and width multiplied by the upsampling factor.
- Parameters:
- x (torch.Tensor) – Input tensor of shape [N, C, H, W], where:
- N: Number of images in the batch.
- C: Number of channels in each image.
- H: Height of each image.
- W: Width of each image.
- factor (int) – Upsampling factor. Default is 2.
- x (torch.Tensor) – Input tensor of shape [N, C, H, W], where:
- Returns: Output tensor of shape [N, C, H * factor, W * factor].
- Return type: torch.Tensor
Examples
>>> x = torch.rand(1, 3, 4, 4) # A batch of 1 image with 3 channels
>>> upsampled = naive_upsample_2d(x, factor=2)
>>> print(upsampled.shape)
torch.Size([1, 3, 8, 8]) # The output shape after upsampling
NOTE
This method is a simple and efficient way to increase the resolution of images but may not preserve the quality as well as more advanced methods.