This project implements three different approaches to music genre classification using machine learning and deep learning techniques.
Genre Classification Notebook
or
Mood Classification Notebook
or
Music genre classification is a fundamental task in Music Information Retrieval (MIR) that automatically categorizes music tracks based on their audio characteristics. We explore three different methodologies for classifying the GTZAN dataset into 10 genres (Blues, Classical, Country, Disco, Hip-hop, Jazz, Metal, Pop, Reggae, and Rock).
The data is provided in three formats:
- Essentia descriptors (ARFF files): Audio features extracted using the Essentia library
- Global and segment features (CSV files): Features extracted at different time scales (30-second and 3-second)
- Spectrograms (PNG images): Visual representations of audio frequency content over time
We used audio descriptors provided in ARFF format to train and evaluate various machine learning models.
- Processed ARFF files, handling 3 categorical features and 237 numerical features
- Applied feature selection using ANOVA F-test to identify the most informative features
- Compared multiple algorithms (Logistic Regression, SVM, KNN, Decision Trees, Random Forest, Neural Networks)
- Performed hyperparameter tuning for top-performing models
- Implemented ensemble learning using a voting classifier
- Neural Network: 100% test accuracy (best model)
- SVM: 94.8% test accuracy
- Logistic Regression: 90.7% test accuracy
- Ensemble: 99.5% test accuracy
- Perfect test accuracy suggests either exceptional feature separation or potential overfitting
- Notable gap between cross-validation (83.1%) and test performance (100%)
- Essentia descriptors provide highly discriminative features for genre classification
We compared global features (30-sec) and segment-level features (3-sec) provided in CSV format to determine which time scale is more effective.
- Applied similar methodology to Task 1 (feature selection, model comparison, hyperparameter tuning)
- Created separate pipelines for 30-second and 3-second features
- Conducted comparative analysis between the two feature sets
- 3-second features generally achieved higher accuracy
- Similar model ranking pattern to Task 1
- Feature importance analysis revealed key audio characteristics for genre discrimination
We implemented deep learning approaches to classify music genres directly from spectrogram images.
- Loaded and preprocessed spectrogram images (224×224 RGB)
- Applied data augmentation (rotation, flips, color adjustments)
- Implemented two models:
- Custom CNN: 4 convolutional blocks with increasing filter complexity
- Audio Spectrogram Transformer (AST): Transformer-based architecture for spectrograms
- Used PyTorch
- Implemented early stopping and learning rate scheduling
- Custom CNN: 76.0% test accuracy
- AST: 60.5% test accuracy
- Most confusion between country/rock (25%) and reggae/hiphop (20%)
- CNN architecture excelled at capturing local spectrogram patterns
- Simpler CNN outperformed the more complex AST model
- Genre confusion patterns aligned with musicological similarities
- CNN's local pattern recognition proved more effective than the transformer's global attention
| Approach | Best Model | Test Accuracy |
|---|---|---|
| Essentia Descriptors | Neural Network | 100.0% |
| CSV Features | Varied by feature set | 80-90% |
| Spectrograms | Custom CNN | 76.0% |
Using uv (faster, modern Python package installer)
uv sync or
uv pip sync requirements.txt
Using traditional pip
pip install -r requirements.txt
Requirements
numpy
pandas
matplotlib
seaborn
scikit-learn
scipy
torch
torchvision
opencv-python
tqdm
-
Ensure all data files are in the correct directories (data/):
GenreTrain.arffandGenreTest.arfffor Task 1features_30_sec.csvandfeatures_3_sec.csvfor Task 2- Spectrogram images in
images_original/directory for Task 3
-
Run each task in sequence in the notebook:
-
Review the results and visualizations within the notebook
This project demonstrates that while hand-crafted audio features (Essentia descriptors) currently provide the best classification performance, deep learning approaches with spectrograms show promise, especially with domain-specific architectures. The custom CNN's superior performance over the AST model highlights that sometimes simpler architectures better capture the relevant patterns for music genre classification.