espnet2.enh.layers.ncsnpp_utils.up_or_down_sampling.naive_downsample_2d
Less than 1 minute
espnet2.enh.layers.ncsnpp_utils.up_or_down_sampling.naive_downsample_2d
espnet2.enh.layers.ncsnpp_utils.up_or_down_sampling.naive_downsample_2d(x, factor=2)
Downsample a 4D tensor (batch of 2D images) by averaging.
This function takes a batch of 2D images and downsamples each image by a specified factor using a naive averaging method. The input tensor should have the shape [N, C, H, W], where N is the batch size, C is the number of channels, H is the height, and W is the width. The output tensor will have the shape [N, C, H // factor, W // factor].
- Parameters:
- x (torch.Tensor) – Input tensor of shape [N, C, H, W] to be downsampled.
- factor (int , optional) – The downsampling factor. Must be a positive integer (default is 2).
- Returns: A downsampled tensor of shape [N, C, H // factor, W // factor].
- Return type: torch.Tensor
Examples
>>> import torch
>>> x = torch.rand(1, 3, 4, 4) # A single 4x4 image with 3 channels
>>> downsampled_x = naive_downsample_2d(x, factor=2)
>>> print(downsampled_x.shape) # Output will be [1, 3, 2, 2]