{"record":{"id":"6e5bca7acf8c5872","repo":"roboflow/supervision","slug":"role-class-ids-must-be-in-0-num-classes-1","errorCode":null,"errorMessage":"{role} class ids must be in [0, {num_classes - 1}], got {invalid_values}.","messagePattern":"(.+?) class ids must be in \\[0, (.+?)\\], got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/metrics/detection.py","lineNumber":57,"sourceCode":"def _validated_class_ids(\n    values: npt.NDArray[np.float32],\n    num_classes: int,\n    role: str,\n) -> npt.NDArray[np.int64]:\n    \"\"\"Return class ids that are safe to use as confusion-matrix indexes.\"\"\"\n    if values.size == 0:\n        return np.asarray(values, dtype=np.int64)\n\n    finite = np.isfinite(values)\n    integral = values == np.floor(values)\n    if not np.all(finite & integral):\n        raise ValueError(f\"{role} class ids must be finite integers.\")\n\n    class_ids = values.astype(np.int64)\n    invalid = (class_ids < 0) | (class_ids >= num_classes)\n    if np.any(invalid):\n        invalid_values = np.unique(class_ids[invalid]).tolist()\n        raise ValueError(\n            f\"{role} class ids must be in [0, {num_classes - 1}], got {invalid_values}.\"\n        )\n    return class_ids\n\n\ndef detections_to_tensor(\n    detections: Detections,\n    with_confidence: bool = False,\n    metric_target: MetricTarget = MetricTarget.BOXES,\n) -> npt.NDArray[np.float32]:\n    \"\"\"\n    Convert Supervision Detections to a numpy tensor for metric computation.\n\n    Args:\n        detections: Detections/Targets in the format of sv.Detections.\n        with_confidence: Whether to include confidence as the last column.\n        metric_target: The type of detection data to use.\n            Supports `MetricTarget.BOXES` and","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/metrics/detection.py#L39-L75","documentation":"Error \"{role} class ids must be in [0, {num_classes - 1}], got {invalid_values}.\" thrown in roboflow/supervision.","triggerScenarios":"Thrown at src/supervision/metrics/detection.py:57 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure every class id is within [0, num_classes - 1]; remap or filter out-of-range ids.","Check that your class list length matches the maximum class id used in predictions and targets."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}