DatasetGenerator Class¶
This class can be used to generate datasets from instances of synthesizers. This is useful for creating large sets of data for training and validating deep learning models.
Examples
Example generating 50000 training samples and 10000 testing samples from the Dexed VST FM Synthesizer. Each sample is created by creating a random patch configuration in Dexed, and then rendering a one second audio clip of that patch. A 13-band MFCC is computed on the resulting audio. These audio features and the synthesizer parameters used to synthesize the audio are saved in numpy files. Audio features are standardized by removing the mean and scaling to unit variance. The values used for scaling are saved after the first dataset generation so they can be used on future data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import spiegelib as spgl
synth = spgl.synth.SynthVST("/Library/Audio/Plug-Ins/VST/Dexed.vst",
note_length_secs=1.0,
render_length_secs=1.0)
# Mel-frequency Cepstral Coefficients audio feature extractor.
features = spgl.features.MFCC(num_mfccs=13, frame_size=2048,
hop_size=1024 time_major=True)
# Setup generator for MFCC output and generate 50000 training examples
# and 10000 testing examples
generator = spgl.DatasetGenerator(synth, features,
output_folder="./data_FM_mfcc",
normalize=True)
generator.generate(50000, file_prefix="train_")
generator.generate(10000, file_prefix="test_")
generator.save_scaler('data_scaler.pkl')
|
-
class
spiegelib.
DatasetGenerator
(synth, features, output_folder='/Users/jshier/Development/Academic/spiegel/docs', save_audio=False, scale=False)¶ - Parameters
synth (Object) – Synthesizer to generate test data from. Must inherit from
spiegelib.synth.SynthBase
.features (Object) – Features to use for dataset generation. Must inherit from
spiegelib.features.FeaturesBase
.output_folder (str, optional) – Output folder for dataset, defaults to currect working directory.
save_audio (bool, optional) – Whether or not to save rendered audio files, defaults to False.
scale (bool, optional) – Whether or not to scale resulting feature vector. If the feature object does not have a scaler set, then this will train a data scaler based on the generated dataset and store them in the features object. Call
save_scaler()
to store scaler settings. Defaults to False.
-
features_filename
¶ filename for features output file, defaults to features.npy
- Type
str
-
patches_filename
¶ filename for patches output file, defaults to patches.npy
- Type
str
-
audio_folder_name
¶ folder name for the audio output if used. Will be automatically created within the output folder if saving audio. Defaults to audio
- Type
str
-
generate
(size, file_prefix='', fit_scaler_only=False)¶ Generate dataset with a set of random patches. Saves the extracted features and parameter settings in separate .npy files. Files are stored in the output folder set during construction (defaults to current working directory) and saves the features as “features.npy” and patches as “patches.npy”. These file names can be prefixed with a string set by the file_prefix argument. If audio files are being saved (configured during construction), then the audio files are saved in a separate audio folder and all audio files are also prefixed by the file_prefix.
- Parameters
size (int) – Number of different synthesizer patches to render.
file_prefix (str, optional) – filename prefix for all output data.
fit_scaler_only (bool, optional) – If this is set to True, then no data will be saved and only scaler will be set or reset for the feature object.
-
save_scaler
(file_name)¶ Save feature scaler as a pickle file.
- Parameters
file_name (str) – file name for scaler pickle file