ConvolutionalLayer<T>

Layers · AiDotNet.NeuralNetworks.Layers

Represents a convolutional layer in a neural network that applies filters to input data.

Inheritance: LayerBase<T> → ConvolutionalLayer<T>

Implements: IShapeContract

For Beginners

A convolutional layer is like a spotlight that scans over data looking for specific patterns.

Think of it like examining a photo with a small magnifying glass:

  • You move the magnifying glass across the image, one step at a time
  • At each position, you note what you see in that small area
  • After scanning the whole image, you have a collection of observations

For example, in image recognition:

  • One filter might detect vertical edges
  • Another might detect horizontal edges
  • Together, they help the network recognize complex shapes

Convolutional layers are fundamental for recognizing patterns in images, audio, and other grid-structured data.

How It Works

A convolutional layer applies a set of learnable filters to input data to extract features. Each filter slides across the input data, performing element-wise multiplication and summing the results. This operation is called convolution and is particularly effective for processing grid-like data such as images.

Constructors

Constructor Summary
ConvolutionalLayer(int outputDepth, int kernelSize, int stride, int padding, IActivationFunction<T> activationFunction, IInitializationStrategy<T> initializationStrategy, IActivationFunction<T> nonlinearityForInit, int groups) Random number generator used for weight initialization.
ConvolutionalLayer(int outputDepth, int kernelSize, int stride, int padding, IActivationFunction<T> activationFunction, IInitializationStrategy<T> initializationStrategy, IActivationFunction<T> nonlinearityForInit, int groups, BiasMode biasMode)
ConvolutionalLayer(int outputDepth, int kernelSize, int stride, int padding, IVectorActivationFunction<T> vectorActivationFunction, IInitializationStrategy<T> initializationStrategy) Initializes a new instance of the ConvolutionalLayer class with the specified parameters and a vector activation function.
ConvolutionalLayer(int outputDepth, int kernelSize, int stride, int padding, IVectorActivationFunction<T> vectorActivationFunction, IInitializationStrategy<T> initializationStrategy, BiasMode biasMode)

Properties

Property Summary
bool HasUninitializedParameters { get; } Gets all trainable parameters of the layer as a single vector.
bool IsInitialized { get; }
bool SupportsTraining { get; }
bool UseBias { get; } Whether this convolution carries its own additive bias.
int Groups { get; set; } Number of convolution groups.
int InputDepth { get; set; } Gets the depth (number of channels) of the input data.
int KernelSize { get; set; } Gets the size of each filter (kernel) used in the convolution operation.
int OutputDepth { get; set; } Gets the depth (number of filters) of the output data.
int Padding { get; set; } Gets the amount of zero-padding added to the input data before convolution.
int Stride { get; set; } Gets the step size for moving the kernel across the input data.

Methods

Method Summary
ConvolutionalLayer<T> Configure(int[] inputShape, int kernelSize, int numberOfFilters, int stride, int padding, IActivationFunction<T> activationFunction) Creates a convolutional layer with the specified configuration and a vector activation function using a fluent interface.
ConvolutionalLayer<T> Configure(int[] inputShape, int kernelSize, int numberOfFilters, int stride, int padding, IVectorActivationFunction<T> vectorActivationFunction) Creates a convolutional layer with the specified configuration and a vector activation function using a fluent interface.
ConvolutionalLayer<T> WithInputDepth(int inputDepth, int outputDepth, int kernelSize, int stride, int padding, IActivationFunction<T> activationFunction, IInitializationStrategy<T> initializationStrategy, IActivationFunction<T> nonlinearityForInit, int groups, BiasMode biasMode) Initializes a convolution whose input channel count is already known.
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].
IReadOnlyList<ValueTuple<string, Tensor<T>>> GetRegisteredBuffers()
Tensor<T> GetBiases() Gets the biases tensor of the convolutional layer.
Tensor<T> GetFilters() Gets a value indicating whether this layer supports training through backpropagation.
void ClearGradients() Clears the kernel and bias gradients along with the base layer’s gradients.
void ResetState() Resets the internal state of the layer.
void SetTrainableParameters(IReadOnlyList<Tensor<T>> parameters) Replaces trainable parameter tensors (e.g., with ParameterBuffer views).
void SetTrainingMode(bool isTraining) Drops FoldedBatchNormMean on a training-mode transition: training moves the bias and the running mean, and a device-side update need not advance the host tensors’ versions the cache keys on.
void UpdateParameters(T learningRate) Updates the layer’s parameters (kernel weights and biases) using the specified learning rate.
void ZeroGrad() Clears all gradient fields discovered by convention ({paramName}Gradient).