PixelUnshuffle

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

Rearranges elements in a tensor of shape \([N, C, H, W]\) to a tensor of shape \([N, r^2C, H/r, W/r]\), or from shape \([N, H, W, C]\) to \([N, H/r, W/r, r^2C]\), where \(r\) is the downscale factor. This operation is the reversion of PixelShuffle operation. 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.

Parameters
  • downscale_factor (int) – Factor to decrease spatial resolution.

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

  • name (str, optional) – Name for the operation (optional, default is None). Normally there is no need for user to set this property. For more information, please refer to Name.

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

  • out: 4-D tensor with shape of \([N, r^2C, H/r, W/r]\) or \([N, H/r, W/r, r^2C]\), where \(r\) is downscale_factor.

Examples

>>> import paddle
>>> import paddle.nn as nn

>>> x = paddle.randn([2, 1, 12, 12])
>>> pixel_unshuffle = nn.PixelUnshuffle(3)
>>> out = pixel_unshuffle(x)
>>> print(out.shape)
[2, 9, 4, 4]
forward ( x )

forward

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

Parameters
  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments

extra_repr ( )

extra_repr

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