class_docstr: Implements a recurrent DQN designed to produce melody sequences.
class_docstr_tok: ["Implements","a","recurrent","DQN","designed","to","produce","melody","sequences","."]
docstr: Initializes internal RNN models, builds the graph, starts the session.
  
  Adds the graphs of the internal RNN models to this graph, adds the DQN ops
  to the graph, and starts a new Saver and session. By having a separate
  function for this rather than doing it in the constructor, it allows a model
  inheriting from this class to define its q_network differently.
  
  Args:
    restore_from_checkpoint: If True, the weights for the 'q_network',
      'target_q_network', and 'reward_rnn' will be loaded from a checkpoint.
      If false, these models will be initialized with random weights. Useful
      for checking what pure RL (with no influence from training data) sounds
      like.
docstr_tok: ["Initializes","internal","RNN","models",",","builds","the","graph",",","starts","the","session",".","Adds","the","graphs","of","the","internal","RNN","models","to","this","graph",",","adds","the","DQN","ops","to","the","graph",",","and","starts","a","new","Saver","and","session",".","By","having","a","separate","function","for","this","rather","than","doing","it","in","the","constructor",",","it","allows","a","model","inheriting","from","this","class","to","define","its","q_network","differently",".","Args",":","restore_from_checkpoint",":","If","True",",","the","weights","for","the","'q_network","'",",","'target_q_network","'",",","and","'reward_rnn","'","will","be","loaded","from","a","checkpoint",".","If","false",",","these","models","will","be","initialized","with","random","weights",".","Useful","for","checking","what","pure","RL","(","with","no","influence","from","training","data",")","sounds","like","."]
code: def initialize_internal_models_graph_session(
      self, restore_from_checkpoint=True
  ):
      """Initializes internal RNN models, builds the graph, starts the session.
  
      Adds the graphs of the internal RNN models to this graph, adds the DQN ops
      to the graph, and starts a new Saver and session. By having a separate
      function for this rather than doing it in the constructor, it allows a model
      inheriting from this class to define its q_network differently.
  
      Args:
        restore_from_checkpoint: If True, the weights for the 'q_network',
          'target_q_network', and 'reward_rnn' will be loaded from a checkpoint.
          If false, these models will be initialized with random weights. Useful
          for checking what pure RL (with no influence from training data) sounds
          like.
      """
      with self.graph.as_default():
          # Add internal networks to the graph.
          tf.logging.info("Initializing q network")
          self.q_network = note_rnn_loader.NoteRNNLoader(
              self.graph,
              "q_network",
              self.note_rnn_checkpoint_dir,
              midi_primer=self.midi_primer,
              training_file_list=self.training_file_list,
              checkpoint_file=self.note_rnn_checkpoint_file,
              hparams=self.note_rnn_hparams,
              note_rnn_type=self.note_rnn_type,
          )
  
          tf.logging.info("Initializing target q network")
          self.target_q_network = note_rnn_loader.NoteRNNLoader(
              self.graph,
              "target_q_network",
              self.note_rnn_checkpoint_dir,
              midi_primer=self.midi_primer,
              training_file_list=self.training_file_list,
              checkpoint_file=self.note_rnn_checkpoint_file,
              hparams=self.note_rnn_hparams,
              note_rnn_type=self.note_rnn_type,
          )
  
          tf.logging.info("Initializing reward network")
          self.reward_rnn = note_rnn_loader.NoteRNNLoader(
              self.graph,
              "reward_rnn",
              self.note_rnn_checkpoint_dir,
              midi_primer=self.midi_primer,
              training_file_list=self.training_file_list,
              checkpoint_file=self.note_rnn_checkpoint_file,
              hparams=self.note_rnn_hparams,
              note_rnn_type=self.note_rnn_type,
          )
  
          tf.logging.info("Q network cell: %s", self.q_network.cell)
  
          # Add rest of variables to graph.
          tf.logging.info("Adding RL graph variables")
          self.build_graph()
  
          # Prepare saver and session.
          self.saver = tf.train.Saver()
          self.session = tf.Session(graph=self.graph)
          self.session.run(tf.global_variables_initializer())
  
          # Initialize internal networks.
          if restore_from_checkpoint:
              self.q_network.initialize_and_restore(self.session)
              self.target_q_network.initialize_and_restore(self.session)
              self.reward_rnn.initialize_and_restore(self.session)
  
              # Double check that the model was initialized from checkpoint properly.
              reward_vars = self.reward_rnn.variables()
              q_vars = self.q_network.variables()
  
              reward1 = self.session.run(reward_vars[0])
              q1 = self.session.run(q_vars[0])
  
              if np.sum((q1 - reward1) ** 2) == 0.0:
                  # TODO(natashamjaques): Remove print statement once tf.logging outputs
                  # to Jupyter notebooks (once the following issue is resolved:
                  # https://github.com/tensorflow/tensorflow/issues/3047)
                  print(
                      "\nSuccessfully initialized internal nets from checkpoint!"
                  )
                  tf.logging.info(
                      "\nSuccessfully initialized internal nets from "
                      "checkpoint!"
                  )
              else:
                  tf.logging.fatal(
                      "Error! The model was not initialized from "
                      "checkpoint properly"
                  )
          else:
              self.q_network.initialize_new(self.session)
              self.target_q_network.initialize_new(self.session)
              self.reward_rnn.initialize_new(self.session)
  
      if self.priming_mode == "random_midi":
          tf.logging.info("Getting priming melodies")
          self.get_priming_melodies()
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import os
  import random
  import urllib
  from magenta.models.rl_tuner import note_rnn_loader
  from magenta.models.rl_tuner import rl_tuner_eval_metrics
  from magenta.models.rl_tuner import rl_tuner_ops
  import matplotlib.pyplot
  from note_seq import melodies_lib
  from note_seq import midi_io
  import numpy
  import scipy.special
  from six.moves import range
  from six.moves import reload_module
  from six.moves import urllib
  import tensorflow.compat.v1
label_desc: Use image node_id 2 for calling the RLTuner obj's underlying member method code with example usage: obj.initialize_internal_models_graph_session(restore_from_checkpoint) without return types