InputLayer - Input layer - MATLAB (original) (raw)
Description
Creation
Syntax
Description
`layer` = inputLayer([inputSize](#mw%5Fd75ee0be-ff75-49b2-ba9c-7e251e8c6a04))
creates an input layer for unformatted data. (since R2025a)
`layer` = inputLayer([inputSize](#mw%5Fd75ee0be-ff75-49b2-ba9c-7e251e8c6a04),[inputFormat](#mw%5Ffb9c3404-fea5-4fd7-b4c2-f16909a81b2e))
creates an input layer and specifies a custom data format.
`layer` = inputLayer(___,Name=[name](#mw%5F6e3e2f1a-b751-480d-94eb-a97466952d26%5Fsep%5Fmw%5F27f4ccf6-2af7-4ecd-9b3a-882699774290))
also specifies the layer name in addition to any of the input argument combinations in previous syntaxes. For example, Name="in"
specifies that the layer has the name "in"
.
Input Arguments
Size of the input, specified as a row vector of positive integers orNaN
.
For networks that support variable sizes for the batch or time dimensions, specify the size of the corresponding dimension as NaN
.
This argument sets the InputSize property.
Example: [224 224 3]
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Description of the data dimensions, specified as a character vector or string scalar.
A data format is a string of characters, where each character describes the type of the corresponding data dimension.
The characters are:
"S"
— Spatial"C"
— Channel"B"
— Batch"T"
— Time"U"
— Unspecified
For example, consider an array that represents a batch of sequences where the first, second, and third dimensions correspond to channels, observations, and time steps, respectively. You can describe the data as having the format "CBT"
(channel, batch, time).
If InputFormat
is""
, then the layer passes unformatted data to the neural network directly. Ensure that subsequent layers support unformatted input data. (since R2025a)
For the layer input format, you can specify multiple dimensions labeled"S"
or "U"
. You can use the labels"C"
, "B"
, and "T"
at most once. When the number of dimensions is greater than two, the input size corresponding to the rightmost "U"
dimension in the input format must be greater than 1.
For more information, see Deep Learning Data Formats.
This argument sets the InputFormat property.
Example: "SSCB"
Example: "SCBT"
Example: "TCB"
Data Types: char
| string
Layer name, specified as a character vector or a string scalar. For Layer
array input, the trainnet anddlnetwork functions automatically assign names to unnamed layers.
This argument sets the Name property.
Data Types: char
| string
Properties
Input
This property is read-only.
This property is read-only after creation.
Size of the input, stored as a row vector of positive integers orNaN
.
For networks that support variable sizes for the batch or time dimensions, the corresponding value is NaN
.
Data Types: double
This property is read-only after creation.
Description of the data dimensions, stored as a character vector.
A data format is a string of characters, where each character describes the type of the corresponding data dimension.
The characters are:
"S"
— Spatial"C"
— Channel"B"
— Batch"T"
— Time"U"
— Unspecified
For example, consider an array that represents a batch of sequences where the first, second, and third dimensions correspond to channels, observations, and time steps, respectively. You can describe the data as having the format "CBT"
(channel, batch, time).
If InputFormat
is""
, then the layer passes unformatted data to the neural network directly. Ensure that subsequent layers support unformatted input data. (since R2025a)
For more information, see Deep Learning Data Formats.
Data Types: char
Layer
Data Types: char
| string
This property is read-only.
Number of inputs of the layer. The layer has no inputs.
Data Types: double
This property is read-only.
Input names of the layer. The layer has no inputs.
Data Types: cell
This property is read-only.
Number of outputs from the layer, stored as 1
. This layer has a single output only.
Data Types: double
This property is read-only.
Output names, stored as {'out'}
. This layer has a single output only.
Data Types: cell
Examples
Create an input layer that inputs 1-D image data (3-D data, with dimensions corresponding to space, channels, and observations). Specify that the data has three channels and an image height size of 64. Specify that the batch dimension can vary.
inputSize = [64 3 NaN]; inputFormat = "SCB"; layer = inputLayer(inputSize,inputFormat)
layer = InputLayer with properties:
Name: ''
InputSize: [64 3 NaN]
InputFormat: 'SCB'
Include the input layer in a network.
layers = [ inputLayer([64 3 NaN],"SCB") convolution1dLayer(5,32) batchNormalizationLayer reluLayer fullyConnectedLayer(10) softmaxLayer];
Create an input layer that inputs spatiotemporal data (4-D data, with dimensions corresponding to space, channels, time, and observations). Specify that the data has three channels and a spatial size of 64. Specify that the batch and time dimensions can vary.
inputSize = [64 3 NaN NaN]; inputFormat = "SCBT"; layer = inputLayer(inputSize,inputFormat)
layer = InputLayer with properties:
Name: ''
InputSize: [64 3 NaN NaN]
InputFormat: 'SCBT'
Include the input layer in a network.
layers = [ inputLayer([64 3 NaN NaN],"SCBT") convolution1dLayer(5,32) batchNormalizationLayer reluLayer globalAveragePooling1dLayer flattenLayer lstmLayer(100,OutputMode="last") fullyConnectedLayer(10) softmaxLayer];
Extended Capabilities
Usage notes and limitations:
You can generate C or C++ code that does not depend on any deep learning third-party libraries for formats with any number of spatial dimensions. For example, code generation supports the input format "SSSCBT"
(spatial, spatial, spatial, channel, batch, time) for inputLayer
.
Code generation for ARM® Compute and Intel® MKL-DNN only supports permutations of these input formats:
"CB"
(channel, batch)"SSCB"
(spatial, spatial, channel, batch)"CBT"
(channel, batch, time)"SSCBT"
(spatial, spatial, channel, batch, time)
Usage notes and limitations:
- You can generate plain CUDA code that is independent of deep learning libraries for formats with any number of spatial dimensions. For example, code generation supports the input format "SSSCBT" (spatial, spatial, spatial, channel, batch, time) for
inputLayer
. - You can generate code that takes advantage of the NVIDIA® CUDA® deep neural network library (cuDNN), or the NVIDIA TensorRT™ high performance inference library.
The cuDNN library supports permutations of these input formats:"CB"
(channel, batch)"SSCB"
(spatial, spatial, channel, batch)"CBT"
(channel, batch, time)"SSCBT"
(spatial, spatial, channel, batch, time)
- The TensorRT library supports permutations of these input formats:
"CB"
(channel, batch)"SSCB"
(spatial, spatial, channel, batch)"CBT"
(channel, batch, time)
Version History
Introduced in R2023b
To create an input layer that passes unformatted data to a neural network, use the syntax inputLayer(inputSize)
or set the inputSize
argument to ""
.
For complex-valued input to the neural network, the layer passes complex-valued data to subsequent layers.