PixelShuffleLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
Pixel shuffle (sub-pixel convolution) layer for efficient spatial upsampling.
Inheritance: LayerBase<T> → PixelShuffleLayer<T>
Implements: IShapeContract
For Beginners
Imagine you have a small image and want to make it bigger.
Pixel shuffle works by:
- Starting with extra channel information (4x more channels for 2x upscaling)
- Rearranging those channel values into spatial positions
- Creating a larger image with the same amount of total information
For example, with 2x upscaling:
- Input: 64 channels × 32×32 pixels
- Output: 16 channels × 64×64 pixels (same total data, different arrangement)
This is commonly used in super-resolution models like Real-ESRGAN and ESPCN.
How It Works
Pixel shuffle rearranges elements from the channel dimension into spatial dimensions, effectively upscaling the spatial resolution. This is more efficient than transposed convolution (deconvolution) for upsampling operations.
For a 2x upscaling, the layer takes 4 channel values and arranges them as a 2x2 spatial block. The operation follows the formula: [batch, channels * r^2, height, width] -> [batch, channels, height * r, width * r]
Constructors
| Constructor | Summary |
|---|---|
PixelShuffleLayer(int upscaleFactor) |
Initializes a new instance of the PixelShuffleLayer class. |
Properties
| Property | Summary |
|---|---|
bool SupportsTraining { get; } |
|
int UpscaleFactor { get; } |
Gets the upscaling factor used by this layer. |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank) |
|
void ResetState() |