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

1 次查看(过去 30 天)
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);

回答(1 个)

Walter Roberson
Walter Roberson 2022-9-14
Notice 277 compared to 227.
I suggest that you use an augmentedDatastore to implement automatic resizing to 227
  3 个评论
Charlene Rabulan
Charlene Rabulan 2022-9-14
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by