roboflow/supervision · error · ValueError

Precision metric requires `class_id` on both predictions and

Error message

Precision metric requires `class_id` on both predictions and targets.

What it means

Error "Precision metric requires `class_id` on both predictions and targets." thrown in roboflow/supervision.

Source

Thrown at src/supervision/metrics/precision.py:217

                    continue
                stats.append(
                    (
                        np.zeros(
                            (len(prediction_class_ids), iou_thresholds.size),
                            dtype=np.bool_,
                        ),
                        np.zeros(
                            (len(prediction_class_ids), iou_thresholds.size),
                            dtype=np.bool_,
                        ),
                        prediction_confidence,
                        prediction_class_ids,
                        np.zeros((0,), dtype=np.int32),
                    )
                )
            elif len(targets) > 0:
                if predictions.class_id is None or targets.class_id is None:
                    raise ValueError(
                        "Precision metric requires `class_id` on both predictions "
                        "and targets."
                    )
                if len(predictions) == 0:
                    target_class_ids = np.asarray(targets.class_id, dtype=np.int32)[
                        target_size_mask
                    ]
                    if len(target_class_ids) == 0:
                        continue
                    stats.append(
                        (
                            np.zeros((0, iou_thresholds.size), dtype=bool),
                            np.zeros((0, iou_thresholds.size), dtype=bool),
                            np.zeros((0,), dtype=np.float32),
                            np.zeros((0,), dtype=int),
                            target_class_ids,
                        )
                    )

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Set class_id on both prediction and target Detections before computing Precision.
  2. Map model and dataset labels to integer class_id arrays.

When it happens

Trigger: Thrown at src/supervision/metrics/precision.py:217 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/2b64723775a235bc. Report an issue: GitHub.