code: def run(config_map, data_fn):
      """Run the infer script."""
      output_dir = os.path.expanduser(FLAGS.output_dir)
  
      config = config_map[FLAGS.config]
      hparams = config.hparams
      hparams.parse(FLAGS.hparams)
  
      # Batch size should always be 1 for inference.
      hparams.batch_size = 1
  
      tf.logging.info(hparams)
  
      tf.gfile.MakeDirs(output_dir)
  
      summary_writer = tf.summary.FileWriter(logdir=output_dir)
  
      with tf.Session():
          run_config = "\n\n".join(
              [
                  "model_dir: " + FLAGS.model_dir,
                  "checkpoint_path: " + str(FLAGS.checkpoint_path),
                  "examples_path: " + FLAGS.examples_path,
                  str(hparams),
              ]
          )
          run_config_summary = tf.summary.text(
              "run_config",
              tf.constant(run_config, name="run_config"),
              collections=[],
          )
          summary_writer.add_summary(run_config_summary.eval())
  
      model_inference(
          model_fn=config.model_fn,
          model_dir=FLAGS.model_dir,
          checkpoint_path=FLAGS.checkpoint_path,
          data_fn=data_fn,
          hparams=hparams,
          examples_path=FLAGS.examples_path,
          output_dir=output_dir,
          summary_writer=summary_writer,
          preprocess_examples=FLAGS.preprocess_examples,
          master=FLAGS.master,
          shuffle_examples=FLAGS.shuffle_examples,
      )
  
file_path: magenta/magenta/models/onsets_frames_transcription/infer.py
imports: import collections
  import functools
  import os
  import time
  import imageio
  from magenta.models.onsets_frames_transcription import constants
  from magenta.models.onsets_frames_transcription import data
  from magenta.models.onsets_frames_transcription import infer_util
  from magenta.models.onsets_frames_transcription import train_util
  from note_seq import midi_io
  from note_seq import sequences_lib
  from note_seq.protobuf import music_pb2
  import numpy
  import six
  import tensorflow.compat.v1
label_desc: Use image node_id 2 for calling a global function with example usage: run(config_map, data_fn) without return types