Пример #1
0
def test_itself(iou_threshold):
    """Same boxes, with all scores being the same should give 1 as mAP"""
    with open("tests/test_jsons/samples_merged.json") as f:
        list_boxes = json.load(f)

    class_name = "car"

    for item in list_boxes:
        item["score"] = 1

    gt_by_class_name = group_by_key(list_boxes, "name")
    pred_by_class_name = group_by_key(list_boxes, "name")

    recalls, precisions, average_precision = recall_precision(
        gt_by_class_name[class_name], pred_by_class_name[class_name],
        iou_threshold)

    assert average_precision == 1
Пример #2
0
def calc_map(gt_file, pred_file, iou_threshold=0.5):
    with open(pred_file) as f:
        predictions = json.load(f)

    with open(gt_file) as f:
        gt = json.load(f)

    gt_by_class_name = group_by_key(gt, "name")
    pred_by_class_name = group_by_key(predictions, "name")

    class_names = sorted(gt_by_class_name.keys())

    average_precisions = np.zeros(len(class_names))

    for class_id, class_name in enumerate(class_names):
        if class_name in pred_by_class_name:
            _, _, avg_prec = recall_precision(gt_by_class_name[class_name],
                                              pred_by_class_name[class_name],
                                              iou_threshold)
            average_precisions[class_id] = avg_prec

    mAP = np.mean(average_precisions)

    return mAP
Пример #3
0
def _recall_precision(gt, pred, th, class_name):
    recalls, precisions, average_precision = recall_precision(gt, pred, th)
    return class_name, average_precision