pytorch / 1.8.0 / generated / torch.nn.pixelshuffle.html /

PixelShuffle

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

Rearranges elements in a tensor of shape ( , C × r 2 , H , W ) (*, C \times r^2, H, W) to a tensor of shape ( , C , H × r , W × r ) (*, C, H \times r, W \times r) , where r is an upscale factor.

This is useful for implementing efficient sub-pixel convolution with a stride of 1 / r 1/r .

See 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

upscale_factor (int) – factor to increase spatial resolution by

Shape:
  • Input: ( , C i n , H i n , W i n ) (*, C_{in}, H_{in}, W_{in}) , where * is zero or more batch dimensions
  • Output: ( , C o u t , H o u t , W o u t ) (*, C_{out}, H_{out}, W_{out}) , where
C o u t = C i n ÷ upscale_factor 2 C_{out} = C_{in} \div \text{upscale\_factor}^2
H o u t = H i n × upscale_factor H_{out} = H_{in} \times \text{upscale\_factor}
W o u t = W i n × upscale_factor W_{out} = W_{in} \times \text{upscale\_factor}

Examples:

>>> pixel_shuffle = nn.PixelShuffle(3)
>>> input = torch.randn(1, 9, 4, 4)
>>> output = pixel_shuffle(input)
>>> print(output.size())
torch.Size([1, 1, 12, 12])

© 2019 Torch Contributors
Licensed under the 3-clause BSD License.
https://pytorch.org/docs/1.8.0/generated/torch.nn.PixelShuffle.html