mindspore.nn.PixelShuffle

class mindspore.nn.PixelShuffle(upscale_factor)[source]

Applies the PixelShuffle operation over input which implements sub-pixel convolutions with stride \(1/r\) . For more details, refer to Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network .

Typically, the input is of shape \((*, C \times r^2, H, W)\) , and the output is of shape \((*, C, H \times r, W \times r)\), where r is an upscale factor and * is zero or more batch dimensions.

Note

The dimension of input Tensor on Ascend should be less than 7.

Parameters

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

Inputs:
  • input (Tensor) - Tensor of shape \((*, C \times r^2, H, W)\) . The dimension of x is larger than 2, and the length of third to last dimension can be divisible by upscale_factor squared.

Outputs:
  • output (Tensor) - Tensor of shape \((*, C, H \times r, W \times r)\) .

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

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

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

  • TypeError – If input is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore as ms
>>> import numpy as np
>>> input_x = np.arange(3 * 2 * 8 * 4 * 4).reshape((3, 2, 8, 4, 4))
>>> input_x = ms.Tensor(input_x, ms.dtype.int32)
>>> pixel_shuffle = ms.nn.PixelShuffle(2)
>>> output = pixel_shuffle(input_x)
>>> print(output.shape)
(3, 2, 2, 8, 8)