class paddle.nn. PixelShuffle ( upscale_factor, data_format='NCHW', name=None ) [source]

PixelShuffle Layer

Rearranges elements in a tensor of shape \([N, C, H, W]\) to a tensor of shape \([N, C/upscale_factor^2, H*upscale_factor, W imes upscale_factor]\), or from shape \([N, H, W, C]\) to \([N, H imes upscale_factor, W imes upscale_factor, C/upscale_factor^2]\). This is useful for implementing efficient sub-pixel convolution with a stride of 1/upscale_factor. Please refer to the paper: Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network . by Shi et. al (2016) for more details.

  • upscale_factor (int) – factor to increase spatial resolution.

  • data_format (str, optional) – The data format of the input and output data. An optional string from: “NCHW”, “NHWC”. The default is “NCHW”. When it is “NCHW”, the data is stored in the order of: [batch_size, input_channels, input_height, input_width].

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

  • x: 4-D tensor with shape of \((N, C, H, W)\) or \((N, H, W, C)\).

  • out: 4-D tensor with shape of \((N, C/upscale_factor^2, H imes upscale_factor, W imes upscale_factor)\) or \((N, H imes upscale_factor, W imes upscale_factor, C/upscale_factor^2)\).


import paddle
import paddle.nn as nn

x = paddle.randn(shape=[2,9,4,4])
pixel_shuffle = nn.PixelShuffle(3)
out_var = pixel_shuffle(x)
out = out_var.numpy()
# (2, 1, 12, 12)
forward ( x )


Defines the computation performed at every call. Should be overridden by all subclasses.

  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments

extra_repr ( )


Extra representation of this layer, you can have custom implementation of your own layer.