How do I calculate top5/top1 deep learning errors in MATLAB?

11 vues (au cours des 30 derniers jours)
Shahad Alqefari
Shahad Alqefari le 29 Nov 2020
Commenté : Shahad Alqefari le 2 Déc 2020
Hello everyone.
I implemented different CNN models (AlexNet, DensNET), and I want to compare them based on top1/top5 error, but I couldn't find any useful tips regarding this point.
Would be appreciated if someone could help me.

Réponses (1)

Raynier Suresh
Raynier Suresh le 2 Déc 2020
Top 1 Accuracy:
Output from the model that is the output label with highest probability needs to be same as expected
You can use the below code for Top-1 Accuracy
[YPred,scores] = classify(net,imdsValidation)
YValidation = imdsValidation.Labels;
top1Accuracy = mean(YPred == YValidation)
Top 5 Accuracy:
Any of the top 5 probability label obtained from the network must match with the original label.
You can use the below code for Top-5 Accuracy
[~,scores] = classify(net,imdsValidation);
YValidation = imdsValidation.Labels;
[n,m] = size(scores);
idx = zeros(m,n);
for i=1:n
[~,idx(:,i)] = sort(scores(i,:),'descend');
end
idx = idx(1:5,:);
top5Classes = net.Layers(end).ClassNames(idx);
top5count = 0;
for i = 1:n
top5count = top5count + sum(YValidation(i,1) == top5Classes(:,i));
end
top5Accuracy = top5count/n
Refer the below links for more information:

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by