espnet2.enh.layers.ncsnpp_utils.upfirdn2d.upfirdn2d
Less than 1 minute
espnet2.enh.layers.ncsnpp_utils.upfirdn2d.upfirdn2d
espnet2.enh.layers.ncsnpp_utils.upfirdn2d.upfirdn2d(input, kernel, up=1, down=1, pad=(0, 0))
UpFirDn2d functions for upsampling, padding, FIR filter, and downsampling.
These functions are designed to perform a series of operations that include upsampling, applying a FIR filter, and downsampling in a two-dimensional space. The implementation is adapted from the StyleGAN2 repository (https://github.com/NVlabs/stylegan2).
- Parameters:
- input (torch.Tensor) – The input tensor of 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.
- kernel (torch.Tensor) – The FIR filter kernel tensor of shape (KH, KW) where KH is the height and KW is the width of the kernel.
- up (int , optional) – The upsampling factor for both dimensions. Default is 1.
- down (int , optional) – The downsampling factor for both dimensions. Default is 1.
- pad (tuple , optional) – A tuple of two integers specifying the padding (pad_y0, pad_y1) for height and (pad_x0, pad_x1) for width. Default is (0, 0).
- Returns: The output tensor after applying the upsampling, FIR filter, and downsampling operations. The output shape is (N, C, out_h, out_w) where out_h and out_w are calculated based on the input dimensions and the specified factors.
- Return type: torch.Tensor
Examples
>>> input_tensor = torch.randn(1, 3, 64, 64) # Example input
>>> kernel = torch.ones((3, 3)) # Example kernel
>>> output_tensor = upfirdn2d(input_tensor, kernel, up=2, down=1, pad=(1, 1))
>>> print(output_tensor.shape) # Output shape will vary based on input
NOTE
This function assumes that the input tensor has at least four dimensions (N, C, H, W). The kernel must be a 2D tensor.
- Raises:
- ValueError – If the input tensor or kernel does not have the
- expected dimensions. –