{"record":{"id":"8ab92afaec3c1308","repo":"open-mmlab/mmdetection","slug":"cocoevalcap-is-not-installed-please-install-it-by","errorCode":null,"errorMessage":"COCOEvalCap is not installed, please install it by: pip install pycocoevalcap","messagePattern":"COCOEvalCap is not installed, please install it by: pip install pycocoevalcap","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"mmdet/evaluation/metrics/coco_caption_metric.py","lineNumber":44,"sourceCode":"    Args:\n        ann_file (str): the path for the COCO format caption ground truth\n            json file, load for evaluations.\n        collect_device (str): Device name used for collecting results from\n            different ranks during distributed training. Must be 'cpu' or\n            'gpu'. Defaults to 'cpu'.\n        prefix (str, optional): The prefix that will be added in the metric\n            names to disambiguate homonymous metrics of different evaluators.\n            If prefix is not provided in the argument, self.default_prefix\n            will be used instead. Should be modified according to the\n            `retrieval_type` for unambiguous results. Defaults to TR.\n    \"\"\"\n\n    def __init__(self,\n                 ann_file: str,\n                 collect_device: str = 'cpu',\n                 prefix: Optional[str] = None):\n        if COCOEvalCap is None:\n            raise RuntimeError(\n                'COCOEvalCap is not installed, please install it by: '\n                'pip install pycocoevalcap')\n\n        super().__init__(collect_device=collect_device, prefix=prefix)\n        self.ann_file = ann_file\n\n    def process(self, data_batch, data_samples):\n        \"\"\"Process one batch of data samples.\n\n        The processed results should be stored in ``self.results``, which will\n        be used to computed the metrics when all batches have been processed.\n\n        Args:\n            data_batch: A batch of data from the dataloader.\n            data_samples (Sequence[dict]): A batch of outputs from the model.\n        \"\"\"\n\n        for data_sample in data_samples:","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/evaluation/metrics/coco_caption_metric.py#L26-L62","documentation":"COCOCaptionMetric computes captioning scores via COCOEvalCap from the pycocoevalcap package; at construction it raises RuntimeError if the optional import failed.","triggerScenarios":"Instantiating COCOCaptionMetric without `pip install pycocoevalcap`; package installed but its Java/Perl-backed scorers (METEOR, ROUGE) fail to import on some systems.","commonSituations":"Evaluating image-captioning models in minimal docker images; systems lacking Java for pycocoevalcap's METEOR scorer.","solutions":["pip install pycocoevalcap","If METEOR fails, ensure a JRE is available (apt-get install default-jre) or use a scorer subset","Verify: python -c \"from pycocoevalcap.tokenizer.ptbtokenizer import PTBTokenizer\""],"exampleFix":"# before\nmetric = COCOCaptionMetric(ann_file=...)  # RuntimeError\n# after\n# pip install pycocoevalcap\nmetric = COCOCaptionMetric(ann_file=...)","handlingStrategy":"validation","validationCode":"try:\n    from pycocoevalcap.cocoEval import COCOEvalCap  # noqa\nexcept ImportError:\n    raise SystemExit('pip install pycocoevalcap')","typeGuard":null,"tryCatchPattern":"try:\n    COCOCaptionMetric(ann_file)\nexcept RuntimeError as e:\n    if 'pycocoevalcap' in str(e):\n        raise SystemExit('Install pycocoevalcap (and a JRE for METEOR)')\n    raise","preventionTips":["Install pycocoevalcap and a JRE before caption eval","Smoke-test the import in CI environments"],"tags":["captioning","missing-dependency","mmdetection","pycocoevalcap"],"backgroundTag":"missing-optional-dependency","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}