Automatic music genre classifiers
The project is built in python2.7
Create and activate a fresh virtual environment:
conda create -n [yourenvname] python=2.7 anaconda
source activate [yourenvname]
Install required packages:
conda install -n [yourenvname] --yes --file requirements.txt
If you get a PackageNotFoundError
, add necessary channels:
conda config --add channels conda-forge
conda config --add channels litl-rnd
and run the previous command again.
In a fresh virtual environment, run
pip install -r requirements.txt
For training and testing our classifiers we use GTZAN music genre collection, but we are restricted to a subset which is not including classical and jazz genres, because one of our classifiers depends on lyrics, and classical and jazz music representatives are mostly instrumentals. To download raw data, run
python download_data.py
This will create data/ directory in project's root, and download and extract both audio and lyrics datasets into it's subdirectories: data/genres/ and data/lyrics/
After that, run
python preprocess_data.py
to create preprocessed datasets (also stored in data/ directory).
To train CRNN (Convolutional Recurrent Neural Network) classifier, run
python train_crnn_model.py
To train Naive Bayes classifier, run
python train_naive_bayes_model.py
Models and weights are saved in models/ directory.
This project includes a small python app that demonstrates the CRNN classifier.
If you want to enable downloading audio from YouTube, make sure you have youtube-dl and pafy libraries installed:
pip install youtube_dl==2017.5.23
pip install pafy==0.5.3.1
Command to run demo app:
python server.py
Now you can access the demo app from your browser at localhost:8080.
There are some example songs at /examples
- melspectrogram.py - generates mel-scaled log-power spectrogram
- lbr_melspectrogram.py - generates mel-scaled log-power spectrogram using librosa lib
Usage:
python melspectrogam.py path/to/audio/file
python lbr_melspectrogam.py path/to/audio/file
- get_lyrics.py - azlyrics, metrolyrics and oldielyrics crawler
Usage:
python get_lyrics.py 'The Smiths' 'Handsome Devil'
- nb_predict.py - uses Naive Bayes model to predict song genre
Usage:
python nb_predict.py path/to/lyrics/file
or
python nb_predict.py 'The Smiths' 'Handsome Devil'