tensorflow/models · error · ValueError

num_class must be a positive integer.

Error message

num_class must be a positive integer.

What it means

Error "num_class must be a positive integer." thrown in tensorflow/models.

Source

Thrown at official/projects/yt8m/eval_utils/mean_average_precision_calculator.py:61

class MeanAveragePrecisionCalculator(object):
  """This class is to calculate mean average precision."""

  def __init__(self, num_class, filter_empty_classes=True, top_n=None):
    """Construct a calculator to calculate the (macro) average precision.

    Args:
      num_class: A positive Integer specifying the number of classes.
      filter_empty_classes: whether to filter classes without any positives.
      top_n: A positive Integer specifying the average precision at n, or None
        to use all provided data points.

    Raises:
      ValueError: An error occurred when num_class is not a positive integer;
      or the top_n_array is not a list of positive integers.
    """
    if not isinstance(num_class, int) or num_class < 1:
      raise ValueError("num_class must be a positive integer.")

    self._ap_calculators = []  # member of AveragePrecisionCalculator
    self._num_class = num_class  # total number of classes
    self._filter_empty_classes = filter_empty_classes
    for _ in range(num_class):
      self._ap_calculators.append(
          average_precision_calculator.AveragePrecisionCalculator(top_n=top_n))

  def accumulate(self, predictions, actuals, num_positives=None):
    """Accumulate the predictions and their ground truth labels.

    Args:
      predictions: A list of lists storing the prediction scores. The outer
        dimension corresponds to classes.
      actuals: A list of lists storing the ground truth labels. The dimensions
        should correspond to the predictions input. Any value larger than 0 will
        be treated as positives, otherwise as negatives.
      num_positives: If provided, it is a list of numbers representing the

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/projects/yt8m/eval_utils/mean_average_precision_calculator.py:61 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/347782122b9d81b7. Report an issue: GitHub.