UpBlock<T>
Models & Types · AiDotNet.Diffusion.VAE
Upsampling block for VAE decoder with transposed convolution and multiple ResBlocks.
Inheritance: LayerBase<T> → UpBlock<T>
Implements: IShapeContract
For Beginners
An UpBlock is like a decompression stage in a decoder.
What it does:
- Increases spatial size by 2x using transposed convolution (decompression)
- Processes the upsampled features through multiple residual blocks
Example: 8x8 input -> 16x16 output (spatial dimensions doubled)
Why use transposed convolution instead of simple interpolation?
- Transposed conv is learnable (the network decides how to upsample)
- Simple interpolation (bilinear, nearest) has fixed behavior
- Learnable upsampling can generate sharper details
Structure:
input [B, C_in, H, W]
│
├─→ ConvTranspose (stride=2) ─→ upsample
│
↓
[B, C_out, 2*H, 2*W]
│
├─→ ResBlock → ResBlock → ... (numLayers blocks)
│
↓
output [B, C_out, 2*H, 2*W]
How It Works
This implements an upsampling block following the Stable Diffusion VAE architecture:
- Transposed convolution (deconvolution) to increase spatial dimensions by 2x
- Multiple VAEResBlocks to process features at the upsampled resolution
Constructors
| Constructor | Summary |
|---|---|
UpBlock(int inChannels, int outChannels, int numLayers, int numGroups, int inputSpatialSize, bool hasUpsample) |
Initializes a new instance of the UpBlock class. |
Properties
| Property | Summary |
|---|---|
bool HasUpsample { get; } |
Gets whether this block performs upsampling. |
bool SupportsTraining { get; } |
|
int InputChannels { get; } |
Gets the number of input channels. |
int NumLayers { get; } |
Gets the number of residual blocks. |
int OutputChannels { get; } |
Gets the number of output channels. |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<ILayer<T>> GetSubLayers() |
|
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank) |
|
IReadOnlyList<VAEResBlock<T>> GetResBlocks() |
Gets the residual blocks for external access. |
void ResetState() |
Resets the internal state of the block. |
void UpdateParameters(T learningRate) |
Updates all learnable parameters using gradient descent. |