tensorflow/models · error · ValueError

total_sample must be positive.

Error message

total_sample must be positive.

What it means

Error "total_sample must be positive." thrown in tensorflow/models.

Source

Thrown at official/projects/yt8m/eval_utils/eval_util.py:237

    return {"hit_at_one": mean_hit_at_one, "perr": mean_perr}

  def get(self, return_per_class_ap=False):
    """Calculate the evaluation metrics for the whole epoch.

    Args:
      return_per_class_ap: a bool variable to determine whether return the
        detailed class-wise ap for more detailed analysis. Default is `False`.

    Raises:
      ValueError: If no examples were accumulated.

    Returns:
      dictionary: a dictionary storing the evaluation metrics for the epoch. The
        dictionary has the fields: avg_hit_at_one, avg_perr, and
        aps (default nan).
    """
    if self.num_examples <= 0:
      raise ValueError("total_sample must be positive.")
    avg_hit_at_one = self.sum_hit_at_one / self.num_examples
    avg_perr = self.sum_perr / self.num_examples

    aps = self.map_calculator.peek_map_at_n()
    mean_ap = sum(aps) / self.num_class
    gap = self.global_ap_calculator.peek_ap_at_n()
    lw_map = self.map_calculator.peek_log_weighted_map_at_n()

    epoch_info_dict = {
        "avg_hit_at_one": avg_hit_at_one,
        "avg_perr": avg_perr,
        "map": mean_ap,
        "gap": gap,
        "lw_map": lw_map
    }

    if return_per_class_ap:
      epoch_info_dict["per_class_ap"] = aps

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/projects/yt8m/eval_utils/eval_util.py:237 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/f82c6480a220d3d6. Report an issue: GitHub.