Skip to content
fn

pixel_unshuffle

→Tensor
pixel_unshuffle(input: Tensor, downscale_factor: int)

Inverse of pixel_shuffle: pack spatial blocks into channels.

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

(N,C,H⋅r,W⋅r)  ⟶  (N,C⋅r2,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

inputTensor
Input of shape (*, C, H·r, W·r) — at least 3-D, any leading dims. Both spatial dims must be divisible by downscale_factor.
downscale_factorint
Spatial downscaling factor rr.

Returns

Tensor

Downsampled tensor of shape (*, 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)

Used by 2