Main Content

additionLayer

R2026b

Addition layer

Description

An addition layer adds inputs from multiple neural network layers element-wise.

Creation

Description

layer = additionLayer(numInputs) creates an addition layer and sets the NumInputs property.

example

layer = additionLayer(numInputs,Name=name) also sets the optional Name property. For example, additionLayer(3,Name="add") creates an addition layer with three inputs and sets the name to "add".

example

Input Arguments

expand all

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

Layer name, specified as a character vector or a string scalar. For Layer array input, the trainnet and dlnetwork functions automatically assign names to unnamed layers.

This argument sets the Name property.

Data Types: char | string

Properties

expand all

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

Layer name, specified as a character vector. For Layer array input, the trainnet and dlnetwork functions automatically assign names to unnamed layers.

Data Types: char

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

collapse all

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)

Figure contains an axes object. The axes object contains an object of type graphplot.

Algorithms

expand all

Extended Capabilities

expand all

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 R2017b

expand all