{"record":{"id":"8df239faf4b9cbde","repo":"open-mmlab/mmdetection","slug":"in-the-image-with-id-the-following-segment-ids","errorCode":null,"errorMessage":"In the image with ID {} the following segment IDs {} are presented in JSON and not presented in PNG.","messagePattern":"In the image with ID (.+?) the following segment IDs (.+?) are presented in JSON and not presented in PNG\\.","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"mmdet/evaluation/functional/panoptic_utils.py","lineNumber":104,"sourceCode":"        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\n            gt_pred_map[(gt_id, pred_id)] = intersection\n\n        # count all matched pairs\n        gt_matched = set()\n        pred_matched = set()\n        for label_tuple, intersection in gt_pred_map.items():","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/evaluation/functional/panoptic_utils.py#L86-L122","documentation":"Inverse consistency check of error 68: every id listed in segments_info must appear as a nonzero label in the prediction PNG. Leftover JSON ids not found in the PNG raise KeyError listing the missing ids.","triggerScenarios":"segments_info entries kept for segments that were dropped, merged, or fully suppressed when writing the PNG; tiny segments lost to resizing; empty masks encoded as absent.","commonSituations":"Postprocessing that filters PNG masks (e.g. min-area threshold) without updating JSON; PNG encoding that maps some ids to 0 due to dtype overflow (ids > 65535 in uint16).","solutions":["Write the PNG and segments_info from the same final segment set (single source of truth)","Use int32-safe PNG encoding so large ids are not truncated","Filter both JSON and PNG consistently when applying min-area/size thresholds"],"exampleFix":"# before\n# JSON ids {1,2,3}; PNG contains {1,2} only\n# after\nresult_panpng[seg_mask] = seg['id']  # write every seg in segments_info to PNG\njson.dump({'segments_info': segments_info, ...}, f)","handlingStrategy":"validation","validationCode":"png_ids = set(np.unique(pan_png)) - {0}\njson_ids = {s['id'] for s in segments_info}\nassert png_ids == json_ids, f'missing in PNG: {json_ids - png_ids}'","typeGuard":null,"tryCatchPattern":"try:\n    pq_compute_single_core(...)\nexcept KeyError as e:\n    if 'not presented in PNG' in str(e):\n        raise ValueError('Regenerate PNG so all JSON segment ids are painted') from e\n    raise","preventionTips":["Paint every segments_info id into the PNG, no filtering after JSON creation","Use int32 arrays for id maps to avoid truncation","Apply min-area filters before writing either artifact"],"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"}