midiGenerator
midiGenerator copied to clipboard
Generate midi file with deep neural network :notes:
Midi Generator
Introduction
This project aim to train different neural networks on midi dataset to generate music
Context
This repository contains the code of my Master Thesis for my Master in the School of Computing of the National University of Singapore ""Music completion with deep probabilistic models"
The Report, Abstract and Presentation's slides are available here
Files
bayesian-opt.py
python bayesian-opt.py
It is used to find the best hyper parameters to train a model
compute_data.py
python compute_data.py
It is used to compute the .mid files of the dataset and create the
numpy arrays used to train a model.
generate.py
python generate.py
Loads a trained model and generate music from it.
train.py
python train.py
Creates or loads a model, train it, and also generate music at the end.
How to use it
Setup
First, get a midi dataset and save all the song in a folder Dataset
The emplacement of this folder has to be at the emplacement ../../../../../storage1/valentin/.
To change it, go in the files src/GlobalVariables/path.py and modify it.
The midi files have to be in a folder.
The name of the folder is the name of the dataset
Get the information of the dataset
To get the information of the dataset, run
python debug/check_dataset.py <DATANAME>
Main options:
datais the name of the dataset name-hor--helpplot the options of the file--notes-rangethe range of the notes. Default is0:88--instrumentsthe instruments separated by a,(ex:Piano,Trombone)--bachfor bach dataset (4 voices of piano)--monoto specify to use mono encoding for monophonic music--no-transposedon't transpose the songs in C major or A minor
The file will print the number of available songs and the notes-range to specify to not loss any data
Compute the dataset
To extract the tensors from a midi dataset and save them
python compute_data.py <DATANAME>
The main options are:
datais the name of the dataset-hor--helpwill print the options of the file--notes-rangeto specify the range of the notes to consider--instrumentsthe instruments separated by a,(ex:Piano,Trombone)--bachfor bach dataset (4 voices of piano)--monoto specify to use mono encoding for monophonic music--no-transposedon't transpose the songs in C major or A minor
Train and use a model
To train, evaluation, create songs with a model, run
python train.py
The main options are:
-hor--helpto print the options of the file-dor--datathe name of the dataset--data-testthe name of the test dataset-mor--modelto specify the model to use (modelName,nameParam,nbSteps)-lor--loadto load the id of the model (name-modelName,nameParam,nbSteps-epochs-id)--monois used to use a monophonic dataset--no-transposedis used to not use a transpose dataset (to C major or A minor)-eor--epochsnumber of epochs--gpuspecifies the GPU to use-bor--batchthe batch size--lrspecifies the learning rate--no-rpoeis used to not used the RPoE layer (Recurrent Product of Experts)--validationthe proportion of the data tu use as a validation set--predict-offsetthe offset of prediction (use2for the band player script)--evaluateto evaluate the model on the test dataset--generatedo the generate task--generate-filldo the fill task--redo-generatedo the redo task--noisevalue of the noise in the inputs of the training data-nor--nameto give a name to the model--use-binaryuse the sigmoid loss for a note_continue for monophonic music
To get the best results from the report, run:
python train.py -d DATANAME --data-test DATATESTNAME -m MRRMVAE,1,8 --use-binary --mono --evaluate --generate --generate-fill --redo-generate
Band Player
This file load a trained model and use a it to play with the user in real time
python controller.py
The main options are:
-hor--helpto print the options of the file--instto specify what instrument sound the user wants--tempospecify the tempo-lor--loadto load the id of the model (name-modelName,nameParam,nbSteps-epochs-id)--played-voicethe voice played by the user in the band--inst-masklist of the mask to choose the voices the user wants to play with (to play the first voice and with the second and last voice for a model with 5 voices:[1,1,0,0,1])--nb-steps-shownthe number of steps showed on the piano roll plot