Problem with image size for AlexNet

12 visualizaciones (últimos 30 días)
Arthur
Arthur el 4 de Abr. de 2018
Comentada: Jithin Nambiar J el 8 de Jun. de 2020
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 comentarios
Adam
Adam el 5 de Abr. de 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 el 5 de Abr. de 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!

Iniciar sesión para comentar.

Respuesta aceptada

Arthur
Arthur el 5 de Abr. de 2018
Hi everyone! On MATLAB 2017b version, i solved my problem with:
imageSize = [277 277 3];
auimds = augmentedImageSource(imageSize, imds);
  3 comentarios
Onkar Mulay
Onkar Mulay el 5 de Feb. de 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 el 8 de Jun. de 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));

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Deep Learning Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by