chenhang98 / BPR

code for `Look Closer to Segment Better: Boundary Patch Refinement for Instance Segmentation`
Apache License 2.0
174 stars 23 forks source link

get AP value #24

Closed weijinmeng closed 2 years ago

weijinmeng commented 2 years ago

I want to know how to get AP metrics.

chenhang98 commented 2 years ago

You can use these codes for COCO dataset.

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

#initialize COCO ground truth api
annFile = sys.argv[2]
cocoGt=COCO(annFile)
#initialize COCO detections api
resFile = sys.argv[1]
cocoDt=cocoGt.loadRes(resFile)

imgIds=sorted(cocoGt.getImgIds())
# running evaluation
cocoEval = COCOeval(cocoGt, cocoDt, 'segm')
cocoEval.params.imgIds  = imgIds
cocoEval.evaluate()
cocoEval.accumulate()
cocoEval.summarize()