{"record":{"id":"5e13b641bc7fec7f","repo":"roboflow/supervision","slug":"role-class-ids-must-be-finite-integers","errorCode":null,"errorMessage":"{role} class ids must be finite integers.","messagePattern":"(.+?) class ids must be finite integers\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/metrics/detection.py","lineNumber":51,"sourceCode":"    if metric_target == MetricTarget.MASKS:\n        raise ValueError(\n            \"MetricTarget.MASKS is not currently supported for ConfusionMatrix.\"\n        )\n\n\ndef _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.","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/metrics/detection.py#L33-L69","documentation":"Error \"{role} class ids must be finite integers.\" thrown in roboflow/supervision.","triggerScenarios":"Thrown at src/supervision/metrics/detection.py:51 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure class ids are finite integers (no NaN, inf, or float values) for both predictions and targets.","Cast class ids with arr.astype(int) after validating they contain no NaN/inf."],"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-15T22:17:37.221Z"}