PaddingLayer<T>

Layers · AiDotNet.NeuralNetworks.Layers

Represents a layer that adds padding to the input tensor.

Inheritance: LayerBase<T> → PaddingLayer<T>

Implements: IShapeContract

For Beginners

This layer adds extra space around the edges of your data.

Think of it like adding a frame around a picture:

  • You have an image (your input data)
  • The padding adds extra space around all sides of the image
  • The padding is filled with zeros by default

This is useful for:

  • Preserving the size of images when applying convolutions
  • Preventing loss of information at the edges of the data
  • Giving convolutional filters more context at the boundaries

For example, if you have a 28×28 image and add padding of 2 pixels on all sides, you get a 32×32 image with your original data in the center and zeros around the edges.

How It Works

The PaddingLayer adds a specified amount of padding around the edges of the input tensor. This is commonly used in convolutional neural networks to preserve spatial dimensions after convolution operations or to provide additional context at the boundaries of the input. The padding is added symmetrically on both sides of each dimension of the input tensor.

Constructors

Constructor Summary
PaddingLayer(int[] padding, IActivationFunction<T> activationFunction) Initializes a new instance of the PaddingLayer class with the specified input shape, padding, and a vector activation function.
PaddingLayer(int[] padding, IVectorActivationFunction<T> vectorActivationFunction) Initializes a new instance of the PaddingLayer class with the specified input shape, padding, and a vector activation function.

Properties

Property Summary
bool SupportsGpuTraining { get; }
bool SupportsTraining { get; } Gets a value indicating whether this layer supports training.

Methods

Method Summary
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank)
void ResetState() Resets the internal state of the padding layer.