Problem with image size for AlexNet

12 vues (au cours des 30 derniers jours)
Arthur
Arthur le 4 Avr 2018
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 commentaires
Adam
Adam le 5 Avr 2018
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.
Arthur
Arthur le 5 Avr 2018
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!

Connectez-vous pour commenter.

Réponse acceptée

Arthur
Arthur le 5 Avr 2018
Hi everyone! On MATLAB 2017b version, i solved my problem with:
imageSize = [277 277 3];
auimds = augmentedImageSource(imageSize, imds);
  3 commentaires
Onkar Mulay
Onkar Mulay le 5 Fév 2020
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.
Jithin Nambiar J
Jithin Nambiar J le 8 Juin 2020
@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));

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Deep Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by