常用流程
from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
import numpy as np
import pylab,json
if __name__ == "__main__":
gt_path = "./data/coco/annotations/instances_val2017.json" # 存放真实标签的路径
dt_path = "./results/my_result.json" # 存放检测结果的路径
cocoGt = COCO(gt_path)
cocoDt = cocoGt.loadRes(dt_path)
cocoEval = COCOeval(cocoGt, cocoDt, "bbox") #
cocoEval.evaluate()
cocoEval.accumulate()
cocoEval.summarize()
评估参数如下(括号中的默认值,一般不需要改变):
运行评估代码通过调用 evaluate()
和 accumulate()
产生两个数据结构来衡量检测质量。这两个结构分别是evalImgs 和 eval,它们分别衡量每个图像的质量并聚合到整个数据集中。evalImgs 结构体具有KxA条目,每个评估设置一个,而 eval 结构体将这些信息组合成 precision 和 recall 数组。
最后,summarize()
根据 eval 结构计算前面定义的12个检测指标。
注意事项:
cocoEval.eval['precision']
是一个5维的数组。
# precision -[T*R*K*A*M] precision for every evaluation setting
# catIds -[all] K cat ids to use for evaluation
# iouThrs -[.5:.05:.95] T=10 IoU thresholds for evaluation
# recThrs -[0:.01:1] R=101 recall thresholds for evaluation
# areaRng -[...] A=4 object area ranges for evaluation
# maxDets -[1 10 100] M=3 thresholds on max detections per image
第一维T:IoU的10个阈值,从0.5到0.95,间隔0.05。
第二维R:101个recall 阈值,从0到101。
第三维K:类别,如果是想展示第一类的结果就设为0。
第四维A:area 目标的大小范围 (all,small, medium, large)。
第五维M:maxDets 单张图像中最多检测框的数量三种 1,10,100。
所以,coco_eval.eval['precision'][0,:,0,0,2]
表示的就是第0类物体在IoU=0.5、最大检测数为100时,从0到100的101个recall 对应的101个precision的值。
- 类似的,
cocoEval.eval['recall']
是一个4维的数组。
# recall - [TxKxAxM] max recall for every evaluation setting
# catIds -[all] K cat ids to use for evaluation
# iouThrs -[.5:.05:.95] T=10 IoU thresholds for evaluation
# areaRng -[...] A=4 object area ranges for evaluation
# maxDets -[1 10 100] M=3 thresholds on max detections per image
- 在训练过程中,记录在 log.txt 中的 test_coco_eval_bbox,里面包含的12个数,就是下面的12个评价指标:
A u t h o r : C h i e r Author: Chier Author:Chier