From def3b4d6979d2d5de39d1663f4c986799e7ad93a Mon Sep 17 00:00:00 2001 From: Yuxin Wu <ppwwyyxxc@gmail.com> Date: Fri, 2 Apr 2021 00:17:43 -0700 Subject: [PATCH] [Refactor]: move pycocotools version check to when it is used (#4880) Co-authored-by: Yuxin Wu <ppwwyyxx@users.noreply.github.com> --- mmdet/datasets/coco.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/mmdet/datasets/coco.py b/mmdet/datasets/coco.py index a46c3031..3a8e1bcf 100644 --- a/mmdet/datasets/coco.py +++ b/mmdet/datasets/coco.py @@ -6,6 +6,7 @@ from collections import OrderedDict import mmcv import numpy as np +import pycocotools from mmcv.utils import print_log from pycocotools.coco import COCO from pycocotools.cocoeval import COCOeval @@ -15,16 +16,6 @@ from mmdet.core import eval_recalls from .builder import DATASETS from .custom import CustomDataset -try: - import pycocotools - if not hasattr(pycocotools, '__sphinx_mock__'): # for doc generation - assert pycocotools.__version__ >= '12.0.2' -except AssertionError: - raise AssertionError('Incompatible version of pycocotools is installed. ' - 'Run pip uninstall pycocotools first. Then run pip ' - 'install mmpycocotools to install open-mmlab forked ' - 'pycocotools.') - @DATASETS.register_module() class CocoDataset(CustomDataset): @@ -53,6 +44,12 @@ class CocoDataset(CustomDataset): Returns: list[dict]: Annotation info from COCO api. """ + if not getattr(pycocotools, '__version__', '0') >= '12.0.2': + raise AssertionError( + 'Incompatible version of pycocotools is installed. ' + 'Run pip uninstall pycocotools first. Then run pip ' + 'install mmpycocotools to install open-mmlab forked ' + 'pycocotools.') self.coco = COCO(ann_file) self.cat_ids = self.coco.get_cat_ids(cat_names=self.CLASSES) -- GitLab