def generate_data(self, data_dir, tmp_dir, task_id=-1): del task_id from magenta.models.score2perf import datagen_beam # pylint: disable=g-import-not-at-top,import-outside-toplevel def augment_note_sequence(ns, stretch_factor, transpose_amount): """Augment a NoteSequence by time stretch and pitch transposition.""" augmented_ns = sequences_lib.stretch_note_sequence(ns, stretch_factor, in_place=False) try: _, num_deleted_notes = sequences_lib.transpose_note_sequence( augmented_ns, transpose_amount, min_allowed_pitch=MIN_PITCH, max_allowed_pitch=MAX_PITCH, in_place=True) except chord_symbols_lib.ChordSymbolError: raise datagen_beam.DataAugmentationError( 'Transposition of chord symbol(s) failed.') if num_deleted_notes: raise datagen_beam.DataAugmentationError( 'Transposition caused out-of-range pitch(es).') return augmented_ns augment_params = itertools.product(self.stretch_factors, self.transpose_amounts) augment_fns = [ functools.partial(augment_note_sequence, stretch_factor=s, transpose_amount=t) for s, t in augment_params ] datagen_beam.generate_examples( input_transform=self.performances_input_transform(tmp_dir), output_dir=data_dir, problem_name=self.dataset_filename(), splits=self.splits, min_hop_size_seconds=self.min_hop_size_seconds, max_hop_size_seconds=self.max_hop_size_seconds, min_pitch=MIN_PITCH, max_pitch=MAX_PITCH, num_replications=self.num_replications, encode_performance_fn=self.performance_encoder( ).encode_note_sequence, encode_score_fns=dict((name, encoder.encode_note_sequence) for name, encoder in self.score_encoders()), augment_fns=augment_fns, absolute_timing=self.absolute_timing, random_crop_length=self.random_crop_length_in_datagen)
def generate_data(self, data_dir, tmp_dir, task_id=-1): del task_id def augment_note_sequence(ns, stretch_factor, transpose_amount): """Augment a NoteSequence by time stretch and pitch transposition.""" augmented_ns = sequences_lib.stretch_note_sequence( ns, stretch_factor, in_place=False) try: _, num_deleted_notes = sequences_lib.transpose_note_sequence( augmented_ns, transpose_amount, min_allowed_pitch=MIN_PITCH, max_allowed_pitch=MAX_PITCH, in_place=True) except chord_symbols_lib.ChordSymbolError: raise datagen_beam.DataAugmentationError( 'Transposition of chord symbol(s) failed.') if num_deleted_notes: raise datagen_beam.DataAugmentationError( 'Transposition caused out-of-range pitch(es).') return augmented_ns augment_fns = [ functools.partial( augment_note_sequence, stretch_factor=stretch_factor, transpose_amount=transpose_amount) for stretch_factor, transpose_amount in itertools.product( self.stretch_factors, self.transpose_amounts) ] datagen_beam.generate_examples( input_transform=self.performances_input_transform(tmp_dir), output_dir=data_dir, problem_name=self.dataset_filename(), splits=self.splits, min_hop_size_seconds=self.min_hop_size_seconds, max_hop_size_seconds=self.max_hop_size_seconds, min_pitch=MIN_PITCH, max_pitch=MAX_PITCH, num_replications=self.num_replications, encode_performance_fn=self.performance_encoder().encode_note_sequence, encode_score_fns=dict((name, encoder.encode_note_sequence) for name, encoder in self.score_encoders()), augment_fns=augment_fns, absolute_timing=self.absolute_timing)
def testGenerateExamples(self): ns = music_pb2.NoteSequence() testing_lib.add_track_to_sequence( ns, 0, [(60, 100, 0.0, 1.0), (64, 100, 1.0, 2.0), (67, 127, 2.0, 3.0)]) input_transform = beam.transforms.Create([('0', ns.SerializeToString())]) output_dir = tempfile.mkdtemp() encoder = music_encoders.MidiPerformanceEncoder( steps_per_second=100, num_velocity_bins=32, min_pitch=21, max_pitch=108) datagen_beam.generate_examples( input_transform=input_transform, output_dir=output_dir, problem_name='test_problem', splits={'train': 1.0}, min_hop_size_seconds=3.0, max_hop_size_seconds=3.0, min_pitch=21, max_pitch=108, num_replications=1, encode_performance_fn=encoder.encode_note_sequence)
def testGenerateExamples(self): ns = music_pb2.NoteSequence() testing_lib.add_track_to_sequence( ns, 0, [(60, 100, 0.0, 1.0), (64, 100, 1.0, 2.0), (67, 127, 2.0, 3.0)]) input_transform = beam.transforms.Create([('0', ns.SerializeToString())]) output_dir = tempfile.mkdtemp() encoder = music_encoders.MidiPerformanceEncoder( steps_per_second=100, num_velocity_bins=32, min_pitch=21, max_pitch=108) datagen_beam.generate_examples( input_transform=input_transform, output_dir=output_dir, problem_name='test_problem', splits={'train': 1.0}, min_hop_size_seconds=3.0, max_hop_size_seconds=3.0, min_pitch=21, max_pitch=108, num_replications=1, encode_performance_fn=encoder.encode_note_sequence)