{"record":{"id":"f82c6480a220d3d6","repo":"tensorflow/models","slug":"total-sample-must-be-positive","errorCode":null,"errorMessage":"total_sample must be positive.","messagePattern":"total_sample must be positive\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/yt8m/eval_utils/eval_util.py","lineNumber":237,"sourceCode":"    return {\"hit_at_one\": mean_hit_at_one, \"perr\": mean_perr}\n\n  def get(self, return_per_class_ap=False):\n    \"\"\"Calculate the evaluation metrics for the whole epoch.\n\n    Args:\n      return_per_class_ap: a bool variable to determine whether return the\n        detailed class-wise ap for more detailed analysis. Default is `False`.\n\n    Raises:\n      ValueError: If no examples were accumulated.\n\n    Returns:\n      dictionary: a dictionary storing the evaluation metrics for the epoch. The\n        dictionary has the fields: avg_hit_at_one, avg_perr, and\n        aps (default nan).\n    \"\"\"\n    if self.num_examples <= 0:\n      raise ValueError(\"total_sample must be positive.\")\n    avg_hit_at_one = self.sum_hit_at_one / self.num_examples\n    avg_perr = self.sum_perr / self.num_examples\n\n    aps = self.map_calculator.peek_map_at_n()\n    mean_ap = sum(aps) / self.num_class\n    gap = self.global_ap_calculator.peek_ap_at_n()\n    lw_map = self.map_calculator.peek_log_weighted_map_at_n()\n\n    epoch_info_dict = {\n        \"avg_hit_at_one\": avg_hit_at_one,\n        \"avg_perr\": avg_perr,\n        \"map\": mean_ap,\n        \"gap\": gap,\n        \"lw_map\": lw_map\n    }\n\n    if return_per_class_ap:\n      epoch_info_dict[\"per_class_ap\"] = aps","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/yt8m/eval_utils/eval_util.py#L219-L255","documentation":"Aggregation guard in the metrics accumulator's get(): total_sample (the count of accumulated examples) is zero or negative, so per-example means cannot be computed. This means get() was called before any examples were accumulated — an eval loop that never fed predictions, an empty dataset shard or glob mismatch, or a second get() call after the first already flushed the counters.","triggerScenarios":"Thrown at official/projects/yt8m/eval_utils/eval_util.py:237 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure accumulate(...) runs with at least one batch before calling get()","Check the input pipeline actually yields examples (empty shard or file-glob mismatch)","Do not call get() twice without accumulating in between"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}