update samples/test/eval_mAP_on_coco_val/coco_eval.py.

Signed-off-by: jario-jin <jariof@foxmail.com>
This commit is contained in:
jario-jin 2023-08-11 11:27:38 +00:00 committed by Gitee
parent 5b66234c72
commit 7a01223db4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 15 additions and 15 deletions

View File

@ -3,23 +3,23 @@ from pycocotools.cocoeval import COCOeval
import os import os
if __name__ == '__main__': if __name__ == '__main__':
path = os.path.abspath(os.path.join(os.getcwd(),"../../..")) path = os.path.abspath(os.path.join(os.getcwd(),"../../.."))
pred_json = 'pd_coco.json' pred_json = 'pd_coco.json'
anno_json = path + '/val2017/gt_coco.json' anno_json = path + '/val2017/gt_coco.json'
# use COCO API to load forecast results and annotations # use COCO API to load forecast results and annotations
cocoGt = COCO(anno_json) cocoGt = COCO(anno_json)
cocoDt = cocoGt.loadRes(pred_json) cocoDt = cocoGt.loadRes(pred_json)
# create COCO eval object # create COCO eval object
cocoEval = COCOeval(cocoGt, cocoDt,'bbox') cocoEval = COCOeval(cocoGt, cocoDt,'bbox')
# assessment # assessment
cocoEval.evaluate() cocoEval.evaluate()
cocoEval.accumulate() cocoEval.accumulate()
cocoEval.summarize() cocoEval.summarize()
# save results # save results
with open('coco_eval.txt', 'w') as f: with open('coco_eval.txt', 'w') as f:
f.write(str(cocoEval.stats)) f.write(str(cocoEval.stats))