featureInputLayer
Description
A feature input layer inputs feature data to a neural network and applies data normalization. Use this layer when you have a data set of numeric scalars representing features (data without spatial or time dimensions).
For image input, use imageInputLayer
.
Creation
Description
returns a feature input layer and sets the layer
= featureInputLayer(numFeatures
)InputSize
property to the specified number of features.
sets the optional properties using name-value pair arguments. You can specify multiple
name-value pair arguments. Enclose each property name in single quotes.layer
= featureInputLayer(numFeatures
,Name,Value
)
Properties
Feature Input
InputSize
— Number of features
positive integer
Number of features for each observation in the data, specified as a positive integer.
For image input, use imageInputLayer
.
Example:
10
Normalization
— Data normalization
'none'
(default) | 'zerocenter'
| 'zscore'
| 'rescale-symmetric'
| 'rescale-zero-one'
| function handle
Data normalization to apply every time data is forward propagated through the input layer, specified as one of the following:
'zerocenter'
— Subtract the mean specified byMean
.'zscore'
— Subtract the mean specified byMean
and divide byStandardDeviation
.'rescale-symmetric'
— Rescale the input to be in the range [-1, 1] using the minimum and maximum values specified byMin
andMax
, respectively.'rescale-zero-one'
— Rescale the input to be in the range [0, 1] using the minimum and maximum values specified byMin
andMax
, respectively.'none'
— Do not normalize the input data.function handle — Normalize the data using the specified function. The function must be of the form
Y = func(X)
, whereX
is the input data and the outputY
is the normalized data.
Tip
The software, by default, automatically calculates the normalization statistics when using the
trainNetwork
function. To save time when
training, specify the required statistics for normalization and set the ResetInputNormalization
option in trainingOptions
to 0
(false
).
NormalizationDimension
— Normalization dimension
'auto'
(default) | 'channel'
| 'all'
Normalization dimension, specified as one of the following:
'auto'
– If the training option isfalse
and you specify any of the normalization statistics (Mean
,StandardDeviation
,Min
, orMax
), then normalize over the dimensions matching the statistics. Otherwise, recalculate the statistics at training time and apply channel-wise normalization.'channel'
– Channel-wise normalization.'all'
– Normalize all values using scalar statistics.
Mean
— Mean for zero-center and z-score normalization
[]
(default) | column vector | numeric scalar
Mean for zero-center and z-score normalization, specified as a
1-by-numFeatures
vector of means per feature, a numeric scalar,
or []
.
If you specify the Mean
property, then Normalization
must be 'zerocenter'
or
'zscore'
. If Mean
is
[]
, then the trainNetwork
function calculates
the mean. To train a dlnetwork
object using a custom training loop or
assemble a network without training it using the assembleNetwork
function, you must set the Mean
property to a numeric scalar or a
numeric array.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
StandardDeviation
— Standard deviation for z-score normalization
[]
(default) | column vector | numeric scalar
Standard deviation for z-score normalization, specified as a
1-by-numFeatures
vector of means per feature, a numeric scalar,
or []
.
If you specify the StandardDeviation
property, then
Normalization
must be 'zscore'
. If
StandardDeviation
is []
, then the
trainNetwork
function calculates the standard deviation. To train a
dlnetwork
object using a custom training loop or assemble a network
without training it using the assembleNetwork
function, you must set
the StandardDeviation
property to a numeric scalar or a
numeric array.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Min
— Minimum value for rescaling
[]
(default) | column vector | numeric scalar
Minimum value for rescaling, specified as a 1-by-numFeatures
vector of minima per feature, a numeric scalar, or []
.
If you specify the Min
property, then Normalization
must be 'rescale-symmetric'
or
'rescale-zero-one'
. If Min
is
[]
, then the trainNetwork
function calculates
the minima. To train a dlnetwork
object using a custom training loop or
assemble a network without training it using the assembleNetwork
function, you must set the Min
property to a numeric scalar or a
numeric array.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Max
— Maximum value for rescaling
[]
(default) | column vector | numeric scalar
Maximum value for rescaling, specified as a 1-by-numFeatures
vector of maxima per feature, a numeric scalar, or []
.
If you specify the Max
property, then Normalization
must be 'rescale-symmetric'
or
'rescale-zero-one'
. If Max
is
[]
, then the trainNetwork
function calculates
the maxima. To train a dlnetwork
object using a custom training loop or
assemble a network without training it using the assembleNetwork
function, you must set the Max
property to a numeric scalar or a
numeric array.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
SplitComplexInputs
— Flag to split input data into real and imaginary components
0
(false
) (default) | 1
(true
)
This property is read-only.
Flag to split input data into real and imaginary components specified as one of these values:
0
(false
) – Do not split input data.1
(true
) – Split data into real and imaginary components.
When SplitComplexInputs
is 1
, then the layer
outputs twice as many channels as the input data. For example, if the input data is
complex-values with numChannels
channels, then the layer outputs data
with 2*numChannels
channels, where channels 1
through numChannels
contain the real components of the input data and
numChannels+1
through 2*numChannels
contain
the imaginary components of the input data. If the input data is real, then channels
numChannels+1
through 2*numChannels
are all
zero.
To input complex-valued data into a neural network, the
SplitComplexInputs
option of the input layer must be
1
.
For an example showing how to train a network with complex-valued data, see Train Network with Complex-Valued Data.
Layer
Name
— Layer name
''
(default) | character vector | string scalar
Layer name, specified as a character vector or a string scalar.
For Layer
array input, the trainNetwork
, assembleNetwork
, layerGraph
, and
dlnetwork
functions automatically assign
names to layers with the name ''
.
Data Types: char
| string
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 of the layer. This layer has a single output only.
Data Types: double
OutputNames
— Output names
{'out'}
(default)
This property is read-only.
Output names of the layer. This layer has a single output only.
Data Types: cell
Examples
Create Feature Input Layer
Create a feature input layer with the name 'input'
for observations consisting of 21 features.
layer = featureInputLayer(21,'Name','input')
layer = FeatureInputLayer with properties: Name: 'input' InputSize: 21 SplitComplexInputs: 0 Hyperparameters Normalization: 'none' NormalizationDimension: 'auto'
Include a feature input layer in a Layer
array.
numFeatures = 21; numClasses = 3; layers = [ featureInputLayer(numFeatures,'Name','input') fullyConnectedLayer(numClasses, 'Name','fc') softmaxLayer('Name','sm') classificationLayer('Name','classification')]
layers = 4x1 Layer array with layers: 1 'input' Feature Input 21 features 2 'fc' Fully Connected 3 fully connected layer 3 'sm' Softmax softmax 4 'classification' Classification Output crossentropyex
Combine Image and Feature Input Layers
To train a network containing both an image input layer and a feature input layer, you must use a dlnetwork
object in a custom training loop.
Define the size of the input image, the number of features of each observation, the number of classes, and the size and number of filters of the convolution layer.
imageInputSize = [28 28 1]; numFeatures = 1; numClasses = 10; filterSize = 5; numFilters = 16;
To create a network with two input layers, you must define the network in two parts and join them, for example, by using a concatenation layer.
Define the first part of the network. Define the image classification layers and include a flatten layer and a concatenation layer before the last fully connected layer.
layers = [ imageInputLayer(imageInputSize,'Normalization','none','Name','images') convolution2dLayer(filterSize,numFilters,'Name','conv') reluLayer('Name','relu') fullyConnectedLayer(50,'Name','fc1') flattenLayer('name','flatten') concatenationLayer(1,2,'Name','concat') fullyConnectedLayer(numClasses,'Name','fc2') softmaxLayer('Name','softmax')];
Convert the layers to a layer graph.
lgraph = layerGraph(layers);
For the second part of the network, add a feature input layer and connect it to the second input of the concatenation layer.
featInput = featureInputLayer(numFeatures,'Name','features'); lgraph = addLayers(lgraph, featInput); lgraph = connectLayers(lgraph, 'features', 'concat/in2');
Visualize the network.
plot(lgraph)
Create a dlnetwork
object.
dlnet = dlnetwork(lgraph)
dlnet = dlnetwork with properties: Layers: [9x1 nnet.cnn.layer.Layer] Connections: [8x2 table] Learnables: [6x3 table] State: [0x3 table] InputNames: {'images' 'features'} OutputNames: {'softmax'} Initialized: 1 View summary with summary.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Code generation does not support complex input and does not support
'SplitComplexInputs'
option.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
To generate CUDA® or C++ code by using GPU Coder™, you must first construct and train a deep neural network. Once the network is trained and evaluated, you can configure the code generator to generate code and deploy the convolutional neural network on platforms that use NVIDIA® or ARM® GPU processors. For more information, see Deep Learning with GPU Coder (GPU Coder).
Code generation does not support complex input and does not support
'SplitComplexInputs'
option.
Version History
Introduced in R2020b
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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)