image resize deep learning

1 次查看(过去 30 天)
amjad hammad
amjad hammad 2022-10-30
i have problem in image size in matlab
Error using trainNetwork (line 183)
Unexpected image size: All images must have the same size.
Error in neuralkadoplnenienulami (line 58)
net = trainNetwork(imgsTrain,layers,options);
%Trenovacie data pre siet
trainingDataPath = fullfile('C:\Users\amjad\Desktop\COVID-19-master\doplnenie nulami (1)\Triedenie');
trainingImages = imageDatastore(trainingDataPath,'IncludeSubfolders',true,'LabelSource','foldernames');
% Zobrazenie nahodnych trenovacich dat
figure;
perm = randperm(169,16);
for i = 1:16
subplot(4,4,i);
imshow(trainingImages.Files{perm(i)});
end
% Pocet fotografii v jednotlivych triedach
labelCount = countEachLabel(trainingImages);
% Velkost trenovacich fotiek
img = readimage(trainingImages,1);
[sizeR, SizeC] = size(img);
%specifikovanie poctu trenovacich a validacnych dat
numTrainData = 75;
[imgsTrain,imgsValidation] = splitEachLabel(trainingImages,numTrainData,'randomize');
%Definovanie architektury siete
layers = [
imageInputLayer([sizeR SizeC 1])
convolution2dLayer(3,8,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(1,'Stride',2)
convolution2dLayer(3,16,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.01, ...
'MaxEpochs',20, ...
'Shuffle','every-epoch', ...
'ValidationData',imgsValidation, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(imgsTrain,layers,options);
%Klasifikacia dat s vyhodnotenim
clasifydataPath = fullfile('C:\Users\amjad\Desktop\COVID-19-master\doplnenie nulami (1)\Klasifikacia');
clasifyingImages = imageDatastore(clasifydataPath,'IncludeSubfolders',true,'LabelSource','foldernames');
YPred = classify(net,clasifyingImages);
YValidation = clasifyingImages.Labels;
accuracy = sum(YPred == YValidation)/numel(YValidation);
missclassifaction = find(YPred ~= YValidation);
missclassifaction = transpose(missclassifaction);
FP = sum(missclassifaction (:)>8);
FN = sum(missclassifaction (:)<9);
TN = 8-FP;
TP = 8-FN;
  2 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2022-10-30
Dear Amjad, before train the model, why do not perfoem just 2 line code to make all images in same size.
amjad hammad
amjad hammad 2022-11-6
i have chabged all images to same sizes using resize program
Please if you have code to resize images can you provide me

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2022-10-30
https://www.mathworks.com/help/deeplearning/ref/augmentedimagedatastore.html
You use an augmented image data store. That allows you to specify an output size. It also allows you to set rgb or grayscale and will automatically convert images as needed.

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by