Too many epochs and the model will overfit and just copy the source music.īut how do you know how many epochs to stop at?Ī simple method is to add a callback that saves the model and a plot of accuracy and loss every 50 epochs during a 500 epoch training run. Too few epochs and the output will have too many repeated notes. Training new models and composing midi files is approximately 5 times as fast using CuDNNLSTM.ĭepending on how long you train the model (how many epochs) determines how similar to the source music the results will be. If you do not have a Cuda capable GPU you would need to change these back to LSTM. This results in much faster LSTM training by using Cuda. Note that in both models I have replaced LSTM with CuDNNLSTM.
![youtube chopin music with rnn youtube chopin music with rnn](https://i.ytimg.com/vi/s_a8mznq8eI/maxresdefault.jpg)
There are most likely better models, but this one worked OK for the rest of my training sessions. I added BatchNormalization too after seeing it in a sentdex video. pile(loss='categorical_crossentropy', optimizer='adam',metrics=) Model.add(CuDNNLSTM(512, input_shape=(network_input.shape, network_input.shape), return_sequences=True)) I have no idea why, but I gave up on that model and started tweaking settings. See the good plots further down this post to see what the accuracy plot should like look in a working model. The accuracy never rises as it should over time and the loss gets stuck at around 3.4 because of this. Once I had plotting added to the script I saw why the model does not work.
![youtube chopin music with rnn youtube chopin music with rnn](https://i.pinimg.com/736x/23/a7/06/23a706ef00e2872051586fed97b0f6cf.jpg)
pile(loss='categorical_crossentropy', optimizer='rmsprop',metrics=) Model.add(CuDNNLSTM(512, return_sequences=True)) Model.add(CuDNNLSTM(512,input_shape=(network_input.shape, network_input.shape),return_sequences=True)) I reran it two times more and got the same results. When I used the predict.py to generate midi files they all disappointingly contained just a repeated single note.
![youtube chopin music with rnn youtube chopin music with rnn](https://i.ytimg.com/vi/C4e8a4nmJC8/maxresdefault.jpg)
I ran the included lstm.py script and after 15 hours it had finished training.
Youtube chopin music with rnn code#
The model I based my code on was this example by Sigurður Skúli Sigurgeirsson which he describes in more detail here. That way the user can select Bach, click the Compose button and have a piece of music generated that (hopefully) sounds a little like Bach. Music of different composers is put into separate folders. I found single piano midi files at Classical Piano Midi Page and mfiles that I used for training my models. Solo piano midi files work well for this. The above diagrams of LSTM internals may look daunting, but using TensorFlow and/or Keras makes creating and experimenting with LSTMs much simpler.įor these simpler LSTM composer networks you want source songs with just a single midi channel. Once the network has been trained sufficiently it is then able to create music that is similar to the training material. The LSTM network is fed a bunch of different note sequences (in this case single channel midi files). Another page that goes into more depths about LSTMs is here. LSTM networks are good at predicting “what comes next” in a sequence of data. The composer works by training a long short-term memory (LSTM) neural network. After recently having some success learning and implementing TensorFlow and neural networks for cellular automata searching I was keen to try using neural networks for music creation. Mostly based on simple math formulas or genetic mutations of random note sequences. I have had some primitive attempts at automated music composition over the years in Visions of Chaos.
Youtube chopin music with rnn software#
If/when I get the code working in newer Python and/or PyTorch I will remove this message.įor almost as long as I have been able to program I have wanted to create software that could compose music.
![youtube chopin music with rnn youtube chopin music with rnn](https://i.ytimg.com/vi/fg-iRQY_CzM/maxresdefault.jpg)
The source and samples are still available in this post for those interested in LSTM. Until I get the Python code updated it is currently not available to use under Visions of Chaos. This is a historic post covering an older music generation method.