roboflow/supervision · error · ValueError
{role} class ids must be in [0, {num_classes - 1}], got {inv
Error message
{role} class ids must be in [0, {num_classes - 1}], got {invalid_values}. What it means
Error "{role} class ids must be in [0, {num_classes - 1}], got {invalid_values}." thrown in roboflow/supervision.
Source
Thrown at src/supervision/metrics/detection.py:57
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.
Args:
detections: Detections/Targets in the format of sv.Detections.
with_confidence: Whether to include confidence as the last column.
metric_target: The type of detection data to use.
Supports `MetricTarget.BOXES` andView on GitHub (pinned to 7f254d9784)
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.
When it happens
Trigger: Thrown at src/supervision/metrics/detection.py:57 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/6e5bca7acf8c5872.
Report an issue: GitHub.