使用txt格式的ground truth文件测人脸检测的AP

使用txt格式的ground truth文件测人脸检测的AP

    • 起源
    • 代码
    • GitHub地址

起源

widerface官方的ground truth文件是mat格式的,因为要测试自己的数据,gt文件是txt格式的,所以要修改一下测AP的方法。

代码

测AP的原代码中的部分函数可以直接使用,修改读gt文件和获取gt中人脸框的部分即可,修改部分如下


def evatxt(pred, gt_file, iou_thresh):
    pred = get_preds(pred)
    norm_score(pred)
    boxes_list = get_gt_boxes_from_txt(gt_file)
    thresh_num = 1000
    aps = []
    count_face = 0
    pr_curve = np.zeros((thresh_num, 2)).astype('float')  # control calcultate how many samples
    error_count = 0

    for boxes in boxes_list:
        try:
            image_name = boxes
            event_name = image_name.split('/')[0]
            image_name = image_name.split('/')[1]
            name_all = event_name + '\\' + image_name[:-4]
            pred_list = pred[event_name]
            pred_info = pred_list[name_all]
        except:
            error_count += 1
            continue

        gt_boxes = boxes_list[boxes].astype('float')
        if len(pred_info) == 0 or len(gt_boxes) == 0:
            error_count += 1
            continue
        count_face += len(gt_boxes)
        pred_recall, proposal_list = image_eval(pred_info, gt_boxes, iou_thresh)
        _img_pr_info = img_pr_info(thresh_num, pred_info, proposal_list, pred_recall)
        pr_curve += _img_pr_info
        print(boxes)

    pr_curve = dataset_pr_info(thresh_num, pr_curve, count_face)

    propose = pr_curve[:, 0]
    recall = pr_curve[:, 1]

    ap = voc_ap(recall, propose)
    aps.append(ap)

    print("==================== Results ====================")
    print("Val AP: {}".format(aps[0]))
    print("=================================================")

GitHub地址

你可能感兴趣的:(Face,Detection,python,pytorch,机器学习)