Training the music GAN

Before we get into training this network, we will look at the overall architecture as depicted in the author's original GitHub source:



Overview of museGAN network architecture

The networks are almost identical until you look closer and see the subtle differences in the LSTM layers. Note how one set uses double the units as the other model.

We can generate music models by running the following command at the Python or Anaconda prompt:

python note-generator.py 
or
python3 note-generator.py

This script loads the sample data and generates the models we use in the musegen.py file later when we create original music. Open up the note-generator.py file with the main parts shown here:

The code was modified from the original to make it more Windows-compatible and cross-platform. Again, this is certainly not a criticism of the author's excellent work.
def loadChorales():
notes = []
iterator = getChoralesIterator()

# load notes of chorales
for chorale in iterator[1:maxChorales]: # iterator is 1-based
transpose_to_C_A(chorale.parts[0])
notes = notes + parseToFlatArray(chorale.parts[0])
notes.append((['end'], 0.0)) # mark the end of the piece

return notes

This code uses the Music21 library to read the MIDI notes and other music forms from the corpus of music you can use for your own testing. This training dataset is an excellent way to generate other sources of music and is composed of the following: http://web.mit.edu/music21/doc/moduleReference/moduleCorpus.html.

You can further modify this example by modifying the contents or adding additional configuration options in the config.py file as shown:

# latent dimension of VAE (used in pitch-generator)
latent_dim = 512

# latent dimensions for pitches and durations (used in note-generator)
latent_dim_p = 512
latent_dim_d = 256

# directory for saving the note embedding network model --- not used anymore
note_embedding_dir = "models/note-embedding"

# directory for saving the generator network model
pitch_generator_dir = 'models/pitch-generator'

# directory for saving the note generator network model
note_generator_dir = 'models/note-generator'

# directory for saving generated music samples
output_dir = 'samples'

The previous sample is great for exploring the generation of music. A more practical and potentially useful example will be introduced in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset