how can I extract predicted label and testlabel from already trained deep learning model. the code below gives error while running

5 visualizaciones (últimos 30 días)
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 comentarios
Bashir Abubakar
Bashir Abubakar el 4 de Dic. de 2021
Thank you walter for support. TestLabels showed categorical While predictedLabels showed single. I want them all to be of class categorical. How do I go about that pls.
Walter Roberson
Walter Roberson el 4 de Dic. de 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 .

Iniciar sesión para comentar.

Respuestas (1)

yanqi liu
yanqi liu el 4 de Dic. de 2021
yes,sir,as Walter Roberson said,may be ensure data class,such as
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))

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by