ROC curve Resnet18

1 Ansicht (letzte 30 Tage)
Kanchon Kanti Podder
Kanchon Kanti Podder am 30 Mär. 2020
Beantwortet: Gayathri am 2 Jan. 2025
I have classified 37 classes in Resnet18.
I need to plot ROC for each classes. Help with the code. While compling this code, I got several comments that "error in '[X,Y, AUC, OPTROCPT,SUBY,SUBYNAMES] = perfcurve(cgt, cscores(:,1),1);'"
I have tried it in both 2017b and 2020a online trail.
here is the code from predicted class:
%% test data
test = imageDatastore('test',...
'IncludeSubfolders',true,...
'LabelSource','foldernames');
testValidation = augmentedImageDatastore(inputSize(1:2),test);
[YPredTest,probs]= classify(trainedNet,testValidation);
%% accu test
accuracyTest = mean(YPredTest == test.Labels);
display(accuracyTest)
%% Plot ROC
cgt = double(testValidation);
cscores = probs;
figure(1)
[X,Y, AUC, OPTROCPT,SUBY,SUBYNAMES] = perfcurve(cgt, cscores(:,1),1);
plot(X,Y);
grid
xlabel('False positive rate')
ylabel('True positive rate')
title('ROC for classification CNN')

Antworten (1)

Gayathri
Gayathri am 2 Jan. 2025
To plot the ROC curve for each class in a multi-class classification problem using a ResNet18 model, you need to ensure that the inputs to the "perfcurve function" are correctly formatted. The "perfcurve" function expects true class labels and predicted scores for each class. We will have to add a "for" loop to iterate over each class.
Please refer to the below code which shows the implementation of the same.
numClasses = numel(unique(cgt));
% Plot ROC for each class
figure;
hold on;
for classIdx = 1:numClasses
% True binary labels for the current class
trueLabels = (cgt == classIdx);
% Scores for the current class
scores = probs(:, classIdx);
% Compute ROC curve
[X, Y, ~, AUC] = perfcurve(trueLabels, scores, true);
% Plot ROC curve
plot(X, Y, 'DisplayName', sprintf('Class %d (AUC = %.2f)', classIdx, AUC));
end
For more information on "perfcurve", please refer to the documentation link below.
Hope you find this information helpful!

Kategorien

Mehr zu ROC - AUC 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!

Translated by