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

조회 수: 5 (최근 30일)
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
Bashir Abubakar
Bashir Abubakar 2021년 12월 4일
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 2021년 12월 4일
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 .

댓글을 달려면 로그인하십시오.

답변 (1개)

yanqi liu
yanqi liu 2021년 12월 4일
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))

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by