Neural Network input images size error

조회 수: 2 (최근 30일)
tpolgar
tpolgar 2017년 5월 31일
댓글: Limyandi Vicotrico 2018년 10월 3일
Hello Matlab Community,
I try to train a convolutional nn with labelled images. Currently i just want to understand the usage, its not a specific task.
The inputs are:
files = imageDatastore({'D:\...\containingDirectory1','D:\...\containingDirectory2'});
Which are 200x200x1 grayscale images. I cropped them to 200x200 with a function and checked the sizes manually.
Labels made manually into a categorical struct, then added to the files:
files.Labels = labels;
Layers are:
layers = [ imageInputLayer([200,200,1])
convolution2dLayer(80,80)
reluLayer
maxPooling2dLayer(40,'Stride',40)
fullyConnectedLayer(2)
softmaxLayer
classificationLayer
];
Training options are:
opts = trainingOptions('sgdm','ExecutionEnvironment','cpu');
('cpu' because my GPU capacity is not enough)
Training:
convnet = trainNetwork(files, layers, opts)
Error:
Error using nnet.internal.cnn.ImageDatastoreDispatcher>iCellTo4DArray (line 246)
Unexpected image size: All images must have the same size.
The heights, widths, color channels and bit depths are the same. All of them are jpg-s. I tried to use just 2 images but it resulted the same error. I tried 2 full black images, one copied from the other, and the "training" ran successfully.
I upload two training images for an example.
  댓글 수: 4
Joss Knight
Joss Knight 2017년 6월 7일
Okay, so convert all your image files to RGB.
Limyandi Vicotrico
Limyandi Vicotrico 2018년 10월 3일
how to do this? convert all the imagedatastore to RGB ?

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

답변 (1개)

Aasma Aslam
Aasma Aslam 2018년 1월 4일
inputSize = net.Layers(1).InputSize(1:2) images.ReadFcn = @(loc)imresize(imread(loc),inputSize); use this command for resizing it will work.
  댓글 수: 4
Rabia Afzal
Rabia Afzal 2018년 2월 1일
And what is this InputSize. Where should I use it. Plz help
if true
DatasetPath = fullfile(matlabroot,'MYDATA');
digitData = imageDatastore(DatasetPath,...
'IncludeSubfolders',true,'LabelSource','foldernames');
% inputSize = net.Layers(1).InputSize(1:2) images.ReadFcn = @(loc)imresize(imread(loc),inputSize);
% net=alexnet; % inputSize = net.Layers(1).InputSize(1:2) % im = imresize(im,inputSize); %digitData.ReadFcn = @(loc)imresize(imread(loc),inputSize);
figure; perm = randperm(20000,20); for i = 1:20 subplot(4,5,i); imshow(digitData.Files{perm(i)}); end
labelCount = countEachLabel(digitData)
img = readimage(digitData,20); size(img)
% trainNumFiles = 3000; % [trainDigitData,valDigitData] = splitEachLabel(digitData,trainNumFiles,'randomize'); % % % Define the convolutional neural network architecture. % layers = [ % imageInputLayer([480 640 3]) % % convolution2dLayer(3,16,'Padding',1) % batchNormalizationLayer % reluLayer % % maxPooling2dLayer(2,'Stride',2) % % convolution2dLayer(3,32,'Padding',1) % batchNormalizationLayer % reluLayer % % maxPooling2dLayer(2,'Stride',2) % % convolution2dLayer(3,64,'Padding',1) % batchNormalizationLayer % reluLayer % % fullyConnectedLayer(4) % softmaxLayer % classificationLayer]; % % options = trainingOptions('sgdm',... % 'MaxEpochs',3, ... % 'ValidationData',valDigitData,... % 'ValidationFrequency',30,... % 'Verbose',false,... % 'Plots','training-progress'); % % % net = trainNetwork(trainDigitData,layers,options); % % % predictedLabels = classify(net,valDigitData); % valLabels = valDigitData.Labels; % % accuracy = sum(predictedLabels == valLabels)/numel(valLabels) end
Limyandi Vicotrico
Limyandi Vicotrico 2018년 10월 3일
can someone elaborate more on how it work again? I cant get it working.
inputSize = net.Layers(1).InputSize(1:2);
imds.ReadFcn = @(loc)imresize(imread(loc),inputSize);

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

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by