PopMNet is a model for generating structured pop music melodies. It comprises a CNN-based Structure Generation Net (SGN) and an RNN-based Melody Generation Net (MGN). The SGN generates melody structures, while the MGN generates melodies conditioned on these structures and chord progressions.
To run the code in this repository, Python 3.6 and several other dependencies are required. To install these dependencies, execute the following command:
pip install -r requirements.txtMagenta is a research project that explores the role of machine learning in the creation of art and music. We utilize some code from Magenta to process our data.
The MusicXML files should be stored in the folder raw_data.
The initial step is to preprocess the data:
python data_process.py --input-dir raw_dataThe MusicXML files in the folder raw_data will be converted to magenta.music.LeadSheet objects and saved in data/LS.pickle.
Train the SGN:
python sgn/main.py --use_cudaThe checkpoints will be saved in results/sgn/checkpoints.
If no Nvidia GPU is available, please remove the --use_cuda option.
To generate melody structures:
python sgn/generate.py --use_cuda --sample_num 100Melody structures will be saved in results/sgn/samples in json formats.
To train the MGN:
python mgn/main.py data/LS.pickle --trainer plan --plan --chords --encoder-decoder onehot --save-dir results/mgn --render-chordsThe checkpoints will be saved in results/sgn/checkpoints.
To generate melodies conditioned on melody structures:
python mgn/main.py data/LS.pickle --inference --trainer plan --generate-dir results/mgn/generate \
--restore-file results/mgn/checkpoints/best_checkpoint \
--generate-num 100 \
--relations results/sgn/samplesNote that the --generate-num should be less than the --sample_num because the generation of melodies requires generated structures as a condition.
Please cite the following paper if you use the code provided in this repository.
@article{WU2020103303,
title = {PopMNet: Generating structured pop music melodies using neural networks},
journal = {Artificial Intelligence},
volume = {286},
pages = {103303},
year = {2020},
issn = {0004-3702},
doi = {https://doi.org/10.1016/j.artint.2020.103303},
url = {https://www.sciencedirect.com/science/article/pii/S000437022030062X},
author = {Jian Wu and Xiaoguang Liu and Xiaolin Hu and Jun Zhu},
}