how can I extract predicted label and testlabel from already trained deep learning model. the code below gives error while running
5 views (last 30 days)
Show older comments
load('MyVGG19Model.mat');
imdsTest = imageDatastore("C:\Users\Bashir\Desktop\Training dataset\Test set", ...
'IncludeSubfolders',true, ...
'LabelSource','foldernames');
imageAugmenter = imageDataAugmenter( ...
'RandRotation',[-90,90], ...
'RandScale',[1 1.1], ...
'RandXTranslation',[-3 3], ...
'RandYTranslation',[-3 3]);
imageSize = myvgg16.Layers(1).InputSize;
augmentedTestSet = augmentedImageDatastore(imageSize, imdsTest, 'DataAugmentation',imageAugmenter);
predictedLabels = predict(myvgg16, augmentedTestSet);
testLabels = imdsTest.Labels
% Tabulate the results using a confusion matrix.
confMat = confusionmat(testLabels, predictedLabels);
% Convert confusion matrix into percentage form
confMat = bsxfun(@rdivide,confMat,sum(confMat,2))
7 Comments
Walter Roberson
on 4 Dec 2021
You could try
categorical(string(round(predictedLabels)))
but I would recommend looking more carefully at the values in predictedLabels. The values of the predictedLabels might possibly be class numbers, in which case you would want to use them to index the categories that were used in TestLabels .
Answers (1)
yanqi liu
on 4 Dec 2021
load('MyVGG19Model.mat');
imdsTest = imageDatastore("C:\Users\Bashir\Desktop\Training dataset\Test set", ...
'IncludeSubfolders',true, ...
'LabelSource','foldernames');
imageAugmenter = imageDataAugmenter( ...
'RandRotation',[-90,90], ...
'RandScale',[1 1.1], ...
'RandXTranslation',[-3 3], ...
'RandYTranslation',[-3 3]);
imageSize = myvgg16.Layers(1).InputSize;
augmentedTestSet = augmentedImageDatastore(imageSize, imdsTest, 'DataAugmentation',imageAugmenter);
predictedLabels = predict(myvgg16, augmentedTestSet);
testLabels = imdsTest.Labels
% Tabulate the results using a confusion matrix.
confMat = confusionmat(double(testLabels), double(predictedLabels));
% Convert confusion matrix into percentage form
confMat = bsxfun(@rdivide,confMat,sum(confMat,2))
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!