API

 torch / nn / torch.nn


PixelShuffle

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

Rearranges elements in a tensor of shape (,C×r2,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) .

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

Look at 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: (N,L,Hin,Win)(N, L, H_{in}, W_{in}) where L=C×upscale_factor2L=C \times \text{upscale\_factor}^2

  • Output: (N,C,Hout,Wout)(N, C, H_{out}, W_{out}) where Hout=Hin×upscale_factorH_{out} = H_{in} \times \text{upscale\_factor} and Wout=Win×upscale_factorW_{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])

此页内容是否对您有帮助