Skip to content

Repository files navigation

DM-Net

DM-Net is a Swin Transformer-based classifier designed to detect deepfake imagery. This repository packages the project into a production-ready structure with clean training and evaluation pipelines while preserving the original data processing and hyperparameters.

🚀 Features

  • Modular source layout under src/
  • FFT-based Swin Tiny classifier mirroring the original architecture
  • Consistent training hyperparameters (batch_size=32, lr=1e-4, epochs=20)
  • ImageFolder and NumPy dataset support
  • Training pipeline with automatic checkpointing and learning rate scheduling
  • Evaluation pipeline generating metrics, confusion matrix, and ROC curve

📦 Installation

python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements_new.txt

📂 Project Structure

DM-Net/
├── datasets/               # Train/val/test splits (ImageFolder or NumPy)
├── models/                 # Saved model checkpoints (.pth)
├── checkpoints/            # Automatically saved training checkpoints
├── results/                # Metrics, confusion matrix, ROC curve
├── logs/                   # (Optional) Training logs
├── src/
│   ├── config.py           # Central configuration
│   ├── data/
│   │   ├── dataloaders.py  # DataLoader factories
│   │   └── datasets.py     # Dataset definitions
│   ├── models/
│   │   └── swin.py         # SwinTinyBinary model
│   └── utils/
│       └── helpers.py      # Utilities (seed, checkpoint, metrics)
├── train_new.py            # Training entrypoint
├── evaluate.py             # Evaluation entrypoint
└── main_new.py             # CLI for train/eval

🏋️ Training

python train_new.py

The script will:

  • Load train/val datasets with the original augmentation (Resize(224) + ToTensor())
  • Train for 20 epochs using AdamW (lr=1e-4)
  • Save the best checkpoint to checkpoints/best_model.pth
  • Record metrics to results/training_metrics.json

✅ Evaluation

python evaluate.py --checkpoint checkpoints/best_model.pth

The evaluation pipeline outputs:

  • Accuracy, precision, recall, F1-score, ROC-AUC
  • Confusion matrix saved to results/confusion_matrix.png
  • ROC curve saved to results/roc_curve.png
  • Metrics file results/evaluation_metrics.json

⚙️ Configuration

All configurable parameters live in src/config.py. The defaults preserve the original project settings and automatically create required output directories.

🧪 Tips

  • Use main_new.py for a simple CLI: python main_new.py --mode train
  • Pass --checkpoint to main_new.py --mode eval to evaluate a specific model
  • Set use_numpy=True in src/data/dataloaders.build_dataloaders() if you want to load .npy data

📄 License

This project follows the original repository license.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages