CoolFace
Modelpublic

mlobj/music_source_separation

sourceHugging Facegplupdated 4y agoView on Hugging Face
1likes
train.py43 linesDownload Raw Back to root
1import argparse2 3import hparams4import utils5import multiresunet_model6 7import tensorflow as tf8import numpy as np9 10if __name__ == '__main__':11  args = argparse.ArgumentParser()12 13  args.add_argument('Path',metavar='path',type=str,help='Path to DSD100 pickled spectrograms. See preprocess_data.py for more details')14  args.add_argument('Source',metavar='source',type=str,help='Desired source to separate')15  args.add_argument('Spectrum',metavar='spectrum',type=str,help='Low (lf) or High (hf) frequencies training')16  args.add_argument('Outpath',metavar='model_out_path',type=str,help='Path to save the model to')17  18  ### Parse Args ###19  args = args.parse_args()20  path = args.Path21  source = args.Source22  spectrum = args.Spectrum23  output_path = args.Outpath24  25  ### Load Data ###26  x = np.load(path + 'mixture_' + spectrum + '.npy')27  y = np.load(path + source + '_' + spectrum + '.npy')28 29  ### Construct model ###30  model = multiresunet_model.Steminator((hparams.frequency_bins,hparams.chunk_size,hparams.n_channels))31  optimizer = tf.keras.optimizers.Adam(lr = hparams.learning_rate)32  model.compile(optimizer, loss='mean_absolute_error')33 34  ### Training ###35  model.fit(x,y,epochs = hparams.epochs, batch_size = hparams.batch_size)36 37  ### Save model ###38  model.save(output_path + source + '_' + spectrum + '.h5')39 40 41 42 43