roboflow/supervision · error · ValueError
{role} class ids must be finite integers.
Error message
{role} class ids must be finite integers. What it means
Error "{role} class ids must be finite integers." thrown in roboflow/supervision.
Source
Thrown at src/supervision/metrics/detection.py:51
if metric_target == MetricTarget.MASKS:
raise ValueError(
"MetricTarget.MASKS is not currently supported for ConfusionMatrix."
)
def _validated_class_ids(
values: npt.NDArray[np.float32],
num_classes: int,
role: str,
) -> npt.NDArray[np.int64]:
"""Return class ids that are safe to use as confusion-matrix indexes."""
if values.size == 0:
return np.asarray(values, dtype=np.int64)
finite = np.isfinite(values)
integral = values == np.floor(values)
if not np.all(finite & integral):
raise ValueError(f"{role} class ids must be finite integers.")
class_ids = values.astype(np.int64)
invalid = (class_ids < 0) | (class_ids >= num_classes)
if np.any(invalid):
invalid_values = np.unique(class_ids[invalid]).tolist()
raise ValueError(
f"{role} class ids must be in [0, {num_classes - 1}], got {invalid_values}."
)
return class_ids
def detections_to_tensor(
detections: Detections,
with_confidence: bool = False,
metric_target: MetricTarget = MetricTarget.BOXES,
) -> npt.NDArray[np.float32]:
"""
Convert Supervision Detections to a numpy tensor for metric computation.View on GitHub (pinned to 7f254d9784)
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.
When it happens
Trigger: Thrown at src/supervision/metrics/detection.py:51 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/5e13b641bc7fec7f.
Report an issue: GitHub.