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

조회 수: 11 (최근 30일)
Shahad Alqefari
Shahad Alqefari 2020년 11월 29일
댓글: Shahad Alqefari 2020년 12월 2일
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.

답변 (1개)

Raynier Suresh
Raynier Suresh 2020년 12월 2일
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:

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by