roboflow/supervision · warning · ValueError
Unsupported metric target for IoU calculation
Error message
Unsupported metric target for IoU calculation
What it means
Inside MeanAverageRecall.compute(), after extracting per-detection content, the code dispatches IoU computation by metric target: box_iou_batch for BOXES, mask_iou_batch for MASKS, oriented_box_iou_batch for ORIENTED_BOUNDING_BOXES. This ValueError is the else-branch exhaustiveness guard: the configured _metric_target matched none of the three. Like errors 340/341 it signals a corrupted or non-enum metric_target rather than a user data problem.
Source
Thrown at src/supervision/metrics/mean_average_recall.py:455
prediction_confidence = np.asarray(
predictions.confidence, dtype=np.float32
)
if self._metric_target == MetricTarget.BOXES:
# BOXES target never yields CompactMask; narrow for mypy.
iou = box_iou_batch(
cast(npt.NDArray[np.number], target_contents),
cast(npt.NDArray[np.number], prediction_contents),
)
elif self._metric_target == MetricTarget.MASKS:
iou = mask_iou_batch(target_contents, prediction_contents)
elif self._metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES:
# OBB target never yields CompactMask; narrow for mypy.
iou = oriented_box_iou_batch(
cast(npt.NDArray[np.number], target_contents),
cast(npt.NDArray[np.number], prediction_contents),
)
else:
raise ValueError(
"Unsupported metric target for IoU calculation"
)
matches, _ = _match_detection_batch_with_target_indices(
prediction_class_ids,
target_class_ids,
iou,
iou_thresholds,
)
ignored_matches = np.zeros_like(matches, dtype=bool)
sorted_indices = np.argsort(-prediction_confidence)
stats.append(
(
matches[sorted_indices],
ignored_matches[sorted_indices],
np.arange(len(prediction_confidence)),
prediction_class_ids[sorted_indices],View on GitHub (pinned to 7f254d9784)
Solutions
- Construct with a valid MetricTarget enum member: BOXES, MASKS, or ORIENTED_BOUNDING_BOXES
- Validate config-sourced values against MetricTarget before constructing the metric
- Do not mutate private state; create a new metric per target
- Fork maintainers: extend the if/elif dispatch when adding a MetricTarget member
Example fix
// before mar = MeanAverageRecall(metric_target=object()) # nonsense target mar.compute() // after from supervision.metrics import MetricTarget mar = MeanAverageRecall(metric_target=MetricTarget.BOXES) mar.compute()
Defensive patterns
Strategy: type-guard
Validate before calling
from supervision.metrics.mean_average_recall import MetricTarget assert isinstance(metric_target, MetricTarget), 'use MetricTarget enum members only'
Type guard
from supervision.metrics.mean_average_recall import MetricTarget
def is_supported_iou_target(value) -> bool:
"""True for the three targets with an IoU implementation in MAR."""
return value in (MetricTarget.BOXES, MetricTarget.MASKS,
MetricTarget.ORIENTED_BOUNDING_BOXES) Try / catch
try:
mar.compute()
except ValueError as e:
if 'Unsupported metric target' in str(e):
raise RuntimeError('metric_target corrupted; recreate MeanAverageRecall') from e
raise Prevention
- Only use enum members for metric_target
- Fork authors: extend the IoU dispatch when adding enum values
- Recreate metric objects instead of mutating internals
When it happens
Trigger: An invalid metric_target value reaching the constructor (raw int, string, or foreign enum) that still passed the earlier content extraction via an unexpected path; mutating _metric_target between update() and compute(); pickling a metric across supervision versions with enum changes; custom forks adding a new MetricTarget member without extending this dispatch.
Common situations: Same class of misuse as 340/341: config-driven metric_target strings not validated; version skew between environments; fork/new-enum contributions forgetting the IoU dispatch table.
Related errors
- Invalid metric target: {self._metric_target}
- Confusion matrix must have shape (..., 3), got {confusion_ma
- Invalid metric target: {self._metric_target}
- Value must be a np.ndarray or a list
- The number of predictions ({len(predictions)}) and targets (
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/fc1fd88552c457d0.
Report an issue: GitHub.