class
PixelUnshuffle
extends
ModulePixelUnshuffle(downscale_factor: int)Reverse the sub-pixel rearrangement performed by PixelShuffle.
PixelUnshuffle is the exact inverse of PixelShuffle: it takes a
high-resolution input with channels and spatial size
and folds it into a low-resolution tensor
with channels and spatial size .
Parameters
downscale_factorintSpatial downscaling factor . Both
H and W must be
divisible by .Attributes
downscale_factorintStored value of the
downscale_factor constructor argument.Notes
- Input: .
- Output: .
- Commonly used in the analysis (encoder) side of learned image compression codecs to efficiently represent high-frequency spatial detail in the channel dimension before further processing.
- Implemented as reshape → permute → reshape, symmetrically to
PixelShuffle.
Examples
**Fold high-resolution channels into low-resolution feature maps:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> pus = nn.PixelUnshuffle(downscale_factor=2)
>>> x = lucid.zeros(1, 3, 112, 112)
>>> pus(x).shape
(1, 12, 56, 56) # 12 = 3 * 2^2
**Round-trip with PixelShuffle:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> x = lucid.randn(2, 4, 30, 30)
>>> pus = nn.PixelUnshuffle(downscale_factor=3)
>>> ps = nn.PixelShuffle(upscale_factor=3)
>>> x_hat = ps(pus(x))
>>> x_hat.shape == x.shape
TrueMethods (3)
dunder
__init__
→None__init__(downscale_factor: int)Initialise the PixelUnshuffle module. See the class docstring for parameter semantics.
fn
forward
→Tensorforward(x: Tensor)Upsample the input tensor.
Parameters
inputTensorInput tensor of shape .
Returns
TensorUpsampled output tensor.
fn
extra_repr
→strextra_repr()Return a string representation of the layer's configuration.