File size: 1,007 Bytes
352cafd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
#!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# Modified by Bowen Cheng from: https://github.com/bowenc0221/boundary-iou-api/blob/master/tools/coco_instance_evaluation.py

"""
Evaluation for COCO val2017:
python ./tools/coco_instance_evaluation.py \
    --gt-json-file COCO_GT_JSON \
    --dt-json-file COCO_DT_JSON
"""
import argparse
import json

from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval

annFile = "dir_to_ann_json_file"
resFile = "dir_to_result_json_file"
simiPath = "dir_to_the_similarity_matrix_of_dataset"
cocoGt = COCO(annFile)

# remove box predictions
resFile = json.load(open(resFile))
for c in resFile:
    c.pop("bbox", None)

cocoDt = cocoGt.loadRes(resFile)
cocoEval = COCOeval(cocoGt, cocoDt, "segm")
cocoEval.params.useCats=1 # class-agnositc
cocoEval.params.openEva=1 # use open-vocabulary evaluation or not
cocoEval.params.simiPath = simiPath
cocoEval.evaluate()
cocoEval.accumulate()
cocoEval.summarize()