Clear Filters
Clear Filters

How to evaluate Trained detector on test dataset?

4 views (last 30 days)
Hello,
How can I evaluate Trained detector on test dataset, pelase? Here example code:
tic
detectionResults = detect(Trained_detector, testData, 'MiniBatchSize', 50);
% Evaluate the object detector using average precision metric.
[ap,recall,precision] = evaluateDetectionPrecision(detectionResults, testData);
classID = 1;
figure
plot(recall{classID},precision{classID},'LineWidth',4)
xlabel("recall")
ylabel("accuracy")
grid on
title(sprintf("AP = %.3f",ap(classID)))
toc
Here Error:
Expected I to be one of these types:
double, single, int16, uint16, uint8, logical
Instead its type was matlab.io.datastore.CombinedDatastore.

Accepted Answer

T.Nikhil kumar
T.Nikhil kumar on 14 May 2024
Hello Drov,
I understand that you are trying to test a detector network on a custom dataset using the ‘detect’ function.
The error message suggests that the ‘detect function’ is expecting images of certain types (e.g., double, single, int16, uint16, uint8, logical), but instead, it received an object of type ‘CombinedDatastore’.
The format of test data argument for ‘detect’ function depends on the type of your trained network. I assume you are using a R-CNN deep learning detector. The ‘detect’ function expects the test data to be a numeric array of images (H-by-W-by-C). You will need to convert the test data from a combined datastore to the required array.
For using the ‘detect’ function, I suggest you to first extract the image data from the ‘combinedDatastore’ object and then detect bounding boxes for each image. You can also accumulate results while doing so. Here is a sample code snippet for the process:
% Read all the data from the combined datsstore
allData = readall(testData);
% Extract the images data
imagesData = allData(:,1);
% preallocate detectionResults
detectionResults = zeros(size(imagesData));
% Loop through the images and store detection results
for i = 1:size(imagesData,1)
imageDetectionResult = detect(Trained_detector, imagesData{i});
detectionResults = [detectionResults imageDetectionResult];
end
For evaluating the performance, you can use ‘evaluateObjectDetection’ function. You can use the combinedDatastore object itself with this function.
Refer to the following documentation for more understanding about:
  1. detect function for YOLOv3 network (look at expected data type for images) - https://www.mathworks.com/help/vision/ref/yolov3objectdetector.detect.html
  2. detect function for RCNN network (look at expected data type for images) - https://www.mathworks.com/help/vision/ref/rcnnobjectdetector.detect.html
  3. evaluateObjectDetection - https://www.mathworks.com/help/vision/ref/evaluateobjectdetection.html
Hope this helps you proceed with your work!
  1 Comment
Drov
Drov on 17 May 2024
Hello dear T.Nikhil kumar,
Thanks for your reply. It's help me. But anothe error like this appear:
Dimensions of arrays being concatenated are not consistent.
Error in (line 88)
detectionResults = [detectionResults imageDetectionResult];
I think, detector detected not only one object, but also many objects, so I'm trying to fix this like:
for i = 1:size(imagesData,1)
imageDetectionResult = detect(Trained_detector, imagesData{i});
detectionResults{i} = imageDetectionResult;
end
But another error also appeared:
Unable to perform assignment because brace indexing is not supported for variables of this type.
Can you suggest something please?
Thank you in advance!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!