{"record":{"id":"99632d5e5fcad9f1","repo":"roboflow/supervision","slug":"detection-annotation-for-image-image-path-contai","errorCode":null,"errorMessage":"Detection annotation for image {image_path} contains non-integer class_id values with dtype {class_ids.dtype}.","messagePattern":"Detection annotation for image (.+?) contains non-integer class_id values with dtype (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/dataset/core.py","lineNumber":115,"sourceCode":"    ) -> None:\n        self.classes = classes\n\n        if set(images) != set(annotations):\n            raise ValueError(\n                \"The keys of the images and annotations dictionaries must match.\"\n            )\n        self.annotations = {\n            image_path: deepcopy(annotation)\n            for image_path, annotation in annotations.items()\n        }\n\n        np_classes = np.array(self.classes)\n        for image_path, annotation in self.annotations.items():\n            class_ids = annotation.class_id\n            if class_ids is None:\n                continue\n            if not np.issubdtype(class_ids.dtype, np.integer):\n                raise ValueError(\n                    f\"Detection annotation for image {image_path!r} contains \"\n                    f\"non-integer class_id values with dtype {class_ids.dtype}.\"\n                )\n\n            invalid_class_ids = class_ids[\n                (class_ids < 0) | (class_ids >= len(self.classes))\n            ]\n            if len(invalid_class_ids) > 0:\n                valid_range = (\n                    \"empty\"\n                    if len(self.classes) == 0\n                    else f\"[0, {len(self.classes) - 1}]\"\n                )\n                raise ValueError(\n                    f\"Detection annotation for image {image_path!r} contains \"\n                    f\"class_id {int(invalid_class_ids[0])}, outside the valid \"\n                    f\"range {valid_range} for {len(self.classes)} classes.\"\n                )","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/dataset/core.py#L97-L133","documentation":"Raised by the DetectionDataset constructor during annotation validation when an annotation's class_id array has a non-integer dtype (e.g. float32). The constructor later indexes the class-name array with class_ids (np_classes[class_ids]) and fills CLASS_NAME_DATA_FIELD, which requires integer indices; float class ids would either fail indexing or hide data-quality bugs.","triggerScenarios":"Constructing DetectionDataset with annotations whose class_id came from JSON/COCO parsing that produced floats (e.g. [[0.0], [2.0]]) and was cast to a float ndarray instead of int.","commonSituations":"Loading COCO annotations via the json module (all numbers are floats) and building Detections without astype(int); converting from CSVs that parse ids as floats; mixing dtypes when hand-assembling annotations.","solutions":["Cast class_id to an integer dtype when building Detections: class_id=np.array(ids, dtype=np.int64).","If parsing from JSON/COCO, map category ids through int(): np.array([int(a['category_id']) for a in anns], dtype=np.int64).","Audit annotations before construction: assert all Detections.class_id is None or np.issubdtype(d.class_id.dtype, np.integer)."],"exampleFix":"// before\ncls_ids = np.array([0.0, 2.0, 1.0])  # float dtype from JSON parsing\ndets = sv.Detections(xyxy=boxes, class_id=cls_ids)\n\n// after\ncls_ids = np.array([0, 2, 1], dtype=np.int64)\ndets = sv.Detections(xyxy=boxes, class_id=cls_ids)","handlingStrategy":"type-guard","validationCode":"for path, dets in annotations.items():\n    if dets.class_id is not None and not np.issubdtype(dets.class_id.dtype, np.integer):\n        annotations[path] = replace(dets, class_id=dets.class_id.astype(np.int64))\nds = DetectionDataset(classes=classes, images=images, annotations=annotations)","typeGuard":"def integer_class_ids(dets: sv.Detections) -> bool:\n    return dets.class_id is None or np.issubdtype(dets.class_id.dtype, np.integer)","tryCatchPattern":null,"preventionTips":["Always build class_id with an explicit integer dtype: np.array(ids, dtype=np.int64).","After parsing COCO/JSON (all floats), cast ids through int() immediately.","Add a lint-style pass over annotations before dataset construction."],"tags":["dataset","class-id","dtype","coco","validation"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}