code: def run(config_map, data_fn, additional_trial_info):
      """Run training or evaluation."""
      tf.logging.set_verbosity(FLAGS.log)
  
      config = config_map[FLAGS.config]
      model_dir = os.path.expanduser(FLAGS.model_dir)
  
      hparams = config.hparams
  
      # Command line flags override any of the preceding hyperparameter values.
      hparams.parse(FLAGS.hparams)
  
      if FLAGS.mode == "train":
          train_util.train(
              model_fn=config.model_fn,
              data_fn=data_fn,
              additional_trial_info=additional_trial_info,
              master=FLAGS.master,
              tpu_cluster=FLAGS.tpu_cluster,
              model_dir=model_dir,
              use_tpu=FLAGS.use_tpu,
              preprocess_examples=FLAGS.preprocess_examples,
              hparams=hparams,
              keep_checkpoint_max=FLAGS.keep_checkpoint_max,
              num_steps=FLAGS.num_steps,
              warm_start_from=FLAGS.warm_start_from,
          )
      elif FLAGS.mode == "eval":
          train_util.evaluate(
              model_fn=config.model_fn,
              data_fn=data_fn,
              additional_trial_info=additional_trial_info,
              master=FLAGS.master,
              model_dir=model_dir,
              name=FLAGS.eval_name,
              preprocess_examples=FLAGS.preprocess_examples,
              hparams=hparams,
              num_steps=FLAGS.eval_num_steps,
          )
      else:
          raise ValueError("Unknown/unsupported mode: %s" % FLAGS.mode)
  
file_path: magenta/magenta/models/onsets_frames_transcription/onsets_frames_transcription_train.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import functools
  import os
  from magenta.models.onsets_frames_transcription import configs
  from magenta.models.onsets_frames_transcription import data
  from magenta.models.onsets_frames_transcription import train_util
  import tensorflow.compat.v1
label_desc: Use image node_id 1 for calling a global function with example usage: run(config_map, data_fn, additional_trial_info) without return types