def testMelodyRNNPipeline(self):
        FLAGS.eval_ratio = 0.0
        note_sequence = testing_lib.parse_test_proto(
            music_pb2.NoteSequence, """
        time_signatures: {
          numerator: 4
          denominator: 4}
        tempos: {
          qpm: 120}""")
        testing_lib.add_track(note_sequence, 0, [(12, 100, 0.00, 2.0),
                                                 (11, 55, 2.1, 5.0),
                                                 (40, 45, 5.1, 8.0),
                                                 (55, 120, 8.1, 11.0),
                                                 (53, 99, 11.1, 14.1)])

        quantizer = pipelines_common.Quantizer(steps_per_quarter=4)
        melody_extractor = pipelines_common.MonophonicMelodyExtractor(
            min_bars=7,
            min_unique_pitches=5,
            gap_bars=1.0,
            ignore_polyphonic_notes=False)
        one_hot_encoder = melodies_lib.OneHotEncoderDecoder(0, 127, 0)
        quantized = quantizer.transform(note_sequence)[0]
        print quantized.tracks
        melody = melody_extractor.transform(quantized)[0]
        one_hot = one_hot_encoder.encode(melody)
        print one_hot
        expected_result = {'training_melodies': [one_hot], 'eval_melodies': []}

        pipeline_inst = melody_rnn_create_dataset.get_pipeline(one_hot_encoder)
        result = pipeline_inst.transform(note_sequence)
        self.assertEqual(expected_result, result)
  def testMelodyRNNPipeline(self):
    note_sequence = testing_lib.parse_test_proto(
        music_pb2.NoteSequence,
        """
        time_signatures: {
          numerator: 4
          denominator: 4}
        tempos: {
          bpm: 120}""")
    testing_lib.add_track(
        note_sequence, 0,
        [(12, 100, 0.01, 10.0), (11, 55, 0.22, 0.50), (40, 45, 2.50, 3.50),
         (55, 120, 4.0, 4.01), (52, 99, 4.75, 5.0)])

    quantizer = pipelines_common.Quantizer(steps_per_beat=4)
    melody_extractor = pipelines_common.MonophonicMelodyExtractor(
        min_bars=7, min_unique_pitches=5,
        gap_bars=1.0)
    one_hot_encoder = melody_rnn_create_dataset.OneHotEncoder()
    quantized = quantizer.transform(note_sequence)[0]
    melody = melody_extractor.transform(quantized)[0]
    one_hot = one_hot_encoder.transform(melody)[0]
    expected_result = {'melody_rnn_train': [one_hot], 'melody_rnn_eval': []}

    pipeline_inst = melody_rnn_create_dataset.MelodyRNNPipeline(eval_ratio=0)
    result = pipeline_inst.transform(note_sequence)
    self.assertEqual(expected_result, result)
Пример #3
0
  def testMonophonicMelodyExtractor(self):
    quantized_sequence = sequences_lib.QuantizedSequence()
    quantized_sequence.steps_per_beat = 1
    testing_lib.add_quantized_track(
        quantized_sequence, 0,
        [(12, 100, 2, 4), (11, 1, 6, 7)])
    testing_lib.add_quantized_track(
        quantized_sequence, 1,
        [(12, 127, 2, 4), (14, 50, 6, 8)])
    expected_events = [
        [NO_EVENT, NO_EVENT, 12, NO_EVENT, NOTE_OFF, NO_EVENT, 11, NOTE_OFF],
        [NO_EVENT, NO_EVENT, 12, NO_EVENT, NOTE_OFF, NO_EVENT, 14, NO_EVENT,
         NOTE_OFF]]
    expected_melodies = []
    for events_list in expected_events:
      melody = melodies_lib.MonophonicMelody()
      melody.from_event_list(events_list)
      melody.steps_per_bar = 4
      expected_melodies.append(melody)
    expected_melodies[0].end_step = 8
    expected_melodies[1].end_step = 12

    unit = pipelines_common.MonophonicMelodyExtractor(
        min_bars=1, min_unique_pitches=1, gap_bars=1)
    self._unit_transform_test(unit, quantized_sequence, expected_melodies)
Пример #4
0
def get_pipeline(melody_encoder_decoder):
    """Returns the Pipeline instance which creates the RNN dataset.

  Args:
    melody_encoder_decoder: A melodies_lib.MelodyEncoderDecoder object.

  Returns:
    A pipeline.Pipeline instance.
  """
    quantizer = pipelines_common.Quantizer(steps_per_beat=4)
    melody_extractor = pipelines_common.MonophonicMelodyExtractor(
        min_bars=7,
        min_unique_pitches=5,
        gap_bars=1.0,
        ignore_polyphonic_notes=False)
    encoder_pipeline = EncoderPipeline(melody_encoder_decoder)
    partitioner = pipelines_common.RandomPartition(
        tf.train.SequenceExample, ['eval_melodies', 'training_melodies'],
        [FLAGS.eval_ratio])

    dag = {
        quantizer: dag_pipeline.Input(music_pb2.NoteSequence),
        melody_extractor: quantizer,
        encoder_pipeline: melody_extractor,
        partitioner: encoder_pipeline,
        dag_pipeline.Output(): partitioner
    }
    return dag_pipeline.DAGPipeline(dag)
Пример #5
0
 def __init__(self, melody_encoder_decoder, eval_ratio):
     self.training_set_name = 'training_melodies'
     self.eval_set_name = 'eval_melodies'
     super(MelodyRNNPipeline,
           self).__init__(input_type=music_pb2.NoteSequence,
                          output_type={
                              self.training_set_name:
                              tf.train.SequenceExample,
                              self.eval_set_name: tf.train.SequenceExample
                          })
     self.eval_ratio = eval_ratio
     self.quantizer = pipelines_common.Quantizer(steps_per_beat=4)
     self.melody_extractor = pipelines_common.MonophonicMelodyExtractor(
         min_bars=7,
         min_unique_pitches=5,
         gap_bars=1.0,
         ignore_polyphonic_notes=False)
     self.encoder_unit = EncoderPipeline(melody_encoder_decoder)
     self.stats_dict = {}