Why there the normalization of the imageIputLayer is Zero-Center, what should I do when I want to scale the image to [0,1] before training?

6 次查看(过去 30 天)
as the document said:https://cn.mathworks.com/help/nnet/examples/create-simple-deep-learning-network-for-classification.html
digitDatasetPath = fullfile(matlabroot,'toolbox','nnet','nndemos', ...
'nndatasets','DigitDataset');
digitData = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
trainingNumFiles = 750;
rng(1) % For reproducibility
[trainDigitData,testDigitData] = splitEachLabel(digitData, ...
trainingNumFiles,'randomize');
layers = [imageInputLayer([28 28 1])
convolution2dLayer(5,20)
reluLayer
maxPooling2dLayer(2,'Stride',2)
fullyConnectedLayer(10)
softmaxLayer
classificationLayer()];
options = trainingOptions('sgdm','MaxEpochs',15, ...
'InitialLearnRate',0.0001);
convnet = trainNetwork(trainDigitData,layers,options);
the data format of the image is 0¬255, but most cnn they trains with data [0,1] so before training, they should normalize the data by data/255.
but in this demo code, the data input of this function is only the index of the image. so I can't do anything to pre-processing the image before.
convnet = trainNetwork(trainDigitData,layers,options);
the only thing I can do to normalize the training data is in the layer
layers = [imageInputLayer([28 28 1])
but the only normalization option this Layer class can support is zero-center (data-mean of data).
what should I do when i want to normalize the input? Or there is no need for a cnn to normalize the training data?

采纳的回答

Scott Weidenkopf
Scott Weidenkopf 2017-7-31
There is not any built-in MATLAB functionality to normalize the data in the manner you describe. A few approaches do exist however:
  1. The R2017b Prerelease adds functionality to create neural networks with custom layers; see the documentation page "Create Custom Layer with Learnable Parameters" (only available after you install the prerelease!). You could create a custom layer after the image input layer that scales the data.
  2. You can pre-process your images to scale the color data, save the scaled images, and then pass the modified images to your neural network.
Whether or not this normalization or scaling is strictly necessary, however, depends on your use case.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 图像深度学习 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!