AddLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
A layer that adds multiple input tensors element-wise and optionally applies an activation function.
Inheritance: LayerBase<T> → AddLayer<T>
Implements: IShapeContract
For Beginners
This layer adds together multiple inputs of the same shape.
Think of this layer as performing element-wise addition:
- If you have two 3×3 matrices, it adds corresponding elements together
- All inputs must have exactly the same dimensions
- After adding, it can optionally apply an activation function
This is commonly used in:
- Residual networks (ResNets) where outputs from earlier layers are added to later layers
- Skip connections that help information flow more directly through deep networks
- Any situation where you want to combine information from multiple sources
For example, if you have two feature maps from different parts of a network, this layer lets you combine them by adding their values together.
How It Works
The AddLayer combines multiple tensors of identical shape by adding their values element-wise. This is useful for implementing residual connections, skip connections, or any architecture that requires combining information from multiple sources. After adding the inputs, an optional activation function can be applied to the result.
Constructors
| Constructor | Summary |
|---|---|
AddLayer(int[][] inputShapes, IActivationFunction<T> activationFunction) |
Creates a new addition layer with the specified input shapes and an optional vector activation function. |
AddLayer(int[][] inputShapes, IVectorActivationFunction<T> vectorActivationFunction) |
Creates a new addition layer with the specified input shapes and an optional vector activation function. |
Properties
| Property | Summary |
|---|---|
IReadOnlyList<LayerPort> InputPorts { get; } |
|
bool SupportsGpuTraining { get; } |
|
bool SupportsTraining { get; } |
Indicates whether this layer has trainable parameters. |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank) |
Derived from this type’s [TensorLayout] declarations. |
void ResetState() |
Clears the layer’s memory of previous inputs and outputs. |