inputLayer
Description
An input layer inputs data into a neural network with a custom format.
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
Description
creates an input layer and sets the layer
= inputLayer(inputSize
,inputFormat
)InputSize
and
InputFormat
properties.
also sets the layer
= inputLayer(inputSize
,format
,Name=name
)Name
property.
Properties
Input
InputSize
— Size of input
row vector of positive integers or NaN
This property is read-only.
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
.
Example:
[224 224 3]
InputFormat
— Description of data dimensions
character vector | string scalar
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 containing a batch of sequences where the first, second,
and third dimensions correspond to channels, observations, and time steps, respectively. You
can specify that this array has the format "CBT"
(channel, batch,
time).
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.
Example: "SSCB"
Example: "SCBT"
Example: "TCB"
Data Types: char
| string
Layer
Name
— Layer name
""
(default) | character vector | string scalar
NumInputs
— Number of inputs
0 (default)
This property is read-only.
Number of inputs of the layer. The layer has no inputs.
Data Types: double
InputNames
— Input names
{}
(default)
This property is read-only.
Input names of the layer. The layer has no inputs.
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 1-D Image Input Layer
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 a 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 Spatiotemporal Input Layer
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];
Algorithms
Complex Numbers
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
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
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)
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
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 R2023bR2024a: Complex-valued outputs
For complex-valued input to the neural network, the layer passes complex-valued data to subsequent layers.
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
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)