From c0aba53f4d8b09c47f0d623977bbd0c1c651b9b2 Mon Sep 17 00:00:00 2001 From: Guanghua Yu <742925032@qq.com> Date: Mon, 2 Sep 2019 11:09:09 +0800 Subject: [PATCH] Fix import cocoapi (#3226) --- ppdet/utils/coco_eval.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ppdet/utils/coco_eval.py b/ppdet/utils/coco_eval.py index 655f40693..7640145dd 100644 --- a/ppdet/utils/coco_eval.py +++ b/ppdet/utils/coco_eval.py @@ -24,9 +24,6 @@ import cv2 import numpy as np import matplotlib matplotlib.use('Agg') -from pycocotools.coco import COCO -from pycocotools.cocoeval import COCOeval -import pycocotools.mask as mask_util import logging logger = logging.getLogger(__name__) @@ -74,6 +71,7 @@ def bbox_eval(results, is_bbox_normalized=False): assert 'bbox' in results[0] assert outfile.endswith('.json') + from pycocotools.coco import COCO coco_gt = COCO(anno_file) cat_ids = coco_gt.getCatIds() @@ -104,6 +102,7 @@ def bbox_eval(results, def mask_eval(results, anno_file, outfile, resolution, thresh_binarize=0.5): assert 'mask' in results[0] assert outfile.endswith('.json') + from pycocotools.coco import COCO coco_gt = COCO(anno_file) clsid2catid = {i + 1: v for i, v in enumerate(coco_gt.getCatIds())} @@ -134,6 +133,9 @@ def cocoapi_eval(jsonfile, max_dets: COCO evaluation maxDets. """ assert coco_gt != None or anno_file != None + from pycocotools.coco import COCO + from pycocotools.cocoeval import COCOeval + if coco_gt == None: coco_gt = COCO(anno_file) logger.info("Start evaluate...") @@ -240,6 +242,7 @@ def bbox2out(results, clsid2catid, is_bbox_normalized=False): def mask2out(results, clsid2catid, resolution, thresh_binarize=0.5): + import pycocotools.mask as mask_util scale = (resolution + 2.0) / resolution segm_res = [] @@ -362,6 +365,7 @@ def get_category_info_from_anno(anno_file, with_background=True): with_background (bool, default True): whether load background as class 0. """ + from pycocotools.coco import COCO coco = COCO(anno_file) cats = coco.loadCats(coco.getCatIds()) clsid2catid = { @@ -552,4 +556,4 @@ def coco17_category_info(with_background=True): if not with_background: clsid2catid = {k - 1: v for k, v in clsid2catid.items()} - return clsid2catid, catid2name + return clsid2catid, catid2name \ No newline at end of file -- GitLab