jason9693 / MusicTransformer-tensorflow2.0

implementation of music transformer with tensorflow-2.0 (ICLR2019)
MIT License
353 stars 81 forks source link

Music Transformer: Generating Music with Long-Term Structure

Abstract

  1. This Repository is perfectly compatible with tensorflow 2.0
  2. If you want pytorch version, see here

Contribution

Preprocessing

Repository Setting

$ git clone https://github.com/jason9693/MusicTransformer-tensorflow2.0.git
$ cd MusicTransformer-tensorflow2.0
$ git clone https://github.com/jason9693/midi-neural-processor.git
$ mv midi-neural-processor midi_processor

Midi Download

$ sh dataset/script/{ecomp_piano_downloader, midi_world_downloader, ...}.sh

Prepare Dataset

$ python preprocess.py {midi_load_dir} {dataset_save_dir}

Trainig

Hyper Parameter

Result

Generate Music

Generated Samples ( Youtube Link )

TF2.0 Trouble Shooting

1. tf.keras

you can't use tf.keras directly in alpha ver. So you should import from tensorflow.python import keras ,then use > keras.{METHODS}

2. tf.keras.optimizers.Adam()

tf-2.0alpha currently not supported keras.optimizers as version 2. so, you can't use optimizer.apply_gradients(). So, you should import from tensorflow.python.keras.optimizer_v2.adam import Adam first.

3. Keras Model Subclassing

current tf 2.0(alpha) , subclassed keras model can't use method save(), summary(), fit() and save_weigths() with .h5 format

4. Distribute Training

As dist train (with 4GPU) is slower than using single GPU, I trained this model with single GPU. Nonethless, you want to see how to distribute training, See dist_train.py