concatenationLayer
Concatenation layer
Description
A concatenation layer takes inputs and concatenates them along a specified dimension. The inputs must have the same size in all dimensions except the concatenation dimension.
Specify the number of inputs to the layer when you create it. The inputs have the
names 'in1','in2',...,'inN'
, where N
is the number
of inputs. Use the input names when connecting or disconnecting the layer by using
connectLayers
or disconnectLayers
.
Creation
Syntax
Description
Properties
Concatenation
Dim
— Concatenation dimension
positive integer
Concatenation dimension, specified as a positive integer. The layer supports concatenating over the channel and spatial dimensions only.
Example:
4
Layer
Name
— Layer name
""
(default) | character vector | string scalar
NumInputs
— Number of inputs
positive integer
Number of inputs to the layer, specified as a positive integer greater than or equal to 2.
The inputs have the names 'in1','in2',...,'inN'
, where N
is
NumInputs
. For example, if NumInputs
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.
InputNames
— Input Names
{'in1','in2',…,'inN'}
(default)
Input names, specified as {'in1','in2',...,'inN'}
, where N
is the number of inputs of the layer.
Data Types: cell
NumOutputs
— Number of outputs
1
(default)
This property is read-only.
Number of outputs from the layer, returned as 1
. This layer has a
single output only.
Data Types: double
OutputNames
— Output names
{'out'}
(default)
This property is read-only.
Output names, returned as {'out'}
. This layer has a single output
only.
Data Types: cell
Examples
Create and Connect Concatenation Layer
Create a concatenation layer that concatenates two inputs along the fourth dimension (channels). Name the concatenation layer 'concat'
.
concat = concatenationLayer(4,2,'Name','concat')
concat = ConcatenationLayer with properties: Name: 'concat' Dim: 4 NumInputs: 2 InputNames: {'in1' 'in2'}
Create two ReLU layers and connect them to the concatenation layer. The concatenation layer concatenates the outputs from the ReLU layers.
relu_1 = reluLayer('Name','relu_1'); relu_2 = reluLayer('Name','relu_2'); net = dlnetwork; net = addLayers(net, relu_1); net = addLayers(net, relu_2); net = addLayers(net, concat); net = connectLayers(net, 'relu_1', 'concat/in1'); net = connectLayers(net, 'relu_2', 'concat/in2'); plot(net)
Algorithms
Layer Input and Output Formats
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 formats consist 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 functionLayer
object, or using the forward
and predict
functions with
dlnetwork
objects.
This table shows the supported input formats of ConcatenationLayer
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 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. The layer may support additional
formats such as formats with additional "S"
(spatial) or
"U"
(unspecified) dimensions.
The layer supports concatenation over "S"
(spatial) and
"C"
(channel) dimensions only. The output format matches the
input format. Each input must have data of the same format.
Input Format | Output Format |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In dlnetwork
objects, ConcatenationLayer
objects also
support these input and output format combinations.
Input Format | Output Format |
---|---|
|
|
|
|
|
|
|
|
Complex Numbers
ConcatenationLayer
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™.
For code generation, you must pass a dlarray
object with a channel (C) dimension as the input to this layer. For example, code generation
supports data format such as "SSC" or "SSCBT".
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Refer to the usage notes and limitations in the C/C++ Code Generation section. The same limitations apply to GPU code generation.
Version History
Introduced in R2019aR2024a: Support for complex-valued inputs and outputs
ConcatenationLayer
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.
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)