How do I calculate top5/top1 deep learning errors in MATLAB?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Raynier Suresh
el 2 de Dic. de 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:
Ver también
Categorías
Más información sobre Image Data Workflows en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!