inputLayer
R2026bDescription
An input layer inputs unformatted data or data with a custom format into a neural network.
For 2-D image input, use
imageInputLayer.For 3-D image input, use
image3dInputLayer.For sequence and time series input, use
sequenceInputLayer.For tabular and feature data input, use
featureInputLayer.
Creation
Syntax
Description
creates an input layer for unformatted data (since R2025a).layer = inputLayer(inputSize)
creates an input layer and specifies a custom data format.layer = inputLayer(inputSize,inputFormat)
specifies options using one or more name-value arguments in addition to any of the input
argument combinations in previous syntaxes. For example, layer = inputLayer(___,Name=Value)Name="in"
specifies that the layer has the name "in".
Input Arguments
Size of the input, specified as a row vector of positive integers or
NaN.
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 deep learning 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, suppose you have 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
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: inputLayer([3 1],"CB",Name="in") creates an
input layer with the name "in".
Since R2026b
Input validation function, specified as one of these:
"auto"— Check that the size and format of the input data match the layer configuration.Function handle with syntax
f(X,info)— Call the specified function during training and prediction. The function throws an error for invalid input data.
If you specify a custom function, then the argument X is the
input data, specified as a formatted dlarray
object. The argument info is a structure with fields
InputSize and InputFormat that contains the
corresponding layer property values.
For example, you can use this function to check that the layer inputs contain only positive values:
function inputMustBePositive(X,info) if any(X<=0,"all") error("Input must be positive.") end end
inputMustBePositive.m, and set
the argument to @inputMustBePositive.This argument sets the InputValidationFcn property.
Data Types: char | string | function_handle
Properties
Input
This property is read-only.
This property is read-only after object creation. To set this property, use the corresponding
positional input argument when you create the InputLayer
object.
Size of the input, stored as a row vector of positive integers or
NaN.
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 object creation. To set this property, use the corresponding
positional input argument when you create the InputLayer
object.
Description of the data dimensions, stored as a character vector.
A deep learning 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, suppose you have 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
Since R2026b
This property is read-only after object creation. To set this property, use the corresponding
name-value argument when you create the InputLayer object.
Input validation function, stored as one of these:
'auto'— Check that the size and format of the input data match the layer configuration.Function handle with syntax
f(X,info)— Call the specified function during training and prediction. The function throws an error for invalid input data.
Data Types: char | function_handle
Layer
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, 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 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'
InputValidationFcn: 'auto'
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'
InputValidationFcn: 'auto'
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];Algorithms
InputLayer objects support passing
complex-valued data to subsequent layers (since R2024a).
For an example showing how to train a network with complex-valued data, see Train Network with Complex-Valued Data.
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 R2023bSpecify a custom input validation function using the InputValidationFcn name-value argument. During training or prediction, the
layer calls this function to validate the input data.
To create an input layer that passes unformatted data to a neural network, use the
syntax inputLayer(inputSize) or set the inputFormat
argument to "".
For complex-valued input to the neural network, the layer passes complex-valued data to subsequent layers.
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.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)