open-mmlab/mmdetection · warning
mmpycocotools is deprecated. Please install official pycocot
Error message
mmpycocotools is deprecated. Please install official pycocotools by "pip install pycocotools"
What it means
Warning from the COCO api wrapper: the installed pycocotools is the deprecated 'mmpycocotools' fork (version string >= '12.0.2' heuristic), and mmdet asks you to move to official pycocotools.
Source
Thrown at mmdet/datasets/api_wrappers/coco_api.py:22
import warnings
from collections import defaultdict
from typing import List, Optional, Union
import pycocotools
from pycocotools.coco import COCO as _COCO
from pycocotools.cocoeval import COCOeval as _COCOeval
class COCO(_COCO):
"""This class is almost the same as official pycocotools package.
It implements some snake case function aliases. So that the COCO class has
the same interface as LVIS class.
"""
def __init__(self, annotation_file=None):
if getattr(pycocotools, '__version__', '0') >= '12.0.2':
warnings.warn(
'mmpycocotools is deprecated. Please install official pycocotools by "pip install pycocotools"', # noqa: E501
UserWarning)
super().__init__(annotation_file=annotation_file)
self.img_ann_map = self.imgToAnns
self.cat_img_map = self.catToImgs
def get_ann_ids(self, img_ids=[], cat_ids=[], area_rng=[], iscrowd=None):
return self.getAnnIds(img_ids, cat_ids, area_rng, iscrowd)
def get_cat_ids(self, cat_names=[], sup_names=[], cat_ids=[]):
return self.getCatIds(cat_names, sup_names, cat_ids)
def get_img_ids(self, img_ids=[], cat_ids=[]):
return self.getImgIds(img_ids, cat_ids)
def load_anns(self, ids):
return self.loadAnns(ids)
View on GitHub (pinned to cfd5d3a985)
Solutions
- pip uninstall mmpycocotools && pip install pycocotools
- Recreate the environment from updated mmdet requirements
Example fix
# before pip install mmpycocotools # after pip uninstall mmpycocotools pip install pycocotools
Defensive patterns
Strategy: validation
Validate before calling
import pycocotools
ver = getattr(pycocotools, '__version__', '0')
if ver >= '12.0.2':
print('deprecated mmpycocotools detected; switch to official pycocotools') Try / catch
import warnings
with warnings.catch_warnings():
warnings.filterwarnings('ignore', message='mmpycocotools is deprecated')
from mmdet.datasets.api_wrappers.coco_api import CocoAPI Prevention
- Pin official pycocotools in requirements
- Avoid legacy mmdet 2.x docker images for new work
When it happens
Trigger: Instantiating CocoAPI/COCO while the mmpycocotools fork (which used inflated version numbers like 12.x) is installed instead of official pycocotools.
Common situations: Old mmdet 2.x environments or Docker images that pinned mmpycocotools; it duplicated code and drifted from upstream.
Related errors
- mmlvis is deprecated, please install official lvis-api by "p
- dataset_meta or class names are not saved in the checkpoint'
- Checkpoint is not loaded, and the inference result is calcul
- weights is None, use COCO classes by default.
- palette does not exist, random is used by default. You can a
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/f1d16e7a2c6f7896.
Report an issue: GitHub.