Clear Filters
Clear Filters

How to asign class name to detection result?

2 views (last 30 days)
Hello guys, after running YOLOv4 detector which I made with help of example on MathWorks page, I run detector on test image and it shows the labels also the score for each label but doesn’t show the name of the predicted class… how to add the class name for each label in results?

Answers (1)

Walter Roberson
Walter Roberson on 24 May 2023
Second output of max() can tell you the index of the most probable class. Then you can use the index to index the class names.
classnames = ["Ruby"; "Zattar"; "Swing"; "BobbleHead"];
classvals = rand(10, length(classnames)) %except for you classvals would be output from classification
classvals = 10×4
0.5384 0.3619 0.4176 0.2853 0.7656 0.1626 0.3680 0.7192 0.5841 0.5552 0.2617 0.1193 0.5984 0.8255 0.3526 0.1028 0.3517 0.7155 0.6643 0.0133 0.9461 0.3689 0.9351 0.5620 0.2196 0.2865 0.3528 0.5704 0.3844 0.2757 0.1887 0.9862 0.6093 0.7014 0.6494 0.0568 0.5415 0.2472 0.4460 0.3464
[~, classidx] = max(classvals, [], 2);
detected_class = classnames(classidx)
detected_class = 10×1 string array
"Ruby" "Ruby" "Ruby" "Zattar" "Zattar" "Ruby" "BobbleHead" "BobbleHead" "Zattar" "Ruby"

Community Treasure Hunt

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

Start Hunting!