fn
pixel_unshuffle
→Tensorpixel_unshuffle(x: Tensor, downscale_factor: int)Inverse of pixel_shuffle: pack spatial blocks into channels.
Folds each spatial block into r² extra
channels, shrinking the spatial extent by along each axis:
Useful as a strided "downsampling without information loss" stage in invertible architectures (e.g. RealNVP, normalising flows) and as the analyzer step in sub-pixel encoders.
Parameters
xTensor4-D input of shape
(N, C, H·r, W·r). Both spatial dims
must be divisible by downscale_factor.downscale_factorintSpatial downscaling factor .
Returns
TensorDownsampled tensor of shape (N, C·r², H, W).
Notes
Like pixel_shuffle, this is a reshape + permute + reshape
chain — completely lossless and free of multiply-add cost.
Examples
>>> import lucid
>>> from lucid.nn.functional import pixel_unshuffle
>>> x = lucid.randn(1, 3, 16, 16)
>>> y = pixel_unshuffle(x, downscale_factor=2)
>>> y.shape
(1, 12, 8, 8)