image resize deep learning
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
KALYAN ACHARJYA
am 30 Okt. 2022
Dear Amjad, before train the model, why do not perfoem just 2 line code to make all images in same size.
Antworten (1)
Walter Roberson
am 30 Okt. 2022
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!