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

14 ビュー (過去 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:
  1 件のコメント
Shahad Alqefari
Shahad Alqefari 2020 年 12 月 2 日
Thank you so much, I will try it

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by