{"record":{"id":"76e6864958a20f27","repo":"facebookresearch/detectron2","slug":"failed-to-use-mask-format-polygon-from-the-give","errorCode":null,"errorMessage":"Failed to use mask_format=='polygon' from the given annotations!","messagePattern":"Failed to use mask_format=='polygon' from the given annotations!","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"detectron2/data/detection_utils.py","lineNumber":421,"sourceCode":"            [BoxMode.convert(obj[\"bbox\"], obj[\"bbox_mode\"], BoxMode.XYXY_ABS) for obj in annos]\n        )\n        if len(annos)\n        else np.zeros((0, 4))\n    )\n    target = Instances(image_size)\n    target.gt_boxes = Boxes(boxes)\n\n    classes = [int(obj[\"category_id\"]) for obj in annos]\n    classes = torch.tensor(classes, dtype=torch.int64)\n    target.gt_classes = classes\n\n    if len(annos) and \"segmentation\" in annos[0]:\n        segms = [obj[\"segmentation\"] for obj in annos]\n        if mask_format == \"polygon\":\n            try:\n                masks = PolygonMasks(segms)\n            except ValueError as e:\n                raise ValueError(\n                    \"Failed to use mask_format=='polygon' from the given annotations!\"\n                ) from e\n        else:\n            assert mask_format == \"bitmask\", mask_format\n            masks = []\n            for segm in segms:\n                if isinstance(segm, list):\n                    # polygon\n                    masks.append(polygons_to_bitmask(segm, *image_size))\n                elif isinstance(segm, dict):\n                    # COCO RLE\n                    masks.append(mask_util.decode(segm))\n                elif isinstance(segm, np.ndarray):\n                    assert segm.ndim == 2, \"Expect segmentation of 2 dimensions, got {}.\".format(\n                        segm.ndim\n                    )\n                    # mask array\n                    masks.append(segm)","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/facebookresearch/detectron2/blob/a2f4a8771ab77e8411c26b27f24f9489a28a2453/detectron2/data/detection_utils.py#L403-L439","documentation":"Error \"Failed to use mask_format=='polygon' from the given annotations!\" thrown in facebookresearch/detectron2.","triggerScenarios":"Thrown at detectron2/data/detection_utils.py:421 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a2f4a8771ab77e8411c26b27f24f9489a28a2453","analyzedAt":"2026-08-27T12:08:21.260Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}