roboflow/supervision · error · ValueError
Targets must have shape (N, {expected_target_cols}). Got {ta
Error message
Targets must have shape (N, {expected_target_cols}). Got {targets.shape} instead. What it means
Error "Targets must have shape (N, {expected_target_cols}). Got {targets.shape} instead." thrown in roboflow/supervision.
Source
Thrown at src/supervision/metrics/detection.py:914
Returns:
Confusion matrix based on a single image.
"""
_assert_supported_target(metric_target)
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
)
if predictions.ndim != 2 or predictions.shape[1] != expected_pred_cols:
raise ValueError(
f"Predictions must have shape (M, {expected_pred_cols}). "
f"Got {predictions.shape} instead."
)
if targets.ndim != 2 or targets.shape[1] != expected_target_cols:
raise ValueError(
f"Targets must have shape (N, {expected_target_cols}). "
f"Got {targets.shape} instead."
)
result_matrix: npt.NDArray[np.int32] = np.zeros(
(num_classes + 1, num_classes + 1), dtype=np.int32
)
# Filter predictions by confidence threshold
coords_dim = 8 if metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES else 4
class_id_idx = coords_dim
conf_idx = coords_dim + 1
confidence = predictions[:, conf_idx]
detection_batch_filtered = predictions[confidence >= conf_threshold]
if len(detection_batch_filtered) == 0:
true_classes = _validated_class_ids(View on GitHub (pinned to 7f254d9784)
Solutions
- Reshape the targets array to (N, expected_target_cols) before calling.
- Check for accidental transposition or extra dimensions in the targets array.
When it happens
Trigger: Thrown at src/supervision/metrics/detection.py:914 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/b5d9893dd3702cf2.
Report an issue: GitHub.