additionLayer
R2026bAddition layer
Description
An addition layer adds inputs from multiple neural network layers element-wise.
Creation
Description
Input Arguments
Number of inputs to the layer, specified as a positive integer greater than or equal to 2.
The inputs have the names 'in1', 'in2', and 'inN', where N is the number of inputs. For example, if number of inputs is 3, then the inputs have the names 'in1', 'in2', and 'in3'. Use the input names when connecting or disconnecting the layer using the connectLayers or disconnectLayers functions.
This argument sets the NumInputs property.
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
Properties
This property is read-only after object creation. To set this property, use the corresponding
positional input argument when you create the AdditionLayer
object.
Number of inputs to the layer, represented as a positive integer greater than or equal to 2.
The inputs have the names 'in1', 'in2', and 'inN', where N is the number of inputs. For example, if number of inputs is 3, then the inputs have the names 'in1', 'in2', and 'in3'. Use the input names when connecting or disconnecting the layer using the connectLayers or disconnectLayers functions.
Data Types: double
This property is read-only.
Input names, represented as {'in1','in2',...,'inN'}, where
N is the number of inputs of the layer.
Data Types: cell
This property is read-only.
Number of outputs from the layer, represented as 1. This layer has
a single output only.
Data Types: double
This property is read-only.
Output name, represented as {'out'}. This layer has a single output
only.
Examples
Create an empty neural network dlnetwork object and add an addition layer with two inputs and the name 'add'.
net = dlnetwork; layer = additionLayer(2,'Name','add'); net = addLayers(net,layer);
Add two ReLU layers to the neural network and connect them to the addition layer. The addition layer outputs the sum of the outputs from the ReLU layers.
layer = reluLayer('Name','relu1'); net = addLayers(net,layer); net = connectLayers(net,'relu1','add/in1'); layer = reluLayer('Name','relu2'); net = addLayers(net,layer); net = connectLayers(net,'relu2','add/in2');
Visualize the updated network in a plot.
plot(net)

Algorithms
Most layers in a layer array or layer graph pass data to subsequent layers as formatted
dlarray objects.
The format of a dlarray object is a string of characters in which each
character describes the corresponding dimension of the data. The format consists of one or
more of these characters:
"S"— Spatial"C"— Channel"B"— Batch"T"— Time"U"— Unspecified
For example, you can describe 2-D image data that is represented as a 4-D array, where the
first two dimensions correspond to the spatial dimensions of the images, the third
dimension corresponds to the channels of the images, and the fourth dimension
corresponds to the batch dimension, as having the format "SSCB"
(spatial, spatial, channel, batch).
You can interact with these dlarray objects in automatic differentiation
workflows, such as those for:
developing a custom layer
using a
functionLayerobjectusing the
forwardandpredictfunctions withdlnetworkobjects
This table shows the supported input formats of AdditionLayer objects and the
corresponding output format. If the software passes the output of the layer to a custom
layer that does not inherit from the nnet.layer.Formattable class, or to
a FunctionLayer object with the Formattable property set
to 0 (false), then the layer receives an unformatted
dlarray object with dimensions ordered according to the formats in this
table. The formats listed here are only a subset of the formats that the layer supports. The
layer might support additional formats, such as formats with additional
"S" (spatial) or "U" (unspecified)
dimensions.
| Input Format | Output Format |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
If several input formats contain the same label, then the corresponding data for
each input must be a singleton or the same size as the nonsingleton data for the
other inputs. If an input format contains multiple U or S labels,
additionLayer matches each label to the labels in the other
input formats by their order of appearance.
In dlnetwork objects, AdditionLayer objects also
support these input and output format combinations.
| Input Format | Output Format |
|---|---|
|
|
|
|
|
|
|
|
AdditionLayer objects support complex-valued input
and outputs (since R2024a). The layer applies the same underlying operation to complex-valued
input as it does to real-valued input and outputs complex-valued data where
applicable.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Version History
Introduced in R2017bAdditionLayer objects support complex-valued input and outputs. The layer applies the same underlying operation to complex-valued input as it does to real-valued input and outputs complex-valued data where applicable.
See Also
trainnet | trainingOptions | dlnetwork | depthConcatenationLayer | exportNetworkToSimulink | Addition Layer
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)