def testTranspositionPipelineIgnoreOutOfRangeNotes(self): note_sequence = common_testing_lib.parse_test_proto( music_pb2.NoteSequence, """ time_signatures: { numerator: 4 denominator: 4} tempos: { qpm: 60}""") tp = note_sequence_pipelines.TranspositionPipeline( range(-1, 2), ignore_out_of_range_notes=True, min_pitch=0, max_pitch=12) testing_lib.add_track_to_sequence( note_sequence, 0, [(10, 100, 1.0, 2.0), (12, 100, 2.0, 4.0), (13, 100, 4.0, 5.0)]) transposed = tp.transform(note_sequence) self.assertEqual(3, len(transposed)) self.assertEqual(3, len(transposed[0].notes)) self.assertEqual(2, len(transposed[1].notes)) self.assertEqual(1, len(transposed[2].notes)) self.assertEqual(9, transposed[0].notes[0].pitch) self.assertEqual(10, transposed[1].notes[0].pitch) self.assertEqual(11, transposed[2].notes[0].pitch) self.assertEqual(11, transposed[0].notes[1].pitch) self.assertEqual(12, transposed[1].notes[1].pitch) self.assertEqual(12, transposed[0].notes[2].pitch)
def testTranspositionPipeline(self): note_sequence = common_testing_lib.parse_test_proto( music_pb2.NoteSequence, """ time_signatures: { numerator: 4 denominator: 4} tempos: { qpm: 60}""") tp = note_sequence_pipelines.TranspositionPipeline(range(0, 2)) testing_lib.add_track_to_sequence( note_sequence, 0, [(12, 100, 1.0, 4.0)]) testing_lib.add_track_to_sequence( note_sequence, 1, [(36, 100, 2.0, 2.01)], is_drum=True) transposed = tp.transform(note_sequence) self.assertEqual(2, len(transposed)) self.assertEqual(2, len(transposed[0].notes)) self.assertEqual(2, len(transposed[1].notes)) self.assertEqual(12, transposed[0].notes[0].pitch) self.assertEqual(13, transposed[1].notes[0].pitch) self.assertEqual(36, transposed[0].notes[1].pitch) self.assertEqual(36, transposed[1].notes[1].pitch)
def get_pipeline(config, min_events, max_events, eval_ratio): """Returns the Pipeline instance which creates the RNN dataset. Args: config: A PerformanceRnnConfig. min_events: Minimum number of events for an extracted sequence. max_events: Maximum number of events for an extracted sequence. eval_ratio: Fraction of input to set aside for evaluation set. Returns: A pipeline.Pipeline instance. """ # Stretch by -5%, -2.5%, 0%, 2.5%, and 5%. stretch_factors = [0.95, 0.975, 1.0, 1.025, 1.05] # Transpose no more than a major third. transposition_range = range(-3, 4) partitioner = pipelines_common.RandomPartition( music_pb2.NoteSequence, ['eval_performances', 'training_performances'], [eval_ratio]) dag = {partitioner: dag_pipeline.DagInput(music_pb2.NoteSequence)} for mode in ['eval', 'training']: sustain_pipeline = note_sequence_pipelines.SustainPipeline( name='SustainPipeline_' + mode) stretch_pipeline = note_sequence_pipelines.StretchPipeline( stretch_factors, name='StretchPipeline_' + mode) splitter = note_sequence_pipelines.Splitter(hop_size_seconds=30.0, name='Splitter_' + mode) quantizer = note_sequence_pipelines.Quantizer( steps_per_second=config.steps_per_second, name='Quantizer_' + mode) transposition_pipeline = note_sequence_pipelines.TranspositionPipeline( transposition_range, name='TranspositionPipeline_' + mode) perf_extractor = PerformanceExtractor( min_events=min_events, max_events=max_events, num_velocity_bins=config.num_velocity_bins, name='PerformanceExtractor_' + mode) encoder_pipeline = EncoderPipeline(config, name='EncoderPipeline_' + mode) dag[sustain_pipeline] = partitioner[mode + '_performances'] if mode == 'eval': # No stretching in eval. dag[splitter] = sustain_pipeline else: dag[stretch_pipeline] = sustain_pipeline dag[splitter] = stretch_pipeline dag[quantizer] = splitter if mode == 'eval': # No transposition in eval. dag[perf_extractor] = quantizer else: dag[transposition_pipeline] = quantizer dag[perf_extractor] = transposition_pipeline dag[encoder_pipeline] = perf_extractor dag[dag_pipeline.DagOutput(mode + '_performances')] = encoder_pipeline return dag_pipeline.DAGPipeline(dag)
def get_pipeline(config, eval_ratio=0.0): partitioner = pipelines_common.RandomPartition( music_pb2.NoteSequence, ['eval_melodies', 'training_melodies'], [eval_ratio]) dag = {partitioner: dag_pipeline.DagInput(music_pb2.NoteSequence)} for mode in ['eval', 'training']: time_change_splitter = note_sequence_pipelines.TimeChangeSplitter( name='TimeChangeSplitter_' + mode) repeat_sequence = RepeatSequence(min_duration=16, name='RepeatSequence_' + mode) transposition_pipeline = note_sequence_pipelines.TranspositionPipeline( (0, ), name='TranspositionPipeline_' + mode) quantizer = note_sequence_pipelines.Quantizer( steps_per_quarter=config.steps_per_quarter, name='Quantizer_' + mode) melody_extractor = melody_pipelines.MelodyExtractor( min_bars=7, max_steps=512, min_unique_pitches=5, gap_bars=1.0, ignore_polyphonic_notes=True, name='MelodyExtractor_' + mode) encoder_pipeline = EncoderPipeline(config, name='EncoderPipeline_' + mode) dag[time_change_splitter] = partitioner[mode + '_melodies'] dag[repeat_sequence] = time_change_splitter dag[quantizer] = repeat_sequence dag[transposition_pipeline] = quantizer dag[melody_extractor] = transposition_pipeline dag[encoder_pipeline] = melody_extractor dag[dag_pipeline.DagOutput(mode + '_melodies')] = encoder_pipeline return dag_pipeline.DAGPipeline(dag)
def get_pipeline(config, min_steps, max_steps, eval_ratio): """Returns the Pipeline instance which creates the RNN dataset. Args: config: An EventSequenceRnnConfig. min_steps: Minimum number of steps for an extracted sequence. max_steps: Maximum number of steps for an extracted sequence. eval_ratio: Fraction of input to set aside for evaluation set. Returns: A pipeline.Pipeline instance. """ # Transpose up to a major third in either direction. # Because our current dataset is Bach chorales, transposing more than a major # third in either direction probably doesn't makes sense (e.g., because it is # likely to exceed normal singing range). transposition_range = range(-4, 5) partitioner = pipelines_common.RandomPartition( music_pb2.NoteSequence, ['eval_poly_tracks', 'training_poly_tracks'], [eval_ratio]) dag = {partitioner: dag_pipeline.DagInput(music_pb2.NoteSequence)} for mode in ['eval', 'training']: time_change_splitter = note_sequence_pipelines.TimeChangeSplitter( name='TimeChangeSplitter_' + mode) quantizer = note_sequence_pipelines.Quantizer( steps_per_quarter=config.steps_per_quarter, name='Quantizer_' + mode) transposition_pipeline = note_sequence_pipelines.TranspositionPipeline( transposition_range, name='TranspositionPipeline_' + mode) poly_extractor = PolyphonicSequenceExtractor(min_steps=min_steps, max_steps=max_steps, name='PolyExtractor_' + mode) encoder_pipeline = event_sequence_pipeline.EncoderPipeline( polyphony_lib.PolyphonicSequence, config.encoder_decoder, name='EncoderPipeline_' + mode) dag[time_change_splitter] = partitioner[mode + '_poly_tracks'] dag[quantizer] = time_change_splitter dag[transposition_pipeline] = quantizer dag[poly_extractor] = transposition_pipeline dag[encoder_pipeline] = poly_extractor dag[dag_pipeline.DagOutput(mode + '_poly_tracks')] = encoder_pipeline return dag_pipeline.DAGPipeline(dag)
def get_pipeline(config, min_steps, max_steps, eval_ratio): """Returns the Pipeline instance which creates the RNN dataset. Args: config: An EventSequenceRnnConfig. min_steps: Minimum number of steps for an extracted sequence. max_steps: Maximum number of steps for an extracted sequence. eval_ratio: Fraction of input to set aside for evaluation set. Returns: A pipeline.Pipeline instance. """ # Transpose up to a major third in either direction. transposition_range = list(range(-4, 5)) partitioner = pipelines_common.RandomPartition( music_pb2.NoteSequence, ['eval_pianoroll_tracks', 'training_pianoroll_tracks'], [eval_ratio]) dag = {partitioner: dag_pipeline.DagInput(music_pb2.NoteSequence)} for mode in ['eval', 'training']: time_change_splitter = note_sequence_pipelines.TimeChangeSplitter( name='TimeChangeSplitter_' + mode) quantizer = note_sequence_pipelines.Quantizer( steps_per_quarter=config.steps_per_quarter, name='Quantizer_' + mode) transposition_pipeline = note_sequence_pipelines.TranspositionPipeline( transposition_range, name='TranspositionPipeline_' + mode) pianoroll_extractor = PianorollSequenceExtractor( min_steps=min_steps, max_steps=max_steps, name='PianorollExtractor_' + mode) encoder_pipeline = event_sequence_pipeline.EncoderPipeline( mm.PianorollSequence, config.encoder_decoder, name='EncoderPipeline_' + mode) dag[time_change_splitter] = partitioner[mode + '_pianoroll_tracks'] dag[quantizer] = time_change_splitter dag[transposition_pipeline] = quantizer dag[pianoroll_extractor] = transposition_pipeline dag[encoder_pipeline] = pianoroll_extractor dag[dag_pipeline.DagOutput(mode + '_pianoroll_tracks')] = encoder_pipeline return dag_pipeline.DAGPipeline(dag)
def get_pipeline(config, transposition_range=(0, ), eval_ratio=0.0): """Returns the Pipeline instance which creates the RNN dataset. Args: config: A MelodyRnnConfig object. transposition_range: Collection of integer pitch steps to transpose. eval_ratio: Fraction of input to set aside for evaluation set. Returns: A pipeline.Pipeline instance. """ partitioner = pipelines_common.RandomPartition( note_seq.NoteSequence, ['eval_melodies', 'training_melodies'], [eval_ratio]) dag = {partitioner: dag_pipeline.DagInput(note_seq.NoteSequence)} for mode in ['eval', 'training']: time_change_splitter = note_sequence_pipelines.TimeChangeSplitter( name='TimeChangeSplitter_' + mode) transposition_pipeline = note_sequence_pipelines.TranspositionPipeline( transposition_range, name='TranspositionPipeline_' + mode) quantizer = note_sequence_pipelines.Quantizer( steps_per_quarter=config.steps_per_quarter, name='Quantizer_' + mode) melody_extractor = melody_pipelines.MelodyExtractor( min_bars=7, max_steps=512, min_unique_pitches=5, gap_bars=1.0, ignore_polyphonic_notes=False, name='MelodyExtractor_' + mode) encoder_pipeline = EncoderPipeline(config, name='EncoderPipeline_' + mode) dag[time_change_splitter] = partitioner[mode + '_melodies'] dag[quantizer] = time_change_splitter dag[transposition_pipeline] = quantizer dag[melody_extractor] = transposition_pipeline dag[encoder_pipeline] = melody_extractor dag[dag_pipeline.DagOutput(mode + '_melodies')] = encoder_pipeline return dag_pipeline.DAGPipeline(dag)