{"record":{"id":"0822a3c78b91b21d","repo":"open-mmlab/mmdetection","slug":"panopticapi-is-not-installed-please-install-it-by","errorCode":null,"errorMessage":"panopticapi is not installed, please install it by: pip install git+https://github.com/cocodataset/panopticapi.git.","messagePattern":"panopticapi is not installed, please install it by: pip install git\\+https://github\\.com/cocodataset/panopticapi\\.git\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"mmdet/apis/det_inferencer.py","lineNumber":633,"sourceCode":"                'scores': pred_instances.scores.tolist()\n            }\n            if 'bboxes' in pred_instances:\n                result['bboxes'] = pred_instances.bboxes.tolist()\n            if masks is not None:\n                if 'bboxes' not in pred_instances or pred_instances.bboxes.sum(\n                ) == 0:\n                    # Fake bbox, such as the SOLO.\n                    bboxes = mask2bbox(masks.cpu()).numpy().tolist()\n                    result['bboxes'] = bboxes\n                encode_masks = encode_mask_results(pred_instances.masks)\n                for encode_mask in encode_masks:\n                    if isinstance(encode_mask['counts'], bytes):\n                        encode_mask['counts'] = encode_mask['counts'].decode()\n                result['masks'] = encode_masks\n\n        if 'pred_panoptic_seg' in data_sample:\n            if VOID is None:\n                raise RuntimeError(\n                    'panopticapi is not installed, please install it by: '\n                    'pip install git+https://github.com/cocodataset/'\n                    'panopticapi.git.')\n\n            pan = data_sample.pred_panoptic_seg.sem_seg.cpu().numpy()[0]\n            pan[pan % INSTANCE_OFFSET == len(\n                self.model.dataset_meta['classes'])] = VOID\n            pan = id2rgb(pan).astype(np.uint8)\n\n            if is_save_pred:\n                mmcv.imwrite(pan[:, :, ::-1], out_img_path)\n                result['panoptic_seg_path'] = out_img_path\n            else:\n                result['panoptic_seg'] = pan\n\n        if is_save_pred:\n            mmengine.dump(result, out_json_path)\n","sourceCodeStart":615,"sourceCodeEnd":651,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/apis/det_inferencer.py#L615-L651","documentation":"When DetInferencer.postprocess runs pred2dict on a data_sample containing 'pred_panoptic_seg', it needs the panopticapi package to encode the panoptic segmentation to COCO RLE format. If the optional import of VOID (from panopticapi.utils) failed at module load, VOID is None and this RuntimeError is raised with install instructions. It is a missing-optional-dependency error, not a logic bug.","triggerScenarios":"Running DetInferencer on a panoptic segmentation model (e.g., MaskFormer/Mask2Former panoptic configs) with pred2dict invoked (default when results are converted to dicts), in an environment where panopticapi is not installed or failed to import.","commonSituations":"Environments that installed mmdet without the panoptic extra; CI images missing the git dependency; panopticapi import errors due to numpy version incompatibilities (which also leave VOID as None).","solutions":["pip install git+https://github.com/cocodataset/panopticapi.git","If behind a firewall, clone the repo and pip install ./panopticapi","If already installed, verify python -c 'from panopticapi.utils import id2rgb, rgb2id' works and fix any underlying import error (often numpy-related)","If you don't need panoptic output dicts, avoid the code path that calls pred2dict with panoptic predictions"],"exampleFix":"# before\n$ pip list | grep panopticapi  # (nothing)\nres = inferencer('img.jpg')  # RuntimeError\n# after\n$ pip install git+https://github.com/cocodataset/panopticapi.git\nres = inferencer('img.jpg')","handlingStrategy":"validation","validationCode":"try:\n    from panopticapi.utils import id2rgb, rgb2id  # noqa: F401\n    HAS_PANOPTICAPI = True\nexcept ImportError:\n    HAS_PANOPTICAPI = False\nassert HAS_PANOPTICAPI, 'pip install git+https://github.com/cocodataset/panopticapi.git'","typeGuard":"null","tryCatchPattern":"try:\n    out = inferencer(imgs)\nexcept RuntimeError as e:\n    if 'panopticapi' in str(e):\n        raise SystemExit('Missing dependency: pip install git+https://github.com/cocodataset/panopticapi.git')\n    raise","preventionTips":["Declare panopticapi in requirements for any panoptic-model deployment","Add a startup capability check when the config's model type is a panoptic variant (MaskFormer/Mask2Core panoptic heads)","Pin a numpy version compatible with panopticapi if the import fails silently"],"tags":["mmdetection","panoptic-segmentation","missing-dependency","panopticapi"],"backgroundTag":"missing-optional-dependency","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}