metricsByArea
Syntax
Description
evaluates object detection metrics for the object size range or ranges, specified as
bounding box areas, areaMetrics
= metricsByArea(metrics
,objectAreaRanges
)objectAreaRanges
. The function evaluates
the specified bounding box size range within the existing object detection
metrics
.
also specifies the names of the classes for which to evaluate area-based
metrics.areaMetrics
= metricsByArea(metrics
,objectAreaRanges
,ClassNames
)
Examples
Evaluate Detection Metrics Across Object Size Ranges
Load a table containing images and ground truth bounding box labels. The first column contains the images, and the remaining columns contain the labeled bounding boxes.
data = load("vehicleTrainingData.mat");
trainingData = data.vehicleTrainingData;
Set the value of the dataDir
variable as the location where the vehicleTrainingData.mat
file is located. Load the test data into a local vehicle data folder.
dataDir = fullfile(toolboxdir("vision"),"visiondata"); trainingData.imageFilename = fullfile(dataDir,trainingData.imageFilename);
Create an imageDatastore
using the files from the table.
imds = imageDatastore(trainingData.imageFilename);
Create a boxLabelDatastore
using the label columns from the table.
blds = boxLabelDatastore(trainingData(:,2:end));
Load a pretrained YOLO v2 object detector trained to detect vehicles into the workspace.
vehicleDetector = load("yolov2VehicleDetector.mat");
detector = vehicleDetector.detector;
Compute Object Detection Performance Metrics
Run the detector on the test images. Set the detection threshold to a low value to detect as many objects as possible. This helps you evaluate the detector precision across the full range of recall values.
results = detect(detector,imds,Threshold=0.01);
Compute metrics for evaluating the performance of an object detector using the evaluateObjectDetection
function.
metrics = evaluateObjectDetection(results,blds);
Evaluate Metrics Across Object Size Ranges
Extract the anchor boxes from the detector, calculate their areas, and sort the areas.
areas = prod(detector.AnchorBoxes,2); sortedAreas = sort(areas);
Define area range limits using the calculated areas. The upper limit for the last range is set to three times the size of the largest area, which is sufficient for the objects in this data set.
lowerLimit = sortedAreas; upperLimit = [sortedAreas(2:end);3*sortedAreas(end)]; areaRanges = [lowerLimit upperLimit]
areaRanges = 4×2
64 960
960 1536
1536 3456
3456 10368
Evaluate detector performance across vehicle size ranges using the metricsByArea
object function. Specify the object size ranges using the bounding box area ranges. The number of vehicles falling into each area range is computed in the NumObjects
column.
areaMetrics = metricsByArea(metrics,areaRanges,ClassName="vehicle");
disp(areaMetrics(:,1:3))
AreaRange NumObjects APOverlapAvg _____________ __________ ____________ 64 960 119 0.9887 960 1536 12 0.99359 1536 3456 45 0.99952 3456 10368 141 0.98551
Plot the average precision (AP) metric, averaged across all overlap thresholds, as a function of the mean object size per vehicle size range.
figure bar(categorical(mean(areaRanges,2)),areaMetrics.APOverlapAvg) title("AP by Vehicle Size") xlabel("Vehicle Anchor Box Mean Area") ylabel("AP") ylim([0.984 1]) grid on
Input Arguments
metrics
— Object detection metrics
M-by-4 numeric matrix | vector
Object detection metrics, specified as an objectDetectionMetrics
object.
objectAreaRanges
— Bounding box area ranges
M-by-2 numeric matrix | vector
Bounding box area ranges (object size ranges), specified as one of the following:
An M-by-2 numeric matrix, with each row specifying the upper (exclusive) and lower (inclusive) limits of an object area range in evaluation. For example, if the input is [x1 x2; x3 x4]. The evaluated bounding box area ranges are x1≤ area <x2 and x3≤ area <x4.
A vector with M+1 elements, specifying the edge values of M contiguous area ranges. Each range is inclusive in the lower limit, and exclusive in the upper limit. For example, if the input is [x1 x2 x3], the area ranges evaluated are x1≤ area <x2 and x2≤ area <x3.
ClassNames
— Names of classes
''
(default) | string scalar | vector
Names of the classes for which to evaluate area-based metrics. If multiple classes are specified, the function computes averaged metrics across the classes. By default, all classes will be considered and the returned metrics will be the average of all classes.
Output Arguments
areaMetrics
— Metrics by area
table
Metrics by area, returned as a table with M rows. Each row contains metrics using objects within an area range (for a total of M area ranges). The columns are specified by these table variables.
AreaRange
: The upper and lower limits of each area range, returned as a two-element row vector.NumObjects
: The number of objects falling within each area range, returned as a positive integer.mAP
: Mean average precision (mAP), or average precision averaged over all classes, computed at all overlap thresholds specified by theOverlapThreshold
property, returned as a numThresh-by-1 numeric vector. numThresh is the number of overlap thresholds.mAPOverlapAvg
: Mean average precision (mAP) averaged over all thresholds specified by theOverlapThreshold
property, returned as a numeric scalar.
Version History
Introduced in R2023b
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)