roboflow/supervision · error · ValueError

Number of predictions ({len(predictions)}) andtargets ({len(

Error message

Number of predictions ({len(predictions)}) andtargets ({len(targets)}) must be equal.

What it means

Error "Number of predictions ({len(predictions)}) andtargets ({len(targets)}) must be equal." thrown in roboflow/supervision.

Source

Thrown at src/supervision/metrics/detection.py:190

            raise ValueError(
                "ConfusionMatrix can only be calculated for Detections with confidence"
            )
        arrays_to_concat.append(np.expand_dims(detections.confidence, 1))

    result: npt.NDArray[np.float32] = np.concatenate(arrays_to_concat, axis=1)
    return result


def _validate_input_tensors(
    predictions: list[npt.NDArray[np.float32]],
    targets: list[npt.NDArray[np.float32]],
    metric_target: MetricTarget = MetricTarget.BOXES,
) -> None:
    """
    Checks for shape consistency of input tensors.
    """
    if len(predictions) != len(targets):
        raise ValueError(
            f"Number of predictions ({len(predictions)}) and"
            f"targets ({len(targets)}) must be equal."
        )
    if len(predictions) > 0:
        if not isinstance(predictions[0], np.ndarray) or not isinstance(
            targets[0], np.ndarray
        ):
            raise ValueError(
                "Predictions and targets must be lists of numpy arrays. "
                f"Got {type(predictions[0])} and {type(targets[0])} instead."
            )

        expected_pred_cols = (
            10 if metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES else 6
        )
        expected_target_cols = (
            9 if metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES else 5
        )

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Pass equally long lists of predictions and targets, one entry per image.
  2. Pair each image's predictions with its corresponding target before calling the metric.

When it happens

Trigger: Thrown at src/supervision/metrics/detection.py:190 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/e2bc158201925217. Report an issue: GitHub.