image resize deep learning
3 次查看(过去 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
2022-10-30
Dear Amjad, before train the model, why do not perfoem just 2 line code to make all images in same size.
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!