Clear Filters
Clear Filters

Current learning AlexNet Deep Learning, I am pretty sure my image size are correct but it seems that it doesn't acknowledge it.

1 view (last 30 days)
The code:
alex = alexnet;
layers = alex.Layers;
layers(23) = fullyConnectedLayer(3);
layers(25) = classificationLayer;
allImages = imageDatastore('common weed images','IncludeSubfolders',true,'LabelSource','foldernames');
[trainingImages, testImages] = splitEachLabel(allImages,0.8,'randomized');
opts = trainingOptions("sgdm",'InitialLearnRate', 0.001 ,'MaxEpochs', 30,'MiniBatchSize', 64);
myNet = trainNetwork(trainingImages, layers, opts);
The ERROR:
Error using trainNetwork
The training images are of size 277×277×3 but the input layer expects images of size 227×227×3.
Error in transferLearning (line 18)
myNet = trainNetwork(trainingImages, layers, opts);
Tried using with augmentedimagedatastore:
alex = alexnet;
layers = alex.Layers;
layers(23) = fullyConnectedLayer(3);
layers(25) = classificationLayer;
allImages = imageDatastore('common weed images','IncludeSubfolders',true,'LabelSource','foldernames');
[trainingImages, testImages] = splitEachLabel(allImages,0.8,'randomized');
trainingImages = augmentedImageDatastore([277 277],trainingImages)
testImages = augmentedImageDatastore([277 277],testImages)
opts = trainingOptions('sgdm', 'InitialLearnRate', 0.001,...
'MaxEpochs', 1, 'MiniBatchSize', 1);
myNet = trainNetwork(trainingImages, layers, opts);
Still has the same ERROR:
Error using trainNetwork
The training images are of size 277×277×3 but the input layer expects images of size 227×227×3.
Error in transferLearning (line 18)
myNet = trainNetwork(trainingImages, layers, opts);

Answers (1)

Walter Roberson
Walter Roberson on 14 Sep 2022
Notice 277 compared to 227.
I suggest that you use an augmentedDatastore to implement automatic resizing to 227
  3 Comments
Charlene Rabulan
Charlene Rabulan on 14 Sep 2022
I currently edited my code above. Is it alright if you check that I did it correctly?
It is still showing the same error though if I ever did it correctly

Sign in to comment.

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!