tensorflow/models · error · ValueError
the shape of predictions and actuals does not match.
Error message
the shape of predictions and actuals does not match.
What it means
Shape agreement check in AveragePrecisionCalculator.accumulate: predictions and actuals must be equal-length sequences (they are zipped pairwise to score each item); mismatched lengths mean one list has scores without ground truth or vice versa, making AP meaningless. Commonly fires when results from partial runs are concatenated independently, or when num_positives was supplied with trimmed arrays built separately.
Solutions
- Ensure predictions and actuals are produced from the same batches and appended together
- Trim or extend both arrays consistently when subsampling
- Add a length assert in the caller before accumulating to catch divergence early
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at official/projects/yt8m/eval_utils/average_precision_calculator.py:114 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/607e6dab7a4fb58c.
Report an issue: GitHub.
Appendix: source
Thrown at official/projects/yt8m/eval_utils/average_precision_calculator.py:114
After the function call, we may call peek_ap_at_n to actually calculate
the average precision.
Note predictions and actuals must have the same shape.
Args:
predictions: a list storing the prediction scores.
actuals: a list storing the ground truth labels. Any value larger than 0
will be treated as positives, otherwise as negatives. num_positives = If
the 'predictions' and 'actuals' inputs aren't complete, then it's
possible some true positives were missed in them. In that case, you can
provide 'num_positives' in order to accurately track recall.
num_positives: number of positive examples.
Raises:
ValueError: An error occurred when the format of the input is not the
numpy 1-D array or the shape of predictions and actuals does not match.
"""
if len(predictions) != len(actuals):
raise ValueError("the shape of predictions and actuals does not match.")
if num_positives is not None:
if not isinstance(num_positives, numbers.Number) or num_positives < 0: # pyrefly: ignore[unsupported-operation]
raise ValueError(
"'num_positives' was provided but it was a negative number.")
if num_positives is not None:
self._total_positives += num_positives
else:
self._total_positives += numpy.size(
numpy.where(numpy.array(actuals) > 1e-5))
topk = self._top_n
heap = self._heap
for i in range(numpy.size(predictions)):
if topk is None or len(heap) < topk:
heapq.heappush(heap, (predictions[i], actuals[i]))
else:View on GitHub (pinned to e006f5f0d5)