roboflow/supervision · error · ValueError

Invalid metric target: {self._metric_target}

Error message

Invalid metric target: {self._metric_target}

What it means

Error "Invalid metric target: {self._metric_target}" thrown in roboflow/supervision.

Source

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

        if self._metric_target == MetricTarget.BOXES:
            return cast(npt.NDArray[Any], detections.xyxy)
        if self._metric_target == MetricTarget.MASKS:
            if detections.mask is not None:
                # detections.mask is NDArray[bool] | CompactMask; return as-is.
                return detections.mask
            if len(detections) > 0:
                raise ValueError(
                    "Recall with `MetricTarget.MASKS` requires detections to "
                    "include masks."
                )
            return self._make_empty_content()
        if self._metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES:
            obb = detections.data.get(ORIENTED_BOX_COORDINATES)
            if obb is not None and len(obb) > 0:
                result_obb: npt.NDArray[np.float32] = np.array(obb, dtype=np.float32)
                return result_obb
            return self._make_empty_content()
        raise ValueError(f"Invalid metric target: {self._metric_target}")

    def _make_empty_content(self) -> npt.NDArray[Any]:
        if self._metric_target == MetricTarget.BOXES:
            empty_boxes: npt.NDArray[np.float32] = np.empty((0, 4), dtype=np.float32)
            return empty_boxes

        if self._metric_target == MetricTarget.MASKS:
            empty_masks: npt.NDArray[np.bool_] = np.empty((0, 0, 0), dtype=bool)
            return empty_masks

        if self._metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES:
            empty_obb: npt.NDArray[np.float32] = np.empty((0, 4, 2), dtype=np.float32)
            return empty_obb

        raise ValueError(f"Invalid metric target: {self._metric_target}")

        raise ValueError(f"Invalid metric target: {self._metric_target}")

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Construct the metric with a valid MetricTarget value (BOXES, MASKS, or ORIENTED_BOUNDING_BOXES as supported).
  2. Do not mutate the internal metric target; set it only via the constructor.

When it happens

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