code: def run(argv, config_map, data_fn):
      """Create transcriptions."""
      tf.logging.set_verbosity(FLAGS.log)
  
      config = config_map[FLAGS.config]
      hparams = config.hparams
      hparams.parse(FLAGS.hparams)
      hparams.batch_size = 1
      hparams.truncated_length_secs = 0
  
      with tf.Graph().as_default():
          examples = tf.placeholder(tf.string, [None])
  
          dataset = data_fn(
              examples=examples,
              preprocess_examples=True,
              params=hparams,
              is_training=False,
              shuffle_examples=False,
              skip_n_initial_records=0,
          )
  
          estimator = train_util.create_estimator(
              config.model_fn,
              os.path.expanduser(FLAGS.model_dir),
              hparams,
          )
  
          iterator = tf.data.make_initializable_iterator(dataset)
          next_record = iterator.get_next()
  
          with tf.Session() as sess:
              sess.run(
                  [
                      tf.initializers.global_variables(),
                      tf.initializers.local_variables(),
                  ]
              )
  
              for filename in argv[1:]:
                  tf.logging.info(
                      "Starting transcription for %s...", filename
                  )
  
                  # The reason we bounce between two Dataset objects is so we can use
                  # the data processing functionality in data.py without having to
                  # construct all the Example protos in memory ahead of time or create
                  # a temporary tfrecord file.
                  tf.logging.info("Processing file...")
                  sess.run(
                      iterator.initializer,
                      {
                          examples: [
                              create_example(
                                  filename,
                                  hparams.sample_rate,
                                  FLAGS.load_audio_with_librosa,
                              )
                          ]
                      },
                  )
  
                  def transcription_data(params):
                      del params
                      return tf.data.Dataset.from_tensors(
                          sess.run(next_record)
                      )
  
                  input_fn = infer_util.labels_to_features_wrapper(
                      transcription_data
                  )
  
                  tf.logging.info("Running inference...")
                  checkpoint_path = None
                  if FLAGS.checkpoint_path:
                      checkpoint_path = os.path.expanduser(
                          FLAGS.checkpoint_path
                      )
                  prediction_list = list(
                      estimator.predict(
                          input_fn,
                          checkpoint_path=checkpoint_path,
                          yield_single_examples=False,
                      )
                  )
                  assert len(prediction_list) == 1
  
                  sequence_prediction = (
                      music_pb2.NoteSequence.FromString(
                          prediction_list[0]["sequence_predictions"][0]
                      )
                  )
  
                  midi_filename = (
                      filename + FLAGS.transcribed_file_suffix + ".midi"
                  )
                  midi_io.sequence_proto_to_midi_file(
                      sequence_prediction, midi_filename
                  )
  
                  tf.logging.info(
                      "Transcription written to %s.", midi_filename
                  )
  
file_path: magenta/magenta/models/onsets_frames_transcription/onsets_frames_transcription_transcribe.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  from magenta.models.onsets_frames_transcription import audio_label_data_utils
  from magenta.models.onsets_frames_transcription import configs
  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.protobuf import music_pb2
  import six
  import tensorflow.compat.v1
label_desc: Use image node_id 2 for calling a global function with example usage: run(argv, config_map, data_fn) and returns: tf