Python 边界框从头开始的平均精度(AP)
我试图评估人脸检测算法的平均精度。我已经创建了一个包含所有预测边界框的CSV文件。我有另一个类似格式的CSV,包含所有地面真相边界框。我在网上找到了很多简单的代码来计算边界框重叠和计算AP,但它们不适用于给定地面真相的可变数量的预测,即,如果一幅图像有8个边界框预测,而地面真相是10,那么如何计算平均精度 我尝试模仿其中一种算法,并以以下格式创建CSV文件:Python 边界框从头开始的平均精度(AP),python,computer-vision,pytorch,data-science,object-detection,Python,Computer Vision,Pytorch,Data Science,Object Detection,我试图评估人脸检测算法的平均精度。我已经创建了一个包含所有预测边界框的CSV文件。我有另一个类似格式的CSV,包含所有地面真相边界框。我在网上找到了很多简单的代码来计算边界框重叠和计算AP,但它们不适用于给定地面真相的可变数量的预测,即,如果一幅图像有8个边界框预测,而地面真相是10,那么如何计算平均精度 我尝试模仿其中一种算法,并以以下格式创建CSV文件: # Filename-1.jpg [ x1, y1, x2, y2 ] [ x1, y1, x2, y2 ] [ x1, y1, x2,
# Filename-1.jpg
[ x1, y1, x2, y2 ]
[ x1, y1, x2, y2 ]
[ x1, y1, x2, y2 ]
[ x1, y1, x2, y2 ]
# Filename-2.jpg
[ x1, y1, x2, y2 ]
[ x1, y1, x2, y2 ]
[ x1, y1, x2, y2 ]
# Filename-3.jpg
[ x1, y1, x2, y2 ]
[ x1, y1, x2, y2 ]
...
...
...
我还分享了我迄今为止的尝试:
def get_max_iou(pred_boxes, gt_box):
"""
calculate the iou multiple pred_boxes and 1 gt_box (the same one)
pred_boxes: multiple predict boxes coordinate
gt_box: ground truth bounding box coordinate
return: the max overlaps about pred_boxes and gt_box
"""
# 1. calculate the inters coordinate
if pred_boxes.shape[0] > 0:
ixmin = np.maximum(pred_boxes[:, 0], gt_box[:, 0])
ixmax = np.minimum(pred_boxes[:, 2], gt_box[:, 2])
iymin = np.maximum(pred_boxes[:, 1], gt_box[:, 1])
iymax = np.minimum(pred_boxes[:, 3], gt_box[:, 3])
iw = np.maximum(ixmax - ixmin + 1., 0.)
ih = np.maximum(iymax - iymin + 1., 0.)
# 2.calculate the area of inters
inters = iw * ih
# 3.calculate the area of union
uni = ((pred_boxes[:, 2] - pred_boxes[:, 0] + 1.) * (pred_boxes[:, 3] - pred_boxes[:, 1] + 1.) +
(gt_box[2] - gt_box[0] + 1.) * (gt_box[3] - gt_box[1] + 1.) -
inters)
# 4.calculate the overlaps and find the max overlap ,the max overlaps index for pred_box
iou = inters / uni
iou_max = np.max(iou)
nmax = np.argmax(iou)
return iou, iou_max, nmax