예제 #1
0
 def testBuildGraphWithAttention(self):
     self.hparams.attn_length = 10
     g = melody_rnn_graph.build_graph('train',
                                      self.hparams,
                                      self.encoder_decoder,
                                      sequence_example_file='test')
     self.assertTrue(isinstance(g, tf.Graph))
def build_graph(mode,
                hparams_string,
                encoder_decoder,
                sequence_example_file=None):
    """Builds the TensorFlow graph.

  Args:
    mode: 'train', 'eval', or 'generate'. Only mode related ops are added to
        the graph.
    hparams_string: A string literal of a Python dictionary, where keys are
        hyperparameter names and values replace default values. For example:
        '{"batch_size":64,"rnn_layer_sizes":[128,128]}'
    encoder_decoder: The MelodyEncoderDecoder being used by the model.
    sequence_example_file: A string path to a TFRecord file containing
        tf.train.SequenceExamples. Only needed for training and evaluation.

  Returns:
    A tf.Graph instance which contains the TF ops.

  Raises:
    ValueError: If mode is not 'train', 'eval', or 'generate', or if
        sequence_example_file does not match a file when mode is 'train' or
        'eval'.
  """
    hparams = default_hparams()
    hparams = hparams.parse(hparams_string)
    return melody_rnn_graph.build_graph(mode, hparams, encoder_decoder,
                                        sequence_example_file)
예제 #3
0
 def testBuildGenerateGraph(self):
     self.hparams.temperature = 1.0
     g = melody_rnn_graph.build_graph('generate',
                                      self.hparams,
                                      self.encoder_decoder,
                                      sequence_example_file='test')
     self.assertTrue(isinstance(g, tf.Graph))
예제 #4
0
def build_graph(mode, hparams_string, encoder_decoder,
                sequence_example_file=None):
  """Builds the TensorFlow graph.

  Args:
    mode: 'train', 'eval', or 'generate'. Only mode related ops are added to
        the graph.
    hparams_string: A string literal of a Python dictionary, where keys are
        hyperparameter names and values replace default values. For example:
        '{"batch_size":64,"rnn_layer_sizes":[128,128]}'
    encoder_decoder: The MelodyEncoderDecoder being used by the model.
    sequence_example_file: A string path to a TFRecord file containing
        tf.train.SequenceExamples. Only needed for training and evaluation.

  Returns:
    A tf.Graph instance which contains the TF ops.

  Raises:
    ValueError: If mode is not 'train', 'eval', or 'generate', or if
        sequence_example_file does not match a file when mode is 'train' or
        'eval'.
  """
  hparams = default_hparams()
  hparams = hparams.parse(hparams_string)
  return melody_rnn_graph.build_graph(mode, hparams, encoder_decoder,
                                      sequence_example_file)
예제 #5
0
 def testBuildEvalGraph(self):
     g = melody_rnn_graph.build_graph('eval',
                                      self.hparams,
                                      self.encoder_decoder,
                                      sequence_example_file='test')
     self.assertTrue(isinstance(g, tf.Graph))
예제 #6
0
 def testBuildGraphWithAttention(self):
   self.hparams.attn_length = 10
   g = melody_rnn_graph.build_graph(
       'train', self.hparams, self.encoder_decoder,
       sequence_example_file='test')
   self.assertTrue(isinstance(g, tf.Graph))
예제 #7
0
 def testBuildGenerateGraph(self):
   self.hparams.temperature = 1.0
   g = melody_rnn_graph.build_graph(
       'generate', self.hparams, self.encoder_decoder,
       sequence_example_file='test')
   self.assertTrue(isinstance(g, tf.Graph))
예제 #8
0
 def testBuildEvalGraph(self):
   g = melody_rnn_graph.build_graph(
       'eval', self.hparams, self.encoder_decoder,
       sequence_example_file='test')
   self.assertTrue(isinstance(g, tf.Graph))