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.
- 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
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements_new.txtDM-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
python train_new.pyThe 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
python evaluate.py --checkpoint checkpoints/best_model.pthThe 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
All configurable parameters live in src/config.py. The defaults preserve the original project settings and automatically create required output directories.
- Use
main_new.pyfor a simple CLI:python main_new.py --mode train - Pass
--checkpointtomain_new.py --mode evalto evaluate a specific model - Set
use_numpy=Trueinsrc/data/dataloaders.build_dataloaders()if you want to load.npydata
This project follows the original repository license.