필터 지우기
필터 지우기

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.
  댓글 수: 2
Mona
Mona 2017년 10월 31일
Hi. I was wondering the same thing. How to create a custom data pr-processing layer? Say that I want to manually take a random crop of every image in each mini-batch. How do I define the layer?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 图像深度学习에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!