A Modular, Extensible Framework for Deepfake Audio Detection (ASV Spoofing)
Project description
What is DeepFense?
DeepFense lets you build deepfake audio detectors by combining frontends (pretrained feature extractors), backends (classifiers), and loss functions -- all defined in a single YAML config. No code changes needed to run new experiments.
Raw Audio --> Frontend (Wav2Vec2, WavLM, HuBERT, ...) --> Backend (AASIST, MLP, ...) --> Loss --> Score
Install
conda create -n deepfense python=3.10
conda activate deepfense
pip install deepfense
Or install from source (for development):
conda create -n deepfense python=3.10
conda activate deepfense
git clone https://github.com/Yaselley/deepfense-framework
cd deepfense-framework
pip install -e .
Quick Start
1. Generate dummy test data
python tests/create_samples.py
2. Train
python train.py --config deepfense/config/train.yaml
3. Test
python test.py \
--config deepfense/config/train.yaml \
--checkpoint outputs/Wav2Vec2_Nes2Net_Example_*/best_model.pth
4. Multi-GPU Training
DeepFense supports multi-GPU training out of the box via PyTorch DDP. Just use torchrun:
# 2 GPUs on a single node
torchrun --nproc_per_node=2 train.py --config deepfense/config/train.yaml
# 4 GPUs
torchrun --nproc_per_node=4 train.py --config deepfense/config/train.yaml
No config changes required -- DDP is detected automatically. Checkpoints, logs, and evaluation run on rank 0 only. The saved checkpoints are identical to single-GPU ones and can be loaded without any DDP-specific handling.
5. Use real data
Create a Parquet file with columns ID, path, label ("bonafide" / "spoof"), then update the config:
data:
train:
parquet_files: ["/path/to/train.parquet"]
val:
parquet_files: ["/path/to/val.parquet"]
How Configuration Works
Everything is controlled by a single YAML file. Here is the anatomy:
# ---------- experiment ----------
exp_name: "my_experiment"
output_dir: "./outputs/"
seed: 42
# ---------- data ----------
data:
sampling_rate: 16000
label_map: {"bonafide": 1, "spoof": 0}
train:
parquet_files: ["train.parquet"]
batch_size: 32
base_transform:
- type: "pad"
max_len: 64600 # ~4 sec at 16 kHz
augment_transform: # training only
- type: "rawboost"
noise_ratio: 0.4
val:
parquet_files: ["val.parquet"]
batch_size: 64
base_transform:
- type: "pad"
max_len: 64600
# ---------- model ----------
model:
type: "StandardDetector"
frontend:
type: "wav2vec2" # or wavlm, hubert, mert, eat
args:
source: "huggingface" # or "fairseq" for local .pt files
ckpt_path: "facebook/wav2vec2-xls-r-300m"
freeze: True
backend:
type: "AASIST" # or MLP, Nes2Net, ECAPA_TDNN, RawNet2
args:
input_dim: 1024 # must match frontend output dim
loss:
- type: "OCSoftmax" # or CrossEntropy, AMSoftmax, ASoftmax
weight: 1.0
embedding_dim: 32 # must match backend output dim
# ---------- training ----------
training:
epochs: 50
device: "cuda"
optimizer:
type: "adam"
lr: 0.0001
scheduler:
type: "cosine_annealing"
T_max: 50
monitor_metric: "EER"
monitor_mode: "min"
metrics:
EER: {}
ACC: {}
minDCF: {Pspoof: 0.05}
See the Full Tutorial for a detailed walkthrough of every parameter.
Available Components
| Category | Options |
|---|---|
| Frontends | Wav2Vec2, WavLM, HuBERT, MERT, EAT |
| Backends | AASIST, ECAPA-TDNN, Nes2Net, RawNet2, MLP, TCM |
| Losses | CrossEntropy, OC-Softmax, AM-Softmax, A-Softmax |
| Augmentations | RawBoost, RIR, Codec, AdditiveNoise, SpeedPerturb, AddBabble, DropChunk, DropFreq |
| Metrics | EER, minDCF, actDCF, ACC, F1 |
List them from the CLI:
deepfense list
deepfense list --component-type backends
Pretrained Models & Datasets (HuggingFace Hub)
DeepFense publishes 455+ pretrained models and 12 datasets at huggingface.co/DeepFense.
# See what's available
deepfense download list-datasets
deepfense download list-models --filter WavLM
# Download a dataset (parquet files)
deepfense download dataset CompSpoof
# Download a pretrained model (checkpoint + config)
deepfense download model ASV19_WavLM_Nes2Net_NoAug_Seed42
# Test the downloaded model
python test.py \
--config models/ASV19_WavLM_Nes2Net_NoAug_Seed42/config.yaml \
--checkpoint models/ASV19_WavLM_Nes2Net_NoAug_Seed42/best_model.pth
Or in Python:
from deepfense.hub import download_dataset, download_model
parquets = download_dataset("CompSpoof") # returns list of local paths
files = download_model("ASV19_WavLM_Nes2Net_NoAug_Seed42") # returns {"checkpoint": ..., "config": ...}
See the HuggingFace Hub Guide for full workflows (training, evaluation, inference).
Adding Your Own Component
Every component type follows the same pattern:
- Create a file (e.g.
deepfense/models/backends/my_backend.py) - Decorate with the registry:
from deepfense.utils.registry import register_backend from deepfense.models.base_model import BaseBackend @register_backend("MyBackend") class MyBackend(BaseBackend): def __init__(self, config): super().__init__() # ... def forward(self, x): # ...
- Import it in the package
__init__.py - Use it in your config:
backend: type: "MyBackend" args: { ... }
The same pattern applies to frontends, losses, augmentations, datasets, optimizers, and metrics. See the user guides for detailed walkthroughs.
Project Structure
deepfense/
├── cli/ # CLI commands (train, test, list)
├── config/ # YAML configs + parquet generators
├── data/ # Dataset loading + transforms/augmentations
├── models/
│ ├── frontends/ # Wav2Vec2, WavLM, HuBERT, MERT, EAT
│ ├── backends/ # AASIST, ECAPA-TDNN, Nes2Net, MLP, ...
│ ├── losses/ # OC-Softmax, AM-Softmax, CrossEntropy, ...
│ └── modules/ # Shared layers (pooling, conformer, fairseq_local)
├── training/ # Trainer, evaluator, metrics, seed
└── utils/ # Registry, visualization
Documentation
| Guide | Description |
|---|---|
| Installation | Setup instructions |
| Quick Start | First model in 5 minutes |
| Full Tutorial | Every config option explained |
| Architecture | How DeepFense works internally |
| Configuration Reference | All YAML parameters |
| Library Usage | Use DeepFense as a Python library |
| HuggingFace Hub | Download datasets & pretrained models |
| CLI Reference | CLI commands |
| Components | Frontend, backend, loss, augmentation reference |
| User Guides | Adding custom components, training workflows |
Citation
@software{deepfense2025,
title={DeepFense: A Modular Framework for Deepfake Audio Detection},
author={DeepFense Team},
year={2025},
url={https://github.com/Yaselley/deepfense-framework}
}
License
Apache 2.0 -- see LICENSE for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deepfense-0.2.2.tar.gz.
File metadata
- Download URL: deepfense-0.2.2.tar.gz
- Upload date:
- Size: 154.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63af86a7d7c2926e511149d3bf3e3153cfb8914a0e2438c019b8a1c43d6986cc
|
|
| MD5 |
54e340aa50c89ccdfddff33f09f136fa
|
|
| BLAKE2b-256 |
55423dbe5b3303ac2d9cb90410c02bb0fa848b8fbe44e6e6252cd273ffb83367
|
File details
Details for the file deepfense-0.2.2-py3-none-any.whl.
File metadata
- Download URL: deepfense-0.2.2-py3-none-any.whl
- Upload date:
- Size: 242.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a2621bf1d49c22e4e21afd0f49ac6e336b100e1c6b0d03fbdaa19b66d33d725
|
|
| MD5 |
69e1dc46935b79df627d15d92aa79daf
|
|
| BLAKE2b-256 |
efeb0d355ddaa3eb5cd5102a0aa1cbf27114f3ce352d4e151c4cbadea11e8eb1
|