当前位置:   article > 正文

目标检测:tp与fp理解_check if detected bboxes are true positive or fals

check if detected bboxes are true positive or false positive

介绍

在目标检测中,通常采用mAP指标来表达检测模型的性能表现,而mAP指标的计算具体包含几个步骤,其中重要的一步就是TP(真正,即命中)与TP(假正)的计算,具体根据mmdetection中的评估代码mean_ap.py进行分析。

  1. def tpfp_func(det_bboxes,gt_bboxes,iou_thr=0.5):
  2. """Check if detected bboxes are true positive or false positive.
  3. Args:
  4. det_bbox (ndarray): Detected bboxes of this image, of shape (m, 5).
  5. gt_bboxes (ndarray): GT bboxes of this image, of shape (n, 4).
  6. iou_thr (float): IoU threshold to be considered as matched.
  7. Default: 0.5.
  8. Returns:
  9. tuple[np.ndarray]: (tp, fp) whose elements are 0 and 1. The shape of
  10. each array is (num_scales, m).
  11. """
  12. num_dets = det_bboxes.shape[0]
  13. num_gts = gt_bboxes.shape[0]
  14. tp = np.zeros((num_dets), dtype=np.float32)
  15. fp = np.zeros((num_dets), dtype=np.float32)
  16. # if there is no gt bboxes in this image, then all det bboxes are false positives
  17. if gt_bboxes.shape[0] == 0:
  18. fp[...] = 1
  19. return tp, fp
  20. ious = bbox_overlaps(det_bboxes, gt_bboxes)
  21. # for each det, the max iou with all gts
  22. ious_max = ious.max(axis=1)
  23. # for each det, which gt overlaps most with it
  24. ious_argmax = ious.argmax(axis=1)
  25. # sort all dets in descending order by scores
  26. sort_inds = np.argsort(-det_bboxes[:, -1])
  27. gt_covered = np.zeros(num_gts, dtype=bool)
  28. for i in sort_inds:
  29. if ious_max[i] >= iou_thr:
  30. matched_gt = ious_argmax[i]
  31. if not gt_covered[matched_gt]:
  32. gt_covered[matched_gt] = True
  33. tp[i] = 1
  34. else:
  35. fp[i] = 1
  36. else:
  37. fp[i] = 1
  38. return tp, fp
'
运行

上述代码为简化版本,去除了面积约束条件以不予考虑的真实框条件(gt_bboxes_ignore),基础约束条件是预测框与标注框具有相同的类别,具体步骤分析如下:

(1)输入:单张图像单个类别的预测框与标注框

(2)初始化tp,fp为0,分别用于预测框真假情况统计

(3)计算预测框与标注框的最大匹配iou值以及对应的标注框索引

(4)按照预测分数排序预测框,方便优先使用置信度更高的预测框

(5)初始化每个真实标注框匹配情况统计量

(6)按照预测分数从高到底,逐一验证其应当归属于tp与fp中的哪个

(7)阈值约束,若不满足阈值要求,则将此种低质量预测归属为fp,若满足阈值要求,且是真实标注框的初次最佳匹配,则为tp,否则表明预测框为具有较低分数的重复预测框,归于fp。

思考分析:

基于tp与fp,我们只能计算出检测模型的准确率(tp/(tp+fp)),还无法获知召回率,通过结合真实标注框的数量gt_nums,我们可以计算出召回率(tp/gt_nums)。

从召回情况,我们可以分析出此该图像某一类别的漏检情况(与标注框的iou极低,甚至为0)。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/967776
推荐阅读
相关标签
  

闽ICP备14008679号