PixelUnshuffle

https://pytorch.org/docs/stable/generated/torch.nn.PixelUnshuffle.html

pixel_unshuffle_demo.py
import svetoviz_webgpu as sv

# 1. Define Modules
downscale_factor = 2
# Reverses PixelShuffle: (*, C, H*r, W*r) to (*, C*r^2, H, W)
unshuffle = nn.PixelUnshuffle(downscale_factor=downscale_factor)
shuffle = nn.PixelShuffle(upscale_factor=downscale_factor)

container = nn.ModuleList([unshuffle, shuffle])

def terminal_callback(buffer, message, images, files):
    # Step A: Unshuffle (Spatial to Channels)
    unshuffled = unshuffle(input_tensor)

    # Step B: Shuffle back (Recovery)
    reconstructed = shuffle(unshuffled)

    buffer.send_system_message(f"Input Resolution: {input_tensor.shape[2:]}")
    buffer.send_system_message(f"Unshuffled (Feature Depth): {list(unshuffled.shape)}")

    mse = torch.mean((input_tensor - reconstructed) ** 2)
    buffer.send_system_message(f"Reconstruction Error: {mse.item():.6f}")

# 2. Start the interactive session
sv.pytorch_web(module=container, terminal_callback=terminal_callback)
Spatial to Channel Folding
PairwiseDistance activations
PixelUnshuffle reduces spatial resolution while increasing channel depth without losing information. It is effectively a "space-to-depth" transformation, commonly used as a more efficient alternative to pooling or strided convolutions.