main Content

评估估计

Evaluate precision metric for object detection

描述

平均推荐=评估eTectectionPrecision(检测,,,,地面图返回平均精度检测compared to the地面图。您可以使用平均精度来测量对象检测器的性能。对于多类检测器,该函数返回平均推荐作为每个对象类的分数向量,地面图

例子

[[平均推荐,,,,记起,,,,精确] =评估eTectectionPrecision(___返回使用上一个语法中的输入参数,用于绘制精度 - 记录曲线的数据点。

[[___] =评估eTectectionPrecision(___,,,,阈值指定将检测分配到地面真相框的重叠阈值。

例子

全部收缩

此示例显示了如何评估验证的Yolo V2对象检测器。

加载车辆地面真相数据

加载包含车辆训练数据的表。第一列包含训练图像,其余列包含标记的边界框。

数据=负载('vehicleTrainingData.mat');trainingData = data.vehicleTrainingData;

Add fullpath to the local vehicle data folder.

dataDir = fullfile(toolboxdir('想象'),'VisionData');triendingdata.imagefileName = fullfile(datadir,trienchdata.imagefileName);

使用表中的文件创建Imagedatastore。

IMD= imageDatastore(trainingData.imageFilename);

使用表中的标签列创建一个BoxLabelDatastore。

blds = boxlabeldatastore(triendingdata(:,2:end));

Load YOLOv2 Detector for Detection

加载包含用于训练的层图的检测器。

vehicleDetector = load('yolov2VehicleDetector.mat');检测器= vehicledetector.detector;

Evaluate and Plot the Results

使用Imagedatastore运行检测器。

结果=检测(检测器,IMD);

根据地面真实数据评估结果。

[AP,召回,精度] = RestectectionEtectionPrecision(结果,大厦);

Plot the precision/recall curve.

figure; plot(recall, precision); gridon标题(sprintf(sprintf)('Average precision = %.1f',AP))

使用预加载的地面真相信息培训基于ACF的检测器。在训练图像上运行检测器。评估检测器并显示Precision-Recall曲线。

Load the ground truth table.

加载(“ stopsignsandcars.mat”)stopSigns = stopSignSandCars(:,1:2);stopSigns.imageFileName = fullfile(toolboxDir(toolboxDir)('想象'),'VisionData',,,,...stopSigns.imageFileName);

训练基于ACF的检测器。

detector = trainACFObjectDetector(stopSigns,“否定样本”,2);
ACF对象探测器训练培训将进行4个阶段。型号的大小为34x31。样本阳性示例(〜100%完成)计算近似系数...完成。计算汇总的通道功能...完成。-------------------------------------------- Stage 1: Sample negative examples(〜100%完成)计算汇总的通道功能...完成。火车分类器,有42个积极的例子和84个负面示例...完成。训练有素的分类器有19个薄弱的学习者。-------------------------------------------- Stage 2: Sample negative examples(〜100%完成)发现了84个新的负面示例用于培训。计算汇总的通道功能...完成。火车分类器,有42个积极的例子和84个负面示例...完成。 The trained classifier has 20 weak learners. -------------------------------------------- Stage 3: Sample negative examples(~100% Completed) Found 84 new negative examples for training. Compute aggregated channel features...Completed. Train classifier with 42 positive examples and 84 negative examples...Completed. The trained classifier has 54 weak learners. -------------------------------------------- Stage 4: Sample negative examples(~100% Completed) Found 84 new negative examples for training. Compute aggregated channel features...Completed. Train classifier with 42 positive examples and 84 negative examples...Completed. The trained classifier has 61 weak learners. -------------------------------------------- ACF object detector training is completed. Elapsed time is 14.4221 seconds.

Create a table to store the results.

numImages =高度(stopsigns);结果=表('尺寸',[数字2],...'VariableTypes',,,,{'细胞',,,,'细胞'},,...'variablenames',,,,{“盒子”,,,,“得分”});

在训练图像上运行检测器。Store the results as a table.

为了i = 1:numImages i = imread(stopSigns.imageFileName {i});[bboxes,分数] =检测(检测器,i);results.boxes {i} = bboxes;results.scores {i} = scores;结尾

根据地面真实数据评估结果。获取精度统计。

[[ap,recall,precision] = evaluateDetectionPrecision(results,stopSigns(:,2));

绘制Precision-Recall曲线。

图图(召回,精度)网格on标题(sprintf(sprintf)('平均精度=%.1F',AP))

图包含一个轴对象。标题平均精度= 0.7的轴对象包含一个类型行的对象。

输入参数

全部收缩

对象位置和分数,指定为一个两列表,其中包含每个检测到的对象的边界框和得分。对于多类检测,第三列包含每个检测的预测标签。边界框必须存储在一个m-by-4单元阵列。分数必须存储在m-b-1单元阵列,标签必须存储为分类向量。

检测对象时,您可以使用imageDatastore

ds = imageDatastore(stopSigns.imageFilename); detectionResults = detect(detector,ds);

数据类型:桌子

标记为地面真相,指定为数据存储或表格。

每个边界框必须以格式[Xy宽度高度]。

  • 数据存储 - 一个数据存储readand读取functions return a cell array or a table with at least two columns of bounding box and labels cell vectors. The bounding boxes must be in a cell array ofm-by-4 matrices in the format [X,,,,y,,,,宽度,,,,高度]。数据存储readand读取功能必须返回其中一种格式:

    • {盒子,,,,标签} — TheBoxLabeldatastore创建这种类型的数据存储。

    • {图片,,,,盒子,,,,标签} - 一个组合的数据存储。例如,使用combine((IMD,,,,大厦)。

    BoxLabeldatastore

  • 表 - 一个或多个列。所有列都包含边界框。每列必须是包含的单元向量m- 代表单个对象类的by-4矩阵,例如停止标志,,,,Carrear, 或者卡饰。这些列包含4个元素的双阵列mbounding boxes in the format [X,,,,y,,,,宽度,,,,高度]。The format specifies the upper-left corner location and size of the bounding box in the corresponding image.

将检测分配到地面真相框的重叠阈值,该框指定为数字标量。重叠比计算为与联合的交集。

输出参数

全部收缩

在所有检测结果中,平均精度为数字标量或向量。精确是真正的积极实例与基于地面真理中对象中的所有积极实例的比率。对于多类检测器,the average precision is a vector of average precision scores for each object class.

记起values from each detection, returned as anm-1数字标量或单元阵列的by-1矢量。长度mequals 1 + the number of detections assigned to a class. For example, if your detection results contain 4 detections with class label'车', 然后记起包含5个元素。召回的第一个价值总是0

记起是真正的积极实例与基于地面真理的真实积极因素和虚假的总和的比例。对于多类检测器,记起and精确是单元格数,每个单元格包含每个对象类的数据点。

每个检测中的精确值,返回为m-1数字标量或单元阵列的by-1矢量。长度mequals 1 + the number of detections assigned to a class. For example, if your detection results contain 4 detections with class label'车', 然后精确包含5个元素。第一个值精确总是1

精确是真正的积极实例与基于地面真理中对象中的所有积极实例的比率。对于多级检测器,记起and精确是单元格数,每个单元格包含每个对象类的数据点。

版本历史记录

在R2017A中引入