{"record":{"id":"e3c0a4378f6ff42d","repo":"facebookresearch/detectron2","slug":"one-annotation-of-image-image-id-contains-empty","errorCode":null,"errorMessage":"One annotation of image {image_id} contains empty 'bbox' value! This json does not have valid COCO format.","messagePattern":"One annotation of image (.+?) contains empty 'bbox' value! This json does not have valid COCO format\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"detectron2/data/datasets/coco.py","lineNumber":180,"sourceCode":"        record[\"width\"] = img_dict[\"width\"]\n        image_id = record[\"image_id\"] = img_dict[\"id\"]\n\n        objs = []\n        for anno in anno_dict_list:\n            # Check that the image_id in this annotation is the same as\n            # the image_id we're looking at.\n            # This fails only when the data parsing logic or the annotation file is buggy.\n\n            # The original COCO valminusminival2014 & minival2014 annotation files\n            # actually contains bugs that, together with certain ways of using COCO API,\n            # can trigger this assertion.\n            assert anno[\"image_id\"] == image_id\n\n            assert anno.get(\"ignore\", 0) == 0, '\"ignore\" in COCO json file is not supported.'\n\n            obj = {key: anno[key] for key in ann_keys if key in anno}\n            if \"bbox\" in obj and len(obj[\"bbox\"]) == 0:\n                raise ValueError(\n                    f\"One annotation of image {image_id} contains empty 'bbox' value! \"\n                    \"This json does not have valid COCO format.\"\n                )\n\n            segm = anno.get(\"segmentation\", None)\n            if segm:  # either list[list[float]] or dict(RLE)\n                if isinstance(segm, dict):\n                    if isinstance(segm[\"counts\"], list):\n                        # convert to compressed RLE\n                        segm = mask_util.frPyObjects(segm, *segm[\"size\"])\n                else:\n                    # filter out invalid polygons (< 3 points)\n                    segm = [poly for poly in segm if len(poly) % 2 == 0 and len(poly) >= 6]\n                    if len(segm) == 0:\n                        num_instances_without_valid_segmentation += 1\n                        continue  # ignore this instance\n                obj[\"segmentation\"] = segm\n","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/facebookresearch/detectron2/blob/a2f4a8771ab77e8411c26b27f24f9489a28a2453/detectron2/data/datasets/coco.py#L162-L198","documentation":"load_coco_json iterates annotations and rejects any whose 'bbox' list is empty (len 0), because an empty box is meaningless for training and indicates a malformed COCO json.","triggerScenarios":"Loading a COCO-format json (register_coco_instances / load_coco_json) where some annotation has \"bbox\": [] — often produced by converters that emit empty bboxes for degenerate objects instead of omitting the annotation.","commonSituations":"Third-party conversion scripts (VOC/CVAT/labelme -> COCO) writing empty bboxes; datasets with fully-cropped-out or zero-size objects; hand-edited jsons.","solutions":["Clean the json: drop annotations with empty or invalid bbox before registering","Fix the converter to skip objects without a valid 4-element bbox","Or patch upstream to tolerate and skip, though cleaning the data is preferred"],"exampleFix":"# before\nfor ann in coco_json[\"annotations\"]:\n    pass  # empty bboxes present\n# after\nimport json\nd = json.load(open('instances.json'))\nd[\"annotations\"] = [a for a in d[\"annotations\"] if a.get(\"bbox\") and len(a[\"bbox\"]) == 4]\njson.dump(d, open('instances_clean.json', 'w'))","handlingStrategy":"validation","validationCode":"import json\nwith open('instances.json') as f:\n    d = json.load(f)\nbad = [a for a in d['annotations'] if not a.get('bbox')]\nassert not bad, f'{len(bad)} annotations have empty bbox'","typeGuard":"def has_valid_bbox(ann) -> bool:\n    b = ann.get('bbox')\n    return isinstance(b, (list, tuple)) and len(b) == 4 and all(isinstance(v, (int, float)) for v in b)","tryCatchPattern":"try:\n    d = load_coco_json(json_file, img_root, 'mydata')\nexcept ValueError as e:\n    raise SystemExit(f'malformed COCO json: {e}') from e","preventionTips":["Run a COCO-format sanity check (pycocotools.COCO load) before registering","Drop invalid annotations in your conversion pipeline","Add CI validation of dataset jsons"],"tags":["detectron2","coco","dataset-validation","bbox"],"backgroundTag":"dataset-schema-validation-failed","analyzedSha":"a2f4a8771ab77e8411c26b27f24f9489a28a2453","analyzedAt":"2026-08-27T12:08:21.260Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}