code: def main(_):
      if FLAGS.note_rnn_type == "basic_rnn":
          hparams = rl_tuner_ops.basic_rnn_hparams()
      else:
          hparams = rl_tuner_ops.default_hparams()
  
      dqn_hparams = contrib_training.HParams(
          random_action_probability=0.1,
          store_every_nth=1,
          train_every_nth=5,
          minibatch_size=32,
          discount_rate=0.5,
          max_experience=100000,
          target_network_update_rate=0.01,
      )
  
      output_dir = os.path.join(FLAGS.output_dir, FLAGS.algorithm)
      output_ckpt = FLAGS.algorithm + ".ckpt"
      backup_checkpoint_file = os.path.join(
          FLAGS.note_rnn_checkpoint_dir, FLAGS.note_rnn_checkpoint_name
      )
  
      rlt = rl_tuner.RLTuner(
          output_dir,
          midi_primer=FLAGS.midi_primer,
          dqn_hparams=dqn_hparams,
          reward_scaler=FLAGS.reward_scaler,
          save_name=output_ckpt,
          output_every_nth=FLAGS.output_every_nth,
          note_rnn_checkpoint_dir=FLAGS.note_rnn_checkpoint_dir,
          note_rnn_checkpoint_file=backup_checkpoint_file,
          note_rnn_type=FLAGS.note_rnn_type,
          note_rnn_hparams=hparams,
          num_notes_in_melody=FLAGS.num_notes_in_melody,
          exploration_mode=FLAGS.exploration_mode,
          algorithm=FLAGS.algorithm,
      )
  
      tf.logging.info(
          "Saving images and melodies to: %s", rlt.output_dir
      )
  
      tf.logging.info("Training...")
      rlt.train(
          num_steps=FLAGS.training_steps,
          exploration_period=FLAGS.exploration_steps,
      )
  
      tf.logging.info(
          "Finished training. Saving output figures and composition."
      )
      rlt.plot_rewards(image_name="Rewards-" + FLAGS.algorithm + ".eps")
  
      rlt.generate_music_sequence(
          visualize_probs=True,
          title=FLAGS.algorithm,
          prob_image_name=FLAGS.algorithm + ".png",
      )
  
      rlt.save_model_and_figs(FLAGS.algorithm)
  
      tf.logging.info(
          "Calculating music theory metric stats for 1000 "
          "compositions."
      )
      rlt.evaluate_music_theory_metrics(num_compositions=1000)
  
file_path: magenta/magenta/models/rl_tuner/rl_tuner_train.py
imports: import os
  from magenta.contrib import training
  from magenta.models.rl_tuner import rl_tuner
  from magenta.models.rl_tuner import rl_tuner_ops
  import matplotlib
  import matplotlib.pyplot
  import tensorflow.compat.v1
label_desc: Use image node_id 1 for calling a global function with example usage: main(_) without return types