fn

pixel_unshuffle

Tensor
pixel_unshuffle(x: Tensor, downscale_factor: int)
source

Inverse of pixel_shuffle: pack spatial blocks into channels.

Folds each r×rr \times r spatial block into extra channels, shrinking the spatial extent by rr along each axis:

(N,C,Hr,Wr)    (N,Cr2,H,W)(N, C, H \cdot r, W \cdot r) \;\longrightarrow\; (N, C \cdot r^2, H, W)

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

xTensor
4-D input of shape (N, C, H·r, W·r). Both spatial dims must be divisible by downscale_factor.
downscale_factorint
Spatial downscaling factor rr.

Returns

Tensor

Downsampled 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)