Data augmentation
MidiTok offers data augmentation solutions, on the pitch octave, velocity and duration attributes.
- miditok.data_augmentation.data_augmentation_dataset(data_path: Path | str, tokenizer=None, nb_octave_offset: int = None, nb_vel_offset: int = None, nb_dur_offset: int = None, octave_directions: Tuple[bool, bool] = (True, True), vel_directions: Tuple[bool, bool] = (True, True), dur_directions: Tuple[bool, bool] = (True, True), all_offset_combinations: bool = False, out_path: Path | str = None, copy_original_in_new_location: bool = True)
Perform data augmentation on a whole dataset, on the pitch dimension. Drum tracks are not augmented. The new created files have names in two parts, separated with a ‘§’ character. Make sure your files do not have ‘§’ in their names if you intend to reuse the information of the second part in some script.
- Parameters:
data_path – root path to the folder containing tokenized json files.
tokenizer – tokenizer, needs to have ‘Pitch’ or ‘NoteOn’ tokens. Has to be given if performing augmentation on tokens (default: None).
nb_octave_offset – number of pitch octaves offset to perform data augmentation.
nb_vel_offset – number of velocity values
nb_dur_offset – number of pitch octaves offset to perform data augmentation.
octave_directions – directions to shift the pitch augmentation, for up / down as a tuple of two booleans. (default: (True, True))
vel_directions – directions to shift the velocity augmentation, for up / down as a tuple of two booleans. (default: (True, True))
dur_directions – directions to shift the duration augmentation, for up / down as a tuple of two booleans. (default: (True, True))
all_offset_combinations – will perform data augmentation on all the possible combinations of offsets. If set to False, will perform data augmentation only based on the original sample.
out_path – output path to save the augmented files. Original (non-augmented) MIDIs will be saved to this location. If none is given, they will be saved in the same location an the data_path. (default: None)
copy_original_in_new_location – if given True, the orinal (non-augmented) MIDIs will be saved in the out_path location too. (default: True)
- miditok.data_augmentation.data_augmentation_midi(midi: MidiFile, tokenizer, pitch_offsets: List[int] = None, velocity_offsets: List[int] = None, duration_offsets: List[int] = None, all_offset_combinations: bool = False) List[Tuple[Tuple[int, int, int], MidiFile]]
Perform data augmentation on a MIDI object. Drum tracks are not augmented, but copied as original in augmented MIDIs.
- Parameters:
midi – midi object to augment
tokenizer – tokenizer, needs to have ‘Pitch’ tokens.
pitch_offsets – list of pitch offsets for augmentation.
velocity_offsets – list of velocity offsets for augmentation.
duration_offsets – list of duration offsets for augmentation.
all_offset_combinations – will perform data augmentation on all the possible combinations of offsets. If set to False, will perform data augmentation only based on the original sample.
- Returns:
augmented MIDI objects.
- miditok.data_augmentation.data_augmentation_tokens(tokens: ndarray | List[int], tokenizer, pitch_offsets: List[int] = None, velocity_offsets: List[int] = None, duration_offsets: List[int] = None, all_offset_combinations: bool = False) List[Tuple[Tuple[int, int, int], List[int]]]
Perform data augmentation on a sequence of tokens, on the pitch dimension. NOTE: token sequences with BPE will be decoded during the augmentation, this might take some time. NOTE 2: the tokenizer must have a vocabulary in which the pitch values increase with the token index, e.g. Pitch_48: token 64, Pitch_49: token65 … The same goes for durations. MIDILike is not compatible with data augmentation on durations. MuMIDI is not compatible at all.
- Parameters:
tokens – tokens to perform data augmentation on.
tokenizer – tokenizer, needs to have ‘Pitch’ tokens.
pitch_offsets – list of pitch offsets for augmentation.
velocity_offsets – list of velocity offsets for augmentation.
duration_offsets – list of duration offsets for augmentation.
all_offset_combinations – will perform data augmentation on all the possible combinations of offsets. If set to False, will perform data augmentation only based on the original sample.
- Returns:
the several data augmentations that have been performed