Hello everyone!
I'm trying to train an AlexNet model to Feature Extraction and i'm getting the following problems:
I have the following imageDatastore:
imds = imageDatastore(fullfile(path),...
'IncludeSubfolders', true, 'LabelSource', 'foldernames',...
'ReadFcn', @preProcess);
As you can see, i'm using the 'ReadFcn' to make resize over all the images from the data set.
My 'preProcess' function:
image = imread(imgFile);
image = imresize(image, [227, 227]);
And my AlexNet model:
net = alexnet;
layers = net.Layers;
layers(end-2) = fullyConnectedLayer(102);
layers(end) = classificationLayer;
options = trainingOptions('sgdm', ...
'MaxEpochs', 6, 'MiniBatchSize', 64, 'ExecutionEnvironment', 'GPU');
[mynet, netinfo] = trainNetwork(imds, layers, options);
I'm getting the following error:
Caused by:
Error using nnet.internal.cnn.MiniBatchDatasourceDispatcher>iCellTo4DArray (line 328)
Unexpected image size: All images must have the same size.
Someone can help me?
Thank you for the support!

댓글 수: 2

Adam
Adam 2018년 4월 5일
It shouldn't be causing your problem (I can't see off-hand what would cause it), but don't name a variable 'image', there is a function of the same name that you are over-riding by doing this.
Hi, Adam, I changed the identifier of the function variable to "img", as you mentioned and i'm still getting this error:
Error using trainNetwork (line 140)
Unexpected image size: All images must have the same size.
Error in modelNet (line 11)
[mynet, netinfo] = trainNetwork(imds, layers, options);
Error in mainFile (line 27)
[mynet, netinfo] = modelNet(numClasses, options, imds);
Caused by:
Error using nnet.internal.cnn.MiniBatchDatasourceDispatcher>iCellTo4DArray (line 328)
Unexpected image size: All images must have the same size.
Thank you for the correction, i forgot the image function!

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

 채택된 답변

Arthur
Arthur 2018년 4월 5일

1 개 추천

Hi everyone! On MATLAB 2017b version, i solved my problem with:
imageSize = [277 277 3];
auimds = augmentedImageSource(imageSize, imds);

댓글 수: 3

YanNuan Li
YanNuan Li 2018년 6월 18일
Hi, I have got the same problem with yours. Could you provide the full code of your training code?
imds=imageDatastore('C:\Users\Onkar\Desktop\HE\brats_test\Testing\HGG_LGG\brats_2013_pat0103_1\VSD.Brain.XX.O.MR_Flair.54193\Dataset','IncludeSubfolders',true,'LabelSource','foldernames');
imageSize = [277 277 3];
auimds = augmentedImageSource(imageSize, imds);
net=alexnet;
layer='fc8';
[imdsTrain,imdsValidation]=splitEachLabel(imds,0.7,'randomized');
featuresTrain=activations(net,imdsTrain,layer,'outputAs','rows');
featuresTest=activations(net,imdsValidation,layer,'outputAs','rows');
svmtrain=fitcsvm(featuresTrain,imdsTrain.Labels);
ypred=predict(svmtrain,featuresTest);
plotconfusion(imdsValidation.Labels,ypred);
This code still gives same error.
@Onkar Mulay
Alexnet accepts images of size [227 227 3]. The code gives you the same error since you are passing the original datastore imds and not auidms. Using the augmented image datastore function won't support using the splitEachLabel function.
If you want to resize the image and split them to imdsTrain and imdsValidation use
imds=imageDatastore('C:\Users\Onkar\Desktop\HE\brats_test\Testing\HGG_LGG\brats_2013_pat0103_1\VSD.Brain.XX.O.MR_Flair.54193\Dataset','IncludeSubfolders',true,'LabelSource','foldernames');
audimds=augmentedImageDatastore([227 227],imds);
% Instead of this line [trainImgs,testImgs] = splitEachLabel(auds,0.85);
% Note that these images are not Randmomized
imdsTrain=partitionByIndex(audimds,[1:900]);
imdsValidation=partitionByIndex(audimds,[901:920]);
numClasses = numel(categories(imds.Labels));

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

질문:

2018년 4월 4일

댓글:

2020년 6월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by