- mmcv.ops.upfirdn2d(input: torch.Tensor, filter: torch.Tensor, up: int = 1, down: int = 1, padding: Union[int, List[int]] = 0, flip_filter: bool = False, gain: Union[float, int] = 1, use_custom_op: bool = True)¶
Pad, upsample, filter, and downsample a batch of 2D images.
Performs the following sequence of operations for each channel:
Upsample the image by inserting N-1 zeros after each pixel (up).
2. Pad the image with the specified number of zeros on each side (padding). Negative padding corresponds to cropping the image.
3. Convolve the image with the specified 2D FIR filter (f), shrinking it so that the footprint of all output pixels lies within the input image.
Downsample the image by keeping every Nth pixel (down).
- This sequence of operations bears close resemblance to
The fused op is considerably more efficient than performing the same calculation using standard PyTorch ops. It supports gradients of arbitrary order.
input (torch.Tensor) – Float32/float64/float16 input tensor of the shape [batch_size, num_channels, in_height, in_width].
filter (torch.Tensor) – Float32 FIR filter of the shape [filter_height, filter_width] (non-separable), [filter_taps] (separable), or None (identity).
up (int) – Integer upsampling factor. Can be a single int or a list/tuple [x, y]. Defaults to 1.
down (int) – Integer downsampling factor. Can be a single int or a list/tuple [x, y]. Defaults to 1.
padding (int | tuple[int]) – Padding with respect to the upsampled image. Can be a single number or a list/tuple [x, y] or [x_before, x_after, y_before, y_after]. Defaults to 0.
flip_filter (bool) – False = convolution, True = correlation. Defaults to False.
gain (int) – Overall scaling factor for signal magnitude. Defaults to 1.
use_custom_op (bool) – Whether to use customized op. Defaults to True.
Tensor of the shape [batch_size, num_channels, out_height, out_width]