code: def run_eval(
      build_graph_fn, train_dir, eval_dir, num_batches, timeout_secs=300
  ):
      """Runs the training loop.
  
      Args:
        build_graph_fn: A function that builds the graph ops.
        train_dir: The path to the directory where checkpoints will be loaded
            from for evaluation.
        eval_dir: The path to the directory where the evaluation summary events
            will be written to.
        num_batches: The number of full batches to use for each evaluation step.
        timeout_secs: The number of seconds after which to stop waiting for a new
            checkpoint.
      Raises:
        ValueError: If `num_batches` is less than or equal to 0.
      """
      if num_batches <= 0:
          raise ValueError(
              "`num_batches` must be greater than 0. Check that the batch size is "
              "no larger than the number of records in the eval set."
          )
      with tf.Graph().as_default():
          build_graph_fn()
  
          global_step = tf.train.get_or_create_global_step()
          loss = tf.get_collection("loss")[0]
          perplexity = tf.get_collection("metrics/perplexity")[0]
          accuracy = tf.get_collection("metrics/accuracy")[0]
          eval_ops = tf.get_collection("eval_ops")
  
          logging_dict = {
              "Global Step": global_step,
              "Loss": loss,
              "Perplexity": perplexity,
              "Accuracy": accuracy,
          }
          hooks = [
              EvalLoggingTensorHook(
                  logging_dict, every_n_iter=num_batches
              ),
              tf_slim.evaluation.StopAfterNEvalsHook(num_batches),
              tf_slim.evaluation.SummaryAtEndHook(eval_dir),
          ]
  
          tf_slim.evaluation.evaluate_repeatedly(
              train_dir,
              eval_ops=eval_ops,
              hooks=hooks,
              eval_interval_secs=60,
              timeout=timeout_secs,
          )
  
file_path: magenta/magenta/models/shared/events_rnn_train.py
imports: import os
  import tempfile
  from magenta.models.shared import sequence_generator_bundle
  import tensorflow.compat.v1
  import tf_slim
label_desc: Use image node_id 2 for calling a global function with example usage: run_eval(build_graph_fn, train_dir, eval_dir, num_batches, timeout_secs) without return types