{"record":{"id":"3ffd97b4eabd4397","repo":"open-mmlab/mmdetection","slug":"in-the-image-with-id-segment-with-id-has-unk","errorCode":null,"errorMessage":"In the image with ID {} segment with ID {} has unknown category_id {}.","messagePattern":"In the image with ID (.+?) segment with ID (.+?) has unknown category_id (.+?)\\.","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"mmdet/evaluation/functional/panoptic_utils.py","lineNumber":98,"sourceCode":"\n        gt_segms = {el['id']: el for el in gt_ann['segments_info']}\n        pred_segms = {el['id']: el for el in pred_ann['segments_info']}\n\n        # predicted segments area calculation + prediction sanity checks\n        pred_labels_set = set(el['id'] for el in pred_ann['segments_info'])\n        labels, labels_cnt = np.unique(pan_pred, return_counts=True)\n        for label, label_cnt in zip(labels, labels_cnt):\n            if label not in pred_segms:\n                if label == VOID:\n                    continue\n                raise KeyError(\n                    'In the image with ID {} segment with ID {} is '\n                    'presented in PNG and not presented in JSON.'.format(\n                        gt_ann['image_id'], label))\n            pred_segms[label]['area'] = label_cnt\n            pred_labels_set.remove(label)\n            if pred_segms[label]['category_id'] not in categories:\n                raise KeyError(\n                    'In the image with ID {} segment with ID {} has '\n                    'unknown category_id {}.'.format(\n                        gt_ann['image_id'], label,\n                        pred_segms[label]['category_id']))\n        if len(pred_labels_set) != 0:\n            raise KeyError(\n                'In the image with ID {} the following segment IDs {} '\n                'are presented in JSON and not presented in PNG.'.format(\n                    gt_ann['image_id'], list(pred_labels_set)))\n\n        # confusion matrix calculation\n        pan_gt_pred = pan_gt.astype(np.uint64) * OFFSET + pan_pred.astype(\n            np.uint64)\n        gt_pred_map = {}\n        labels, labels_cnt = np.unique(pan_gt_pred, return_counts=True)\n        for label, intersection in zip(labels, labels_cnt):\n            gt_id = label // OFFSET\n            pred_id = label % OFFSET","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/evaluation/functional/panoptic_utils.py#L80-L116","documentation":"Every prediction segment's category_id in segments_info must exist in the dataset categories dict used for PQ. An unknown category_id raises KeyError with the image and segment id.","triggerScenarios":"Predictions containing category ids outside the dataset's thing/stuff category map (e.g. id from a different label-space or off-by-one after remapping).","commonSituations":"Model trained on a different number of classes than the eval dataset; category remapping bugs in converters; using continuous ids when eval expects disjoint thing/stuff ids.","solutions":["Verify all category_id values in predictions exist in the COCO panoptic categories used by the metric","Fix label remapping (e.g. CLASSES order, offset for stuff classes) in postprocessing","Re-inspect dataset meta['classes'] / categories file passed to pq_compute_single_core"],"exampleFix":"# before\nsegments_info = [{'id': 1, 'category_id': 999, ...}]\n# after\nassert seg['category_id'] in categories for seg in segments_info  # remap before dump","handlingStrategy":"validation","validationCode":"valid_cats = set(categories)  # or category ids\nassert all(s['category_id'] in valid_cats for s in segments_info), 'unknown category_id in predictions'","typeGuard":null,"tryCatchPattern":"try:\n    pq_compute_single_core(...)\nexcept KeyError as e:\n    if 'unknown category_id' in str(e):\n        raise ValueError('Remap prediction category ids to the eval dataset') from e\n    raise","preventionTips":["Remap model class indices to dataset category ids in postprocess","Validate category ids against the categories dict before eval"],"tags":["panoptic","category-id","data-consistency","mmdetection"],"backgroundTag":"annotation-id-mismatch","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}