This repository evaluates the robustness of audio classification models under adversarial attack conditions and measures whether adversarial training improves resistance to gradient-based attacks. The project uses a CNN trained on synthetic UrbanSound8K-style audio data and evaluates performance under FGSM and PGD adversarial attacks.
This project demonstrates how to build a research-style adversarial machine learning workflow with:
- Audio classification using convolutional neural networks
- Mel-spectrogram feature extraction
- Fast Gradient Sign Method (FGSM) attacks
- Projected Gradient Descent (PGD) attacks
- Adversarial training and model hardening
- Robustness benchmarking and evaluation
- Reproducible experimentation on consumer hardware
Machine learning models are often evaluated using clean test datasets. However, real-world systems may encounter malicious inputs specifically designed to cause misclassification.
This is particularly relevant for audio systems such as:
- Speech recognition
- Voice assistants
- Audio moderation systems
- Speaker identification systems
- Voice-cloning detection systems
Small perturbations added to an audio signal can significantly reduce model performance while remaining difficult for humans to detect.
This project evaluates how robust an audio classifier remains under attack conditions and whether adversarial training can improve resistance to these attacks.
Early experiments reported nearly perfect robustness under both FGSM and PGD attacks.
Further investigation revealed that this result was caused by:
- Extremely low training loss
- Vanishing gradients
- An overly separable synthetic dataset
The dataset and training procedure were revised to create a more realistic robustness benchmark using:
- Frequency jitter
- Increased noise
- Deliberate class overlap
- Label smoothing
A built-in sanity check verifies that gradients remain meaningful before adversarial attacks are evaluated.
This highlights an important lesson in adversarial machine learning:
A model that appears robust may simply be difficult to attack because gradients have collapsed rather than because genuine robustness has been learned.
The project uses a synthetic UrbanSound8K-style audio dataset consisting of:
- 10 audio classes
- Variable frequency ranges
- Background noise augmentation
- Frequency jitter
- Mel-spectrogram feature extraction
The dataset is generated programmatically within the notebook and does not require external downloads.
A convolutional neural network is trained on mel-spectrogram representations of synthetic audio samples.
Model architecture includes:
- 4 convolutional layers
- Batch normalization
- Dropout regularization
- Cross-entropy loss with label smoothing
The Fast Gradient Sign Method generates single-step adversarial perturbations using:
- ε = 0.03
This provides a fast estimate of model robustness against gradient-based attacks.
Projected Gradient Descent performs a stronger iterative attack using:
- ε = 0.03
- 10 attack steps
PGD is generally considered a more challenging robustness benchmark than FGSM.
The project trains a hardened model using adversarial examples and compares performance against the baseline model.
This allows direct measurement of how much robustness can be recovered through adversarial training.
| Model | Clean | FGSM | PGD |
|---|---|---|---|
| Baseline | 81.9% | 68.8% | 64.4% |
| Hardened | 81.9% | 75.6% | 75.0% |
- Adversarial training improved FGSM robustness by 6.8 percentage points
- Adversarial training improved PGD robustness by 10.6 percentage points
- Clean accuracy remained unchanged
- The largest gains occurred under the stronger PGD attack
These results suggest that adversarial training improved genuine robustness rather than merely defending against a single attack method.
Language: Python
Deep Learning: PyTorch
Audio Processing: Torchaudio
Numerical Computing: NumPy
Visualization: Matplotlib
Platform: Google Colab
Research Area: Adversarial Machine Learning, Robustness Evaluation, Audio Security
audioguard/
│
├── notebook/
│ └── AudioGuard.ipynb
│
├── paper/
│ └── audioguard.pdf
│
├── figures/
│ ├── robustness_comparison.png
│ ├── sample_spectrograms.png
│ └── perturbation_visual.png
│
├── results/
│ ├── results.json
│ └── report.md
│
├── requirements.txt
├── LICENSE
└── README.md
Install dependencies:
pip install -r requirements.txtRun the notebook:
notebook/AudioGuard.ipynb
A CUDA-enabled GPU is recommended for faster training and evaluation.
The workflow consists of four stages:
Synthetic audio samples are generated with class-specific frequency distributions and noise augmentation.
The CNN is trained on mel-spectrogram features using label smoothing to prevent loss saturation.
FGSM and PGD attacks are applied to measure baseline robustness.
A second model is trained using adversarial examples and re-evaluated under attack conditions.
The project generates:
- Clean accuracy metrics
- FGSM robustness metrics
- PGD robustness metrics
- Robustness comparison figures
- Experiment reports
- Reproducible result files
- Evaluate on real-world audio datasets
- Test transfer attacks
- Compare additional adversarial training methods
- Evaluate voice-cloning detection systems
- Add certified robustness approaches