This project uses a Convolutional Neural Network (CNN) built with Keras and TensorFlow to classify music into 10 different genres based on their audio features (MFCCs).
Demo.Video.mp4
- Classifies 10 music genres from the GTZAN dataset.
- Extracts Mel-Frequency Cepstral Coefficients (MFCCs) using Librosa.
- Uses a Keras CNN model for classification.
- Provides a command-line script to predict the genre of any audio file.
data_and_training.ipynb: Jupyter Notebook for data processing, model training, and evaluation.predict.py: Command-line script to classify a new audio file.visualize.py: Generate a spectrogram for an audio filerequirements.txt: A list of all required Python packages.
-
Clone the repository:
git clone https://github.com/debug-soham/Music-Genre-Classification.git cd music-genre-classification -
Download the Dataset:
- Download the GTZAN Genre Collection dataset from here.
- Unzip it and place the
genres_originalfolder inside a newDatafolder in the project root. The final path should beData/genres_original/. (Note: The Data folder is not included in this repository due to its size.)
-
Create a Virtual Environment:
# Make sure you have Python 3.11 installed py -3.11 -m venv my_env .\my_env\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
-
Train the Model:
- Open and run all the cells in the
01_data_and_training.ipynbnotebook. - This will create two files:
data.jsonandmusic_genre_classifier.keras.
- Open and run all the cells in the
-
Predict a Genre:
- Use the
predict.pyscript to classify an audio file:
python predict.py "path/to/your/song.wav" - Use the
-
Visualize a Spectrogram (Optional)
- Use the
visualize.pyscript to generate a spectrogram for any audio file:
python visualize.py "path/to/your/song.wav" - Use the
- Python 3.11
- TensorFlow / Keras
- Librosa
- Scikit-learn
- NumPy
- Matplotlib