def testToNoteSequenceMultipleChunksWithChords(self): sequence = copy.deepcopy(self.sequence) testing_lib.add_track_to_sequence(sequence, 0, [ (64, 100, 0, 2), (60, 100, 0, 4), (67, 100, 2, 4), (62, 100, 4, 6), (59, 100, 4, 8), (67, 100, 6, 8), ]) testing_lib.add_track_to_sequence(sequence, 1, [ (40, 100, 0, 0.125), (50, 100, 0, 0.125), (50, 100, 2, 2.125), (40, 100, 4, 4.125), (50, 100, 4, 4.125), (50, 100, 6, 6.125), ], is_drum=True) testing_lib.add_chords_to_sequence(sequence, [('C', 0), ('G', 4)]) converter = data_hierarchical.MultiInstrumentPerformanceConverter( hop_size_bars=4, chunk_size_bars=2, chord_encoding=note_seq.MajorMinorChordOneHotEncoding()) tensors = converter.to_tensors(sequence) self.assertEqual(1, len(tensors.outputs)) sequences = converter.from_tensors(tensors.outputs, tensors.controls) self.assertEqual(1, len(sequences)) self.assertProtoEquals(sequence, sequences[0])
def setUp(self): super().setUp() self.config = improv_rnn_model.ImprovRnnConfig( None, note_seq.ConditionalEventSequenceEncoderDecoder( note_seq.OneHotEventSequenceEncoderDecoder( note_seq.MajorMinorChordOneHotEncoding()), note_seq.OneHotEventSequenceEncoderDecoder( note_seq.MelodyOneHotEncoding(0, 127))), contrib_training.HParams(), min_note=0, max_note=127, transpose_to_key=0)
def testMelodyRNNPipeline(self): note_sequence = magenta.common.testing_lib.parse_test_proto( note_seq.NoteSequence, """ time_signatures: { numerator: 4 denominator: 4} tempos: { qpm: 120}""") note_seq.testing_lib.add_track_to_sequence(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)]) note_seq.testing_lib.add_chords_to_sequence(note_sequence, [('N.C.', 0.0), ('Am9', 5.0), ('D7', 10.0)]) quantizer = note_sequence_pipelines.Quantizer(steps_per_quarter=4) lead_sheet_extractor = lead_sheet_pipelines.LeadSheetExtractor( min_bars=7, min_unique_pitches=5, gap_bars=1.0, ignore_polyphonic_notes=False, all_transpositions=False) conditional_encoding = note_seq.ConditionalEventSequenceEncoderDecoder( note_seq.OneHotEventSequenceEncoderDecoder( note_seq.MajorMinorChordOneHotEncoding()), note_seq.OneHotEventSequenceEncoderDecoder( note_seq.MelodyOneHotEncoding(self.config.min_note, self.config.max_note))) quantized = quantizer.transform(note_sequence)[0] lead_sheet = lead_sheet_extractor.transform(quantized)[0] lead_sheet.squash(self.config.min_note, self.config.max_note, self.config.transpose_to_key) encoded = pipelines_common.make_sequence_example( *conditional_encoding.encode(lead_sheet.chords, lead_sheet.melody)) expected_result = { 'training_lead_sheets': [encoded], 'eval_lead_sheets': [] } pipeline_inst = improv_rnn_pipeline.get_pipeline(self.config, eval_ratio=0.0) result = pipeline_inst.transform(note_sequence) self.assertEqual(expected_result, result)