Skip to content

Yaselley/deepfense-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DeepFense Logo

DeepFense Framework

A Modular, Extensible Framework for Deepfake Audio Detection

Website HuggingFace Documentation Recipes

License Python PyTorch


What is DeepFense?

DeepFense is a modular framework for building and training deepfake audio detection models. It provides a plug-and-play architecture where you can easily combine different Frontends (feature extractors), Backends (classifiers), and Loss Functions to create state-of-the-art detection systems.

Key Features

  • πŸ”„ Modular Architecture β€” Swap components with a single config change
  • βš™οΈ Configuration-Driven β€” All experiments defined in YAML
  • πŸŽ›οΈ Advanced Augmentations β€” RawBoost, RIR, Codec, Noise, and more
  • πŸ“Š Built-in Metrics β€” EER, minDCF, F1-score, Accuracy
  • πŸš€ Simple CLI β€” Train and test models with command-line interface
  • πŸ“š Recipes β€” Pre-configured training setups and example models (see recipes)

New to DeepFense? Check out our recipes for pre-configured training setups and example models to get started quickly!


Table of Contents

  1. Installation
  2. Understanding DeepFense Architecture
  3. Available Components
  4. Training Models
  5. Evaluating and Testing Models
  6. Data Preparation
  7. Extending DeepFense
  8. Using the CLI (Alternative)
  9. Complete Pipeline Flow
  10. Documentation

Installation

# From source (recommended for development)
git clone https://github.com/Yaselley/deepfense-framework
cd deepfense-framework
pip install -e .

# Or From PyPI 
pip install deepfense

See Installation Guide for detailed instructions.


Understanding DeepFense Architecture

DeepFense uses a modular pipeline architecture:

Raw Audio β†’ Frontend β†’ Features β†’ Backend β†’ Embeddings β†’ Loss β†’ Scores

Key Components:

  • Frontend: Extracts features from audio (Wav2Vec2, WavLM, HuBERT, etc.)
  • Backend: Processes features into embeddings (AASIST, ECAPA-TDNN, MLP, etc.)
  • Loss Function: Computes loss and scores (CrossEntropy, OC-Softmax, etc.)

See Architecture Overview for detailed architecture explanation, or Pipeline Flow for complete pipeline walkthrough.


Available Components

DeepFense provides a modular set of components that can be mixed and matched:

See Component Reference for complete details.

Looking for example configurations? Check out our recipes for pre-configured training setups and trained models.


Training Models

Train models using Python scripts:

python train.py --config deepfense/config/train.yaml

Training creates an experiment directory with checkpoints, logs, and metrics.

Alternative: You can also use the CLI (see Using the CLI section below).

See Quick Start Guide for detailed instructions and Configuration Reference for all YAML parameters.


Evaluating and Testing Models

Test a trained model using Python scripts:

python test.py \
    --config deepfense/config/train.yaml \
    --checkpoint outputs/my_experiment/best_model.pth

DeepFense computes metrics automatically (EER, minDCF, F1, ACC) and saves results to the experiment directory.

Alternative: You can also use the CLI (see Using the CLI section below).

See Evaluation & Inference Guide for details.


Data Preparation

DeepFense uses Parquet files for dataset metadata. Each parquet file should contain:

  • ID: Unique identifier
  • path: Path to audio file
  • label: Label string ("bonafide" or "spoof")
  • dataset_name: (Optional) Dataset identifier

Example:

import pandas as pd
data = pd.DataFrame({
    "ID": ["sample_001", "sample_002"],
    "path": ["/path/to/audio1.flac", "/path/to/audio2.flac"],
    "label": ["bonafide", "spoof"]
})
data.to_parquet("train.parquet")

Data Transforms, Padding, and Cropping

DeepFense applies transforms in two stages:

  1. Base Transforms (always): Padding, cropping, resampling
  2. Augmentations (training only): RawBoost, RIR, Noise, etc.

Critical: All audio must be padded/cropped to the same length for batching. Configure this in your YAML:

data:
  train:
    base_transform:
      - type: "pad"
        args:
          max_len: 160000       # 10 seconds @ 16kHz
          random_pad: True      # Random crop if longer
          pad_type: "repeat"    # Repeat if shorteror

See Data Transforms Guide for complete transform parameters, padding/cropping options, augmentations, and how to check/modify configurations.


Extending DeepFense

DeepFense makes it easy to add custom components using the registry pattern. Each component type has a detailed guide:

See Extending DeepFense (Quick Reference) for a quick overview of all component types.


Using the CLI (Alternative)

DeepFense provides a CLI as an alternative to Python scripts. The CLI supports:

# Train a model (alternative to python train.py)
deepfense train --config config/train.yaml

# Test a model (alternative to python test.py)
deepfense test --config config/train.yaml --checkpoint outputs/exp/best_model.pth

# List available components
deepfense list

Note: The CLI currently supports training and testing existing models with different parameters. Future versions will support adding components via CLI.

See CLI Reference for complete documentation.


Complete Pipeline Flow

The DeepFense pipeline: Data β†’ Transforms β†’ Frontend β†’ Backend β†’ Loss β†’ Training β†’ Evaluation

See Pipeline Flow Documentation for the complete detailed pipeline with all stages, data shapes, and configuration flow.


Documentation

Getting Started

Guide Description
Installation Full installation instructions
Quick Start Train your first model in 5 minutes
Full Tutorial Complete config-driven training guide
Architecture How DeepFense works internally

Component Reference

Component Documentation
Frontends Wav2Vec2, WavLM, HuBERT, MERT, EAT
Backends AASIST, ECAPA_TDNN, RawNet2, MLP, Pool, Nes2Net, TCM
Losses CrossEntropy, OC-Softmax, AM-Softmax, A-Softmax
Augmentations RawBoost, RIR, Codec, Noise, SpeedPerturb
Optimizers & Schedulers Adam, SGD, CosineAnnealing, StepLR

User Guides

Guide Description
Training with CLI How to train models using the CLI
Training Workflow Detailed training loop explanation
Evaluation & Inference Testing and deployment
Configuration Reference All YAML parameters explained
Library Usage Use DeepFense programmatically in Python

Extending DeepFense

Guide Description
Adding a New Backend Step-by-step guide to create custom backends
Adding a New Frontend Step-by-step guide to create custom frontends
Adding a New Loss Step-by-step guide to create custom loss functions
Adding a New Dataset Step-by-step guide to create custom datasets
Adding Augmentations Step-by-step guide to create custom data augmentations
Adding Optimizers Step-by-step guide to add custom optimizers
Adding Metrics Step-by-step guide to add custom evaluation metrics
Adding Schedulers Step-by-step guide to add custom learning rate schedulers
Extending DeepFense (Quick Reference) Quick reference for all component types

CLI Reference

Guide Description
CLI Reference Complete CLI documentation

Recipes

Resource Description
Recipes Pre-configured training setups and example models

Project Structure

deepfense/
β”œβ”€β”€ config/          # YAML configurations
β”œβ”€β”€ data/            # Data handling & transforms
β”œβ”€β”€ models/          # Frontends, backends, losses
β”œβ”€β”€ training/        # Training loop & evaluation
β”œβ”€β”€ utils/           # Registry & helpers
└── cli/             # Command-line interface

See Architecture Overview for detailed structure and component organization.


Recipes

DeepFense provides example recipes (pre-configured training setups) to help you get started quickly. Each recipe includes:

  • Complete configuration files
  • Pre-trained model checkpoints (where available)
  • Training scripts and evaluation results
  • Documentation on architecture choices and hyperparameters

See the recipes folder for available recipes. Each recipe includes detailed README files explaining the configuration and how to reproduce the results.


Contributing

We welcome contributions! See Extending DeepFense for guidelines on adding new components.


License

Apache 2.0 β€” see LICENSE for details.


Citation

If you use DeepFense in your research, please cite:

@software{deepfense2024,
  title={DeepFense: A Modular Framework for Deepfake Audio Detection},
  author={DeepFense Team},
  year={2024},
  url={https://github.com/Yaselley/deepfense-framework}
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •