class_docstr: Reporter class.
  
  Examples:
  
      >>> reporter = Reporter()
      >>> with reporter.observe('train') as sub_reporter:
      ...     for batch in iterator:
      ...         stats = dict(loss=0.2)
      ...         sub_reporter.register(stats)
class_docstr_tok: ["Reporter","class",".","Examples",":",">",">",">","reporter","=","Reporter","(",")",">",">",">","with","reporter.observe","(","'train","'",")","as","sub_reporter",":","...","for","batch","in","iterator",":","...","stats","=","dict","(","loss=0.2",")","...","sub_reporter.register","(","stats",")"]
code: def start_epoch(self, key: str, epoch: int = None) -> SubReporter:
      if epoch is not None:
          if epoch < 0:
              raise ValueError(f"epoch must be 0 or more: {epoch}")
          self.epoch = epoch
  
      if (
          self.epoch - 1 not in self.stats
          or key not in self.stats[self.epoch - 1]
      ):
          # If the previous epoch doesn't exist for some reason,
          # maybe due to bug, this case also indicates 0-count.
          if self.epoch - 1 != 0:
              warnings.warn(
                  f"The stats of the previous epoch={self.epoch - 1}"
                  f"doesn't exist."
              )
          total_count = 0
      else:
          total_count = self.stats[self.epoch - 1][key]["total_count"]
  
      sub_reporter = SubReporter(key, self.epoch, total_count)
      # Clear the stats for the next epoch if it exists
      self.stats.pop(epoch, None)
      return sub_reporter
  
imports: import dataclasses
  import datetime
  import logging
  import time
  import warnings
  from collections import defaultdict
  from contextlib import contextmanager
  from pathlib import Path
  from typing import ContextManager, Dict, List, Optional, Sequence, Tuple, Union
  import humanfriendly
  import numpy
  import torch
  from packaging.version import parse
  from typeguard import check_argument_types, check_return_type
label_desc: Use image node_id 5 for calling the Reporter obj's underlying member method code with example usage: obj.start_epoch(key, epoch) and returns: sub_reporter