Conv2DLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
A 2-D convolution with explicit input and output channels, kernel, stride and zero padding per axis and an optional
bias — PyTorch’s nn.Conv2d, with its weight layout [out, in, kernelHeight, kernelWidth].
Inheritance: LayerBase<T> → Conv2DLayer<T>
Implements: IShapeContract
For Beginners
A small filter slides over an image-like grid (here, often a spectrogram) and responds to local patterns; stride skips positions to shrink the grid.
How It Works
The kernel and bias are initialized as PyTorch initializes nn.Conv2d: U(−1/√fan_in, 1/√fan_in) with
fan_in = in · kernelHeight · kernelWidth. Input is [batch, in, height, width] or [in, height, width];
output is [batch, out, height', width'] (or without the batch axis).
With Weight the kernel is weight-normalized (Salimans and Kingma 2016,
PyTorch weight_norm(Conv2d)): W = g · V / ‖V‖ per output channel, g starting at ‖V‖.
Constructors
| Constructor | Summary |
|---|---|
Conv2DLayer(int inChannels, int outChannels, int kernelHeight, int kernelWidth, int strideHeight, int strideWidth, int padHeight, int padWidth, bool useBias, ConvolutionNormalization normalization, int dilationHeight, int dilationWidth) |
Creates the layer. |
Properties
| Property | Summary |
|---|---|
bool SupportsTraining { get; } |
Methods
| Method | Summary |
|---|---|
Dictionary<string, string> GetParameterRoles() |
Returns parameter roles for per-role optimizer configuration (e.g., weight decay exemption for biases). |
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank) |
|
IReadOnlyList<Tensor<T>> GetTrainableParameters() |
Returns all trainable parameter tensors marked with [TrainableParameter]. |
void ResetState() |
|
void SetTrainableParameters(IReadOnlyList<Tensor<T>> parameters) |
Replaces trainable parameter tensors (e.g., with ParameterBuffer views). |
void ZeroGrad() |
Clears all gradient fields discovered by convention ({paramName}Gradient). |