Image input layer
An image input layer inputs 2-D images to a network and applies data normalization.
For 3-D image input, use image3dInputLayer
.
returns an image input layer and specifies the layer
= imageInputLayer(inputSize
)InputSize
property.
sets the optional properties using name-value pairs. You can specify multiple
name-value pairs. Enclose each property name in single quotes.layer
= imageInputLayer(inputSize
,Name,Value
)
InputSize
— Size of the inputSize of the input data, specified as a row vector of integers
[h w c]
, where h
,
w
, and c
correspond to the
height, width, and number of channels respectively.
For grayscale images, specify a vector with
c
equal to
1
.
For RGB images, specify a vector with c
equal to 3
.
For multispectral or hyperspectral images, specify a
vector with c
equal to the number of
channels.
For 3-D image or volume input, use image3dInputLayer
.
Example:
[224 224 3]
Normalization
— Data normalization'zerocenter'
(default) | 'zscore'
| 'rescale-symmetric'
| 'rescale-zero-one'
| 'none'
| function handleData normalization to apply every time data is forward propagated through the input layer, specified as one of the following:
'zerocenter'
— Subtract the mean specified by Mean
.
'zscore'
— Subtract the mean specified by Mean
and divide by StandardDeviation
.
'rescale-symmetric'
— Rescale the input to be in the range [-1, 1] using the minimum and maximum values specified by Min
and Max
, respectively.
'rescale-zero-one'
— Rescale the input to be in the range [0, 1] using the minimum and maximum values specified by Min
and Max
, 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)
, where X
is the input data, and the output Y
is the normalized data.
Tip
The software, by default, automatically calculates the normalization statistics at training time. To save time when training, specify the required statistics for normalization and set the 'ResetInputNormalization'
option in trainingOptions
to false
.
NormalizationDimension
— Normalization dimension'auto'
(default) | 'channel'
| 'element'
| 'all'
Normalization dimension, specified as one of the following:
'auto'
– If the training option is false
and you specify any of the normalization statistics (Mean
, StandardDeviation
, Min
, or Max
), then normalize over the dimensions matching the statistics. Otherwise, recalculate the statistics at training time and apply channel-wise normalization.
'channel'
– Channel-wise normalization.
'element'
– Element-wise normalization.
'all'
– Normalize all values using scalar statistics.
Mean
— Mean for zero-center and z-score normalization[]
(default) | 3-D array | numeric scalarMean for zero-center and z-score normalization, specified as a
h-by-w-by-c
array, a 1-by-1-by-c array of means per channel, a
numeric scalar, or []
, where h,
w, and c correspond to the
height, width, and the number of channels of the mean,
respectively.
If you specify the Mean
property,
then Normalization
must be
'zerocenter'
or 'zscore'
. If
Mean
is []
,
then the software calculates the mean at training time.
You can set this property when creating networks without
training (for example, when assembling networks using assembleNetwork
).
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
StandardDeviation
— Standard deviation for z-score normalization[]
(default) | 3-D array | numeric scalarStandard deviation for z-score normalization, specified as a
h-by-w-by-c
array, a 1-by-1-by-c array of means per channel, a
numeric scalar, or []
, where h,
w, and c correspond to the
height, width, and the number of channels of the standard deviation,
respectively.
If you specify the StandardDeviation
property,
then Normalization
must be
'zscore'
. If StandardDeviation
is []
, then the software
calculates the standard deviation at training time.
You can set this property when creating networks without
training (for example, when assembling networks using assembleNetwork
).
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Min
— Minimum value for rescaling[]
(default) | 3-D array | numeric scalarMinimum value for rescaling, specified as a
h-by-w-by-c
array, a 1-by-1-by-c array of minima per channel, a
numeric scalar, or []
, where h,
w, and c correspond to the
height, width, and the number of channels of the minima,
respectively.
If you specify the Min
property,
then Normalization
must be
'rescale-symmetric'
or
'rescale-zero-one'
. If Min
is []
, then the software
calculates the minimum at training time.
You can set this property when creating networks without
training (for example, when assembling networks using assembleNetwork
).
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Max
— Maximum value for rescaling[]
(default) | 3-D array | numeric scalarMaximum value for rescaling, specified as a
h-by-w-by-c
array, a 1-by-1-by-c array of maxima per channel, a
numeric scalar, or []
, where h,
w, and c correspond to the
height, width, and the number of channels of the maxima,
respectively.
If you specify the Max
property,
then Normalization
must be
'rescale-symmetric'
or
'rescale-zero-one'
. If Max
is []
, then the software
calculates the maximum at training time.
You can set this property when creating networks without
training (for example, when assembling networks using assembleNetwork
).
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
DataAugmentation
— Data augmentation transforms'none'
(default) | 'randcrop'
| 'randfliplr'
| cell array of 'randcrop'
and
'randfliplr'
Note
The DataAugmentation
property is not
recommended. To preprocess images with cropping, reflection, and
other geometric transformations, use augmentedImageDatastore
instead.
Data augmentation transforms to use during training, specified as one of the following.
'none'
— No data augmentation
'randcrop'
— Take a random crop from the
training image. The random crop has the same size as the input
size.
'randfliplr'
— Randomly flip the input
images horizontally with a 50% chance.
Cell array of 'randcrop'
and
'randfliplr'
. The software applies the
augmentation in the order specified in the cell array.
Augmentation of image data is another way of reducing overfitting [1], [2].
Data Types: string
| char
| cell
Name
— Layer name''
(default) | character vector | string scalar
Layer name, specified as a character vector or a string scalar.
To include a layer in a layer graph, you must specify a nonempty unique layer name. If you train
a series network with the layer and Name
is set to ''
,
then the software automatically assigns a name to the layer at training time.
Data Types: char
| string
NumInputs
— Number of inputsNumber of inputs of the layer. The layer has no inputs.
Data Types: double
InputNames
— Input names{}
(default)Input names of the layer. The layer has no inputs.
Data Types: cell
NumOutputs
— Number of outputsNumber of outputs of the layer. This layer has a single output only.
Data Types: double
OutputNames
— Output names{'out'}
(default)Output names of the layer. This layer has a single output only.
Data Types: cell
Create an image input layer for 28-by-28 color images with name 'input'.
By default, the layer performs data normalization by subtracting the mean image of the training set from every input image.
inputlayer = imageInputLayer([28 28 3],'Name','input')
inputlayer = ImageInputLayer with properties: Name: 'input' InputSize: [28 28 3] Hyperparameters DataAugmentation: 'none' Normalization: 'zerocenter' NormalizationDimension: 'auto' Mean: []
Include an image input layer in a Layer
array.
layers = [ ... imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer maxPooling2dLayer(2,'Stride',2) fullyConnectedLayer(10) softmaxLayer classificationLayer]
layers = 7x1 Layer array with layers: 1 '' Image Input 28x28x1 images with 'zerocenter' normalization 2 '' Convolution 20 5x5 convolutions with stride [1 1] and padding [0 0 0 0] 3 '' ReLU ReLU 4 '' Max Pooling 2x2 max pooling with stride [2 2] and padding [0 0 0 0] 5 '' Fully Connected 10 fully connected layer 6 '' Softmax softmax 7 '' Classification Output crossentropyex
AverageImage
property will be removedNot recommended starting in R2019b
AverageImage
will be removed. Use Mean
instead. To update your code, replace all instances of AverageImage
with Mean
.
There are no differences between the properties that require additional updates to your
code.
imageInputLayer
and image3dInputLayer
, by default, use channel-wise normalizationBehavior change in future release
Starting in R2019b, imageInputLayer
and image3dInputLayer
,
by default, use channel-wise normalization. In previous versions, these layers use
element-wise normalization. To reproduce this behavior, set the NormalizationDimension
option of these layers to
'element'
.
[1] Krizhevsky, A., I. Sutskever, and G. E. Hinton. "ImageNet Classification with Deep Convolutional Neural Networks". Advances in Neural Information Processing Systems. Vol 25, 2012.
[2] Cireşan, D., U. Meier, J. Schmidhuber. "Multi-column Deep Neural Networks for Image Classification". IEEE Conference on Computer Vision and Pattern Recognition, 2012.
Usage notes and limitations:
Code generation does not support 'Normalization'
specified using a function handle.
Usage notes and limitations:
Code generation does not support 'Normalization'
specified using a function handle.
augmentedImageDatastore
| convolution2dLayer
| Deep Network
Designer | featureInputLayer
| fullyConnectedLayer
| image3dInputLayer
| maxPooling2dLayer
| trainNetwork
You have a modified version of this example. Do you want to open this example with your edits?