mindspore.mint.nn.functional.pixel_shuffle

View Source On Gitee
mindspore.mint.nn.functional.pixel_shuffle(input, upscale_factor) Tensor[source]

Rearrange elements in a tensor according to an upscaling factor.

Rearranges elements in a tensor of shape (,C×r2,H,W) to a tensor of shape (,C,H×r,W×r), where r is an upscale factor.

This is useful for implementing efficient sub-pixel convolution with a stride of 1/r.

For detailed introduction to the pixel_shuffle algorithm, refer to Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network .

Warning

This is an experimental API that is subject to change or deletion.

Parameters
  • input (Tensor) – Tensor of shape (,C×r2,H,W) . The dimension of input is larger than 2, and the length of third to last dimension can be divisible by the square of upscale_factor.

  • upscale_factor (int) – factor to shuffle the input Tensor, and is a positive integer. upscale_factor is the above-mentioned r.

Returns

  • output (Tensor) - Tensor of shape (,C,H×r,W×r) .

Raises
  • ValueError – If upscale_factor is not a positive integer.

  • ValueError – If the length of third to last dimension is not divisible by the square of upscale_factor.

  • ValueError – If the dimension of input is less than 3.

Supported Platforms:

Ascend

Examples

>>> from mindspore import mint
>>> input = mint.randn(1, 9, 4, 4)
>>> output = mint.nn.functional.pixel_shuffle(input, 3)
>>> print(output.shape)
    (1, 1, 12, 12)