def read_from_tf_event(input_event_file_pattern: str,
                       metric2id_dict: Dict[str, int],
                       biggest: bool = True,
                       missing_value: float = 0.0) -> Dict[int, np.ndarray]:
  """Reads metrics from the TF event files in input_event_file_pattern.

  Args:
    input_event_file_pattern: Pattern of the TensorFlow event files for a single
      experiment.
    metric2id_dict: Dict of the metric names to their index
    biggest: Whether to read only from the biggest event file. In some cases,
      biggest file is also the latest. If False, read from all event files.
    missing_value: Default values for missing fields.

  Returns:
    2D numpy array containing the step size and value extracted
      from the tag.
  """
  files = gfile.glob(input_event_file_pattern)
  ret_dict = {}

  # Sorts the file by file size. Bigger files are more recent.
  # The assumption may not hold in many jobs.
  # It usually holds for the eval_only or universal_evaluator jobs (hyper-tune).
  sizes = [gfile.stat(t).length for t in files]
  file_tuple = list(zip(files, sizes))
  file_tuple.sort(key=lambda tup: -tup[1])

  nan_array = np.empty([len(metric2id_dict)])
  nan_array[:] = np.nan

  if not file_tuple:
    return {0: nan_array}

  if biggest:
    file_tuple = [file_tuple[0]]

  for event_file in file_tuple:
    try:
      for summary in tf.compat.v1.train.summary_iterator(event_file[0]):
        for v in summary.summary.value:
          if v.tag in metric2id_dict:
            cur_ret_values = ret_dict.get(
                summary.step,
                np.ones([len(metric2id_dict)]) * missing_value)
            cur_ret_values[metric2id_dict[v.tag]] = tf.make_ndarray(v.tensor)
            ret_dict[summary.step] = cur_ret_values
    except tf.errors.NotFoundError:
      continue
  if not ret_dict:
    ret_dict = {0: nan_array}
  return ret_dict
Reads metrics from the TF event files in input_event_file_pattern.

  Args:
    input_event_file_pattern: Pattern of the TensorFlow event files for a single
      experiment.
    metric2id_dict: Dict of the metric names to their index
    biggest: Whether to read only from the biggest event file. In some cases,
      biggest file is also the latest. If False, read from all event files.
    missing_value: Default values for missing fields.

  Returns:
    2D numpy array containing the step size and value extracted
      from the tag.
  
videogvt/interfaces/colab_utils.py