roboflow/supervision · error · ValueError

Recall metric requires `class_id` on both predictions and ta

Error message

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

What it means

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

Source

Thrown at src/supervision/metrics/recall.py:236

                    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(
                        "Recall 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 Recall.
  2. Map your model's labels and the dataset's labels to integer class_id arrays.

When it happens

Trigger: Thrown at src/supervision/metrics/recall.py:236 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/caecc70afb843afd. Report an issue: GitHub.