Pixel Shuffle在Pytorch中的实现
Pixel shuffle的原理这里不着重探讨,详细原理请参考论文:Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network。
这里先给出pytorch中pixel shuffle的代码。可以看到,代码的核心部分是permute操作,下面主要讨论pytorch如何通过该操作完成pixel shuffle的。(默认读者已经知道view/permute/contiguous等基础操作)
def pixel_shuffle(input, upscale_factor):
r"""Rearranges elements in a tensor of shape ``[*, C*r^2, H, W]`` to a
tensor of shape ``[C, H*r, W*r]``.
See :class:`~torch.nn.PixelShuffle` for details.
Args:
input (Variable): Input
upscale_factor (int): factor to increase spatial resolution by
Examples::
>>> ps = nn.PixelShuffle(3)
>>> input = autograd.Variable(torch.Tensor(1, 9, 4, 4))
>>> output = ps