hoe to evaluate trained faster rcnn detector
3 views (last 30 days)
Show older comments
hi everyone
i want ti ecaluate my faster Rcnn detector on testdta set i tried this code but i got error on evaluationobjectdetector
lassID = 1;
metrics = evaluateObjectDetection(detectionResults,testData);
precision = metrics.ClassMetrics.Precision{classID};
recall = metrics.ClassMetrics.Recall{classID}
than i tried this code is aldo so error
testData = transform(testData,@(data)preprocessData(data,inputSize));
detectionResults = detect(detector,testData,'MinibatchSize',10);
% Determine the number of classes in your dataset
num_classes = 5;
% Preallocate arrays to store precision and recall values for all classes
precisions = zeros(1, num_classes);
recalls = zeros(1, num_classes);
% Loop through all class IDs
for classID = 1:num_classes
% Evaluate precision and recall for the current class ID
metrics = fasterRCNNtestdetect(detectionResults, testData);
precision = metrics.ClassMetrics.Precision{classID};
recall = metrics.ClassMetrics.Recall{classID};
% Store precision and recall for the current class
precisions(classID) = precision;
recalls(classID) = recall;
0 Comments
Answers (1)
Maneet Kaur Bagga
on 14 Nov 2023
Hi Ahmad,
After reproducing the code at my end, as per my understanding the syntax error is because of the "ClassMetrics" of the "evaluateObjectDetection" function. The metrics.ClassMetrics represents a table and for each class it represents a row, hence to access each class iterate through all the rows and for each row access the "precision" and "recall" property.
Please refer to the following code snippet for better understanding of the workaround.
% Evaluate object detection
metrics = evaluateObjectDetection(detectionResults, groundTruthData);
% Access precision and recall for each class
classMetrics = metrics.ClassMetrics;
% Loop through each class and obtain precision and recall
for classID = 1:numel(classMetrics)
precision = classMetrics(classID).Precision;
recall = classMetrics(classID).Recall;
% Do something with precision and recall for the current class
fprintf('Class %d: Precision = %.2f, Recall = %.2f\n', ...
classID, precision, recall);
end
Please refer to the following MATLAB documentaion specially the "ClassMetrics" section.
objectDetectionMetrics : https://www.mathworks.com/help/vision/ref/objectdetectionmetrics.html
Hope this helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!