code: def build_stats(history, eval_output, callbacks):
      """Normalizes and returns dictionary of stats.
  
      Args:
        history: Results of the training step. Supports both categorical_accuracy
          and sparse_categorical_accuracy.
        eval_output: Output of the eval step. Assumes first value is eval_loss and
          second value is accuracy_top_1.
        callbacks: a list of callbacks which might include a time history callback
          used during keras.fit.
  
      Returns:
        Dictionary of normalized results.
      """
      stats = {}
      if eval_output:
          stats["accuracy_top_1"] = eval_output[1].item()
          stats["eval_loss"] = eval_output[0].item()
  
      if history and history.history:
          train_hist = history.history
          # Gets final loss from training.
          stats["loss"] = train_hist["loss"][-1].item()
          # Gets top_1 training accuracy.
          if "categorical_accuracy" in train_hist:
              stats[TRAIN_TOP_1] = train_hist["categorical_accuracy"][
                  -1
              ].item()
          elif "sparse_categorical_accuracy" in train_hist:
              stats[TRAIN_TOP_1] = train_hist[
                  "sparse_categorical_accuracy"
              ][-1].item()
  
      if not callbacks:
          return stats
  
      # Look for the time history callback which was used during keras.fit
      for callback in callbacks:
          if isinstance(callback, keras_utils.TimeHistory):
              timestamp_log = callback.timestamp_log
              stats["step_timestamp_log"] = timestamp_log
              stats["train_finish_time"] = callback.train_finish_time
              if len(timestamp_log) > 1:
                  stats["avg_exp_per_second"] = (
                      callback.batch_size
                      * callback.log_steps
                      * (len(callback.timestamp_log) - 1)
                      / (
                          timestamp_log[-1].timestamp
                          - timestamp_log[0].timestamp
                      )
                  )
      return stats
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  from absl import flags
  import numpy
  import tensorflow
  from tensorflow.python.keras.optimizer_v2 import gradient_descent
  from utils.flags import core
  from utils.misc import keras_utils
label_desc: Use image node_id 4 for calling a global function with example usage: build_stats(history, eval_output, callbacks) and returns: stats, stats