mindspore.nn.PixelShuffle

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

Applies a pixelshuffle operation over an input signal composed of several input planes. This is useful for implementiong efficient sub-pixel convolution with a stride of \(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.

Parameters

upscale_factor (int) – factor to increase spatial resolution by, and is a positive integer.

Inputs:
  • x (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 x is not divisible by upscale_factor squared.

  • TypeError – If the dimension of x is less than 3.

Supported Platforms:

Ascend GPU CPU

Examples

>>> input_x = np.arange(3 * 2 * 9 * 4 * 4).reshape((3, 2, 9, 4, 4))
>>> input_x = mindspore.Tensor(input_x, mindspore.dtype.int32)
>>> pixel_shuffle = nn.PixelShuffle(3)
>>> output = pixel_shuffle(input_x)
>>> print(output.shape)
(3, 2, 1, 12, 12)