A deep learning project for Speech Emotion Recognition (SER) using Transformer-based architectures on the CREMA-D dataset.
-
Data Pipeline
- Download and preprocessing script for CREMA-D dataset
- Audio loading with librosa
- Mel spectrogram feature extraction (64 mel bins, 4-second clips)
- Train/validation/test split (70/10/20)
-
Model Architectures
- CNN + Transformer hybrid model (
CNNTransformerModel) - Pure Spectrogram Transformer model (
SpectrogramTransformer) - Positional encoding, attention mechanisms, classification heads
- CNN + Transformer hybrid model (
-
Training Pipeline
- PyTorch training loop with GPU support
- AdamW optimizer with learning rate scheduling
- Early stopping with patience
- Model checkpointing (best model saved)
-
Evaluation Pipeline
- Accuracy, F1-score (macro/weighted) metrics
- Per-class accuracy analysis
- Confusion matrix visualization
- Classification report generation
-
Exploratory Notebook
- Data exploration and visualization
- Audio playback functionality
- Label distribution analysis
-
Data Augmentation
- Time stretching, pitch shifting
- SpecAugment (frequency/time masking)
- Noise injection
-
Model Improvements
- Implement attention visualization
- Add model ensembling
- Experiment with pre-trained audio models (wav2vec2, HuBERT)
-
Advanced Training
- Cross-validation
- Hyperparameter tuning (learning rate, model size, etc.)
- Mixed precision training (FP16)
- Gradient accumulation for larger effective batch sizes
-
Deployment
- ONNX export for inference
- Real-time inference demo
- Web API endpoint
-
Documentation
- Add detailed model architecture diagrams
- Benchmark comparisons with other SER methods
- Hyperparameter sensitivity analysis
audio-transformer-project/
├── data/
│ └── download_data.py # Script to download CREMA-D dataset
├── notebooks/
│ └── module_notebook.ipynb # Data exploration and preprocessing
├── src/
│ ├── models/
│ │ ├── __init__.py
│ │ ├── cnn_with_trans.py # CNN + Transformer model
│ │ └── spect_transformer.py # Pure Transformer model
│ ├── preprocessing/
│ │ ├── __init__.py
│ │ ├── data_load.py # Dataset class for loading audio
│ │ └── preprocess.py # Audio preprocessing utilities
│ ├── train.py # Training script
│ └── evaluate.py # Evaluation script
├── checkpoints/ # Saved model checkpoints (gitignored)
├── results/ # Evaluation results (gitignored)
├── requirements.txt
├── LICENSE
└── README.md
CREMA-D (Crowd-sourced Emotional Multimodal Actors Dataset)
- 7,442 audio clips from 91 actors
- 6 emotion classes:
angry,disgust,fear,happy,neutral,sad - Sample rate: 16kHz
git clone https://github.com/yourusername/audio-transformer-project.git
cd audio-transformer-projectpython -m venv venv
# Windows
.\venv\Scripts\Activate
# Linux/Mac
source venv/bin/activatepip install -r requirements.txt- Windows: Download from ffmpeg.org and add to PATH
- Linux:
sudo apt install ffmpeg - Mac:
brew install ffmpeg
python data/download_data.pyThis downloads the CREMA-D dataset and saves audio files to data/crema_d/audio/ with labels in data/crema_d/labels.csv.
Run the Jupyter notebook to generate mel spectrogram features:
jupyter notebook notebooks/module_notebook.ipynbThis saves preprocessed features to src/features/X.npy and src/features/y.npy.
python src/train.py --epochs 50 --batch_size 32 --lr 0.001Training Arguments:
| Argument | Default | Description |
|---|---|---|
--epochs |
50 | Number of training epochs |
--batch_size |
32 | Batch size |
--lr |
0.001 | Learning rate |
--features_dir |
src/features | Path to features directory |
--checkpoint_dir |
checkpoints | Path to save checkpoints |
python src/evaluate.py --checkpoint checkpoints/best_model.ptEvaluation Arguments:
| Argument | Default | Description |
|---|---|---|
--checkpoint |
checkpoints/best_model.pt | Path to model checkpoint |
--batch_size |
32 | Batch size for inference |
--output_dir |
results | Directory to save results |
--plot |
True | Generate confusion matrix plot |
Input: Mel Spectrogram (64 x T)
↓
CNN Feature Extractor (3 conv layers)
↓
Linear Projection → d_model
↓
Positional Encoding
↓
Transformer Encoder (4 layers)
↓
Global Average Pooling
↓
Classification Head → 6 classes
Input: Mel Spectrogram (64 x T)
↓
Linear Projection (per frame) → d_model
↓
[CLS] Token + Positional Encoding
↓
Transformer Encoder (6 layers, pre-norm)
↓
CLS Token Output
↓
Classification Head → 6 classes
Model Hyperparameters:
| Parameter | CNN+Transformer | Spectrogram Transformer |
|---|---|---|
| d_model | 256 | 256 |
| nhead | 8 | 8 |
| num_layers | 4 | 6 |
| dim_feedforward | 512 | 512 |
| dropout | 0.1 | 0.1 |
- Python 3.10+
- PyTorch 2.0+
- CUDA (optional, for GPU acceleration)
See requirements.txt for full dependencies.
This project is licensed under the terms specified in the LICENSE file.