{"record":{"id":"b321cb2f801c0ebb","repo":"open-mmlab/mmdetection","slug":"in-the-image-with-id-segment-with-id-is-pres","errorCode":null,"errorMessage":"In the image with ID {} segment with ID {} is presented in PNG and not presented in JSON.","messagePattern":"In the image with ID (.+?) segment with ID (.+?) is presented in PNG and not presented in JSON\\.","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"mmdet/evaluation/functional/panoptic_utils.py","lineNumber":91,"sourceCode":"\n        # The predictions can only be on the local dist now.\n        pan_pred = mmcv.imread(\n            os.path.join(pred_folder, pred_ann['file_name']),\n            flag='color',\n            channel_order='rgb')\n        pan_pred = rgb2id(pan_pred)\n\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","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/evaluation/functional/panoptic_utils.py#L73-L109","documentation":"During PQ computation, every segment id present in the prediction PNG must have a matching entry in the JSON segments_info. A label found in the PNG (other than VOID=0) but absent from JSON raises KeyError, mirroring the official panopticapi consistency checks.","triggerScenarios":"Postprocessing code that writes instance ids into the PNG but omits/collapses corresponding segments_info entries; overlapping segments merged incorrectly; ids shifted between PNG and JSON.","commonSituations":"Custom panoptic result converters; re-using COCO instance ids instead of contiguous segment ids; VOID pixels encoded with nonzero values.","solutions":["Ensure the PNG writer assigns one unique id per segment and emits exactly one segments_info entry per id","Use the official panopticapi id allocation (png_utils.id2rgb / color encoding) for generating predictions","Treat ignore/void pixels as 0 (VOID) so they are skipped","Re-generate results rather than hand-editing JSON to match"],"exampleFix":"# before\n# PNG has ids {1,2,3}; segments_info lists only {1,2}\n# after\nsegments_info = [{'id': i, 'category_id': c, 'iscrowd': 0, 'area': a} for i, c, a in segments]  # one entry per PNG id","handlingStrategy":"validation","validationCode":"import numpy as np\ndef check_png_json_consistent(pan_png, segments_info, void=0):\n    png_ids = set(np.unique(pan_png)) - {void}\n    json_ids = {s['id'] for s in segments_info}\n    assert png_ids == json_ids, f'PNG-only={png_ids-json_ids} JSON-only={json_ids-png_ids}'","typeGuard":null,"tryCatchPattern":"try:\n    pq_compute_single_core(...)\nexcept KeyError as e:\n    raise ValueError(f'Inconsistent panoptic results: {e}') from e","preventionTips":["Generate PNG and segments_info from one segment dict","Validate consistency before dumping results","Use panopticapi's png_utils for id encoding"],"tags":["panoptic","data-consistency","mmdetection","evaluation"],"backgroundTag":"annotation-id-mismatch","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}