How do I calculate top5/top1 deep learning errors in MATLAB?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Raynier Suresh
am 2 Dez. 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:
Siehe auch
Kategorien
Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!