roboflow/supervision · error · ValueError
Precision metric requires `class_id` and `confidence` on pre
Error message
Precision metric requires `class_id` and `confidence` on predictions.
What it means
Error "Precision metric requires `class_id` and `confidence` on predictions." thrown in roboflow/supervision.
Source
Thrown at src/supervision/metrics/precision.py:188
prediction_size_mask = np.ones(len(predictions), dtype=bool)
target_size_mask = np.ones(len(targets), dtype=bool)
if size_category != ObjectSizeCategory.ANY:
if len(predictions) > 0:
prediction_size_mask = (
get_detection_size_category(predictions, self._metric_target)
== size_category.value
)
if len(targets) > 0:
target_size_mask = (
get_detection_size_category(targets, self._metric_target)
== size_category.value
)
if len(targets) == 0 and len(predictions) > 0:
# Only predictions are present (e.g. a background image); every
# prediction is a false positive.
if predictions.class_id is None or predictions.confidence is None:
raise ValueError(
"Precision metric requires `class_id` and `confidence` "
"on predictions."
)
prediction_class_ids = np.asarray(predictions.class_id, dtype=np.int32)[
prediction_size_mask
]
prediction_confidence = np.asarray(
predictions.confidence, dtype=np.float32
)[prediction_size_mask]
if len(prediction_class_ids) == 0:
continue
stats.append(
(
np.zeros(
(len(prediction_class_ids), iou_thresholds.size),
dtype=np.bool_,
),
np.zeros(View on GitHub (pinned to 7f254d9784)
Solutions
- Ensure prediction Detections have both class_id and confidence set before computing Precision.
- Populate class_id and confidence from your model outputs when constructing Detections.
When it happens
Trigger: Thrown at src/supervision/metrics/precision.py:188 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/4bbc68f4084d62a9.
Report an issue: GitHub.