class

PixelUnshuffle

extendsModule
PixelUnshuffle(downscale_factor: int)
source

Reverse the sub-pixel rearrangement performed by PixelShuffle.

PixelUnshuffle is the exact inverse of PixelShuffle: it takes a high-resolution input with CC channels and spatial size (Hr,Wr)(H \cdot r, W \cdot r) and folds it into a low-resolution tensor with Cr2C \cdot r^2 channels and spatial size (H,W)(H, W).

output[n,cr2+shr+sw,H,W]=input[n,c,Hr+sh,Wr+sw]\text{output}[n,\, c \cdot r^2 + s_h \cdot r + s_w,\, H,\, W] = \text{input}[n,\, c,\, H \cdot r + s_h,\, W \cdot r + s_w]

Parameters

downscale_factorint
Spatial downscaling factor rr. Both H and W must be divisible by rr.

Attributes

downscale_factorint
Stored value of the downscale_factor constructor argument.

Notes

  • Input: (N,C,Hr,Wr)(N, C, H \cdot r, W \cdot r).
  • Output: (N,Cr2,H,W)(N, C \cdot r^2, H, W).
  • 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
True

Methods (3)

dunder

__init__

None
__init__(downscale_factor: int)
source

Initialise the PixelUnshuffle module. See the class docstring for parameter semantics.

fn

forward

Tensor
forward(x: Tensor)
source

Upsample the input tensor.

Parameters

inputTensor
Input tensor of shape (N,C,)(N, C, *).

Returns

Tensor

Upsampled output tensor.

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.