Skip to content

JustinShenk/genre-melodies

Repository files navigation

Deep learning genre-specific melodies with Magenta

Getting Started

This docker installation of a minimal jazz melody generation implementation which runs all of the scripts and begins generating:

docker run -it -p 6006:6006 -v /tmp/magenta:/genre-melodies justinshenk/melodic

Manual Magenta installation:

sudo apt-get update -y
sudo apt-get install libasound2-dev libasound-dev libjack-dev git -y
curl https://raw.githubusercontent.com/tensorflow/magenta/master/magenta/tools/magenta-install.sh > /tmp/magenta-install.sh &&
bash /tmp/magenta-install.sh

or using Conda (NOTE: Magenta currently supports version 2 of Python):

conda create -n magenta python=2.7 jupyter
source activate magenta

Open a new terminal window so the environmental variable changes take effect and enter:

source activate magenta && pip install tensorflow-gpu &&
git clone https://github.com/JustinShenk/genre-melodies.git &&
cd genre-melodies &&
pip install -r requirements.txt &&
python create_dataset.py &&
sh train_model.sh

If using a CPU replace 'tensorflow-gpu' with 'tensorflow'.

Preprocessing and Analysis

See the preprocessing and visualization notebook for sample outputs and visualization scripts.

Visualizations:

2d visualization

3d visualization

Tensorboard graph of trained network:

Tensorboard Graph

Postprocessing

Convert MIDIs to MP3 using timidity.

Install timidity with brew install timidity (OSX) or sudo apt-get install timidity (Ubuntu).

To play the sounds in a browser, convert the files to a format supported by HTML5, such as mp3. Find the generated MIDI files in /tmp/melody_rnn/generated/[genre]. Use a one-line shell command to convert MIDI files to mp3:

$ for file in *.mid ; do timidity "${file}" -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 64k "${file%.*}.mp3"; done

Output

Check out some samples with an explanation of Magenta's hyperparameters.