背景:实现相应的目标检测网络需要能够测试mAP
目的:实现mAP的测试。
参考代码:https://github.com/Cartucho/mAP#create-the-ground-truth-files
目录
一、mAP概览
1.1 mAP概览
mAP为目标检测领域的基础指标。
首先标签相同交并比IoU>0.5表示网络检测正确。
然后画出相应的查全率与查准率的曲线,积分得到的蓝色区域即为mAP。
各类的平均AP即mAP
1.2 测试需要的步骤
•Create a separate ground-truth text file for each image. In these files, each line should be in the following format: <class_name> <left> <top> <right> <bottom> [<difficult>]
生成相应的标注文档,无论是GroundTruth还是网络生成的预测,都需要按照上面的格式标注。
•Use matching names (e.g. image: "image_1.jpg", ground-truth: "image_1.txt"; "image_2.jpg", "image_2.txt"...).
然后图片放入相应的文件夹之中。
1.Create the ground-truth files 创建相应的GroundTruth文件
2.Move the ground-truth files into the folder ground-truth/ 放入相应文件夹
3.Create the predicted objects files 创建相应的预测的文件
4.Move the predictions files into the folder predicted/ 放入相应文件夹
5.Run the mAP code 运行mAP的代码
二、GroundTruth文档的生成
按照要求将文件拷入文件夹与生成相应的标注。
<class_name> <left> <top> <right> <bottom> [<difficult>] 标注需要与文件同名且每一行按照这种格式生成。
此部分代码实现了
- 旧用于预测的图像重命名放入新目录下
- 旧标签按照mAP的要求格式生成新标签
三、网络预测结果生成
根据网络预测将所有图片运行一遍,结果写入相应txt文件之中,然后调用mAP测试函数对结果进行预测。
四、预测mAP代码
4.1 运算IoU
4.2 运算AP
先设置两个点,即precision为1的时候,recall为0;precision为0的时候,recall为1
precision随着recall的增减,逐渐减少
创建recall的变化
AP即为曲线下积分的面积
4.3 mAP
根据每类的AP算出mAP
。。。代码中有大量的代码用于画出曲线和显示出ground truth和图像上的prediction等,我们省去此部分。