pixel_shuffle

paddle.fluid.layers.pixel_shuffle(x, upscale_factor)[source]

This op rearranges elements in a tensor of shape [N, C, H, W] to a tensor of shape [N, C/r**2, H*r, W*r]. This is useful for implementing efficient sub-pixel convolution with a stride of 1/r. 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
  • x (Variable) – 4-D tensor, the data type should be float32 or float64.

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

Returns

Reshaped tensor according to the new dimension.

Return type

Out(Variable)

Raises

ValueError – If the square of upscale_factor cannot divide the channels of input.

Examples

# declarative mode
import paddle.fluid as fluid
import numpy as np
input = fluid.data(name="input", shape=[2,9,4,4])
output = fluid.layers.pixel_shuffle(x=input, upscale_factor=3)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())

input_data = np.random.rand(2,9,4,4).astype("float32")
output_data = exe.run(fluid.default_main_program(),
    feed={"input":input_data},
    fetch_list=[output],
    return_numpy=True)

# print(output.shape)
# (2L, 1L, 12L, 12L)