def evaluate_predictions_on_coco(coco_gt, coco_results, json_result_file, iou_type="bbox", cfg=cfg): import json with open(json_result_file, "w") as f: json.dump(coco_results, f) from pycocotools.coco import COCO from pycocotools.cocoeval import COCOeval coco_dt = coco_gt.loadRes( str(json_result_file)) if coco_results else COCO() # coco_dt = coco_gt.loadRes(coco_results) coco_eval = COCOeval(coco_gt, coco_dt, iou_type) coco_eval.evaluate() coco_eval.accumulate() coco_eval.summarize() if cfg.PER_CATEGORY_RESULTS: coco_eval.summarize_per_category() return coco_eval