roboflow/supervision · error · ValueError

Confusion matrix must have shape (..., 3), got {confusion_ma

Error message

Confusion matrix must have shape (..., 3), got {confusion_matrix.shape}

What it means

Error "Confusion matrix must have shape (..., 3), got {confusion_matrix.shape}" thrown in roboflow/supervision.

Source

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

        result_matrix: npt.NDArray[np.float64] = confusion_matrix
        return result_matrix

    @staticmethod
    def _compute_precision(
        confusion_matrix: npt.NDArray[np.float64],
    ) -> npt.NDArray[np.float64]:
        """
        Broadcastable function, computing the precision from the confusion matrix.

        Args:
            confusion_matrix: shape (N, ..., 3), where the last dimension
                contains the true positives, false positives, and false negatives.

        Returns:
            shape (N, ...), containing the precision for each element.
        """
        if not confusion_matrix.shape[-1] == 3:
            raise ValueError(
                f"Confusion matrix must have shape (..., 3), got "
                f"{confusion_matrix.shape}"
            )
        true_positives = confusion_matrix[..., 0]
        false_positives = confusion_matrix[..., 1]

        denominator = true_positives + false_positives
        precision = np.divide(
            true_positives,
            denominator,
            out=np.zeros_like(true_positives),
            where=denominator != 0,
        )

        result_precision: npt.NDArray[np.float64] = precision
        return result_precision

    def _detections_content(self, detections: Detections) -> npt.NDArray[Any]:

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Provide a confusion matrix whose last dimension is 3.
  2. Use the metric's own computation methods to build the matrix instead of constructing it manually.

When it happens

Trigger: Thrown at src/supervision/metrics/precision.py:496 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/4e86f6a8bc3e128b. Report an issue: GitHub.