pixel_shuffle
→Tensorpixel_shuffle(x: Tensor, upscale_factor: int)Sub-pixel upsampling: rearrange channels into spatial resolution.
Reshapes a low-resolution multi-channel feature map into a higher-resolution map with fewer channels, without introducing any interpolation. Originally proposed by Shi et al., 2016 ("Real-Time Single Image and Video Super-Resolution"), this is the canonical decoder layer in single-image super-resolution and many GAN / diffusion upsamplers.
Concretely, with upscale factor :
Each patch in the output is taken from a block of channels in the input.
Parameters
xTensor(N, C·r², H, W). The channel dimension
must be divisible by upscale_factor².upscale_factorintReturns
TensorUpsampled tensor of shape (N, C, H·r, W·r).
Notes
The transformation is a pure reshape + permute + reshape — autograd
flows through ReshapeBackward and PermuteBackward with no
custom gradient. Because no convolution is involved, the operator
is essentially free; it is most often preceded by a convolution
that produces the required C·r² channels.
Examples
>>> import lucid
>>> from lucid.nn.functional import pixel_shuffle
>>> x = lucid.randn(1, 12, 8, 8) # C=3, r=2 → C·r²=12
>>> y = pixel_shuffle(x, upscale_factor=2)
>>> y.shape
(1, 3, 16, 16)