Pixel shuffle

Resample · node type · DepthToSpace, SpaceToDepth

Rearranges groups of channels into larger blocks of pixels: upsampling by reshuffling, not interpolating.

Also called DepthToSpace, SpaceToDepth, Sub-pixel convolution

Figure 1. Pixel shuffle inside Generate a frame between two photos, a real model in WeightSpace. The 5 outlined nodes are Pixel shuffle; select any node for its shapes and parameters.

What it does

Pixel shuffle takes a low-resolution tensor with r² times as many channels as needed and moves each group of r² channels into an r × r patch of neighboring output pixels. The preceding convolution therefore computes all the sub-pixel values at low resolution, which is cheap, and the shuffle only rearranges memory. Super-resolution networks such as ESPCN end with this rearrangement; the ESPCN export in WeightSpace spells it as Reshape, Transpose and Reshape rather than a single DepthToSpace. SpaceToDepth performs the reverse, folding pixel blocks into channels to downsample without losing information.

Formula

Y[n, c, r·y + i, r·x + j] = X[n, c·r2 + i·r + j, y, x] (CRD order)

Shapes and parameters

Shapes
Input [N, C·r², H, W]; output [N, C, r·H, r·W].
Parameters
None. The learned work happens in the convolution before it.
Used for
ESPCN and other super-resolution models, some frame interpolation and detection necks.

Figure 2. The typed ports of Pixel shuffle, in the same format as every model drawing. Letters such as N or C stand for any size.

In WeightSpace

Read-only itself. In the ESPCN super-resolution model the editable value is a shared offset on the nine biases of the convolution that feeds the sub-pixel rearrangement, one per position in each 3 × 3 block, so an edit brightens or darkens every output pixel.