コード例 #1
0
ファイル: coco_utils.py プロジェクト: XrosLiang/SimCal
def coco_eval(result_files, result_types, coco, max_dets=(100, 300, 1000)):
    for res_type in result_types:
        assert res_type in [
            'proposal', 'proposal_fast', 'bbox', 'segm', 'keypoints'
        ]

    if mmcv.is_str(coco):
        coco = COCO(coco)
    assert isinstance(coco, COCO)

    if result_types == ['proposal_fast']:
        ar = fast_eval_recall(result_files, coco, np.array(max_dets))
        for i, num in enumerate(max_dets):
            print('AR@{}\t= {:.4f}'.format(num, ar[i]))
        return

    for res_type in result_types:
        result_file = result_files[res_type]
        # assert result_file.endswith('.json')

        coco_dets = coco.loadRes(result_file)
        img_ids = coco.getImgIds()
        iou_type = 'bbox' if res_type == 'proposal' else res_type
        cocoEval = COCOeval(coco, coco_dets, iou_type)
        cocoEval.params.imgIds = img_ids
        if res_type == 'proposal':
            cocoEval.params.useCats = 0
            cocoEval.params.maxDets = list(max_dets)
        cocoEval.evaluate()
        cocoEval.accumulate()
        cocoEval.summarize()
コード例 #2
0
gt_path = './GT/AVD_split1_test.json'
results_path = './my_results.json'
#gather the object instance ids
all_catIds = [
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
    22, 23, 24, 25, 26, 27
]
known_catIds = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
novel_catIds = [18, 19, 20, 21, 22, 23, 24, 25, 26, 27]

iouThrs = .5
maxDets = [1, 10, 100]
#initialize COCO ground truth api
cocoGt = COCO(gt_path)
#initialize COCO detections api
cocoDt = cocoGt.loadRes(my_results.json)

annType = 'bbox'
cocoEval = COCOeval(cocoGt, cocoDt, annType)
cocoEval.params.iouThrs = np.array([iouThrs])
cocoEval.params.maxDets = maxDets
#cocoEval.params.areaRng = [[0, 10000000000.0], [416, 10000000000.0 ], [0, 416], [416, 1250], [1250, 3750], [3750, 7500], [7500,10000000000.0]]
#cocoEval.params.areaRngLbl = ['all', 'valid', 'l0', 'l1', 'l2', 'l3', 'l4']
cocoEval.params.areaRng = [[0, 10000000000.0]]
cocoEval.params.areaRngLbl = ['all']
cocoEval.params.useSegs = [0]

catIds_types = [all_catIds, known_catIds, novel_catIds]
results = []

for catIds in catIds_types: