A comparative deep learning study for binary facial deepfake classification (Real vs. Fake) using both a custom convolutional neural network and transfer learning.
This project addresses the problem of Facial Deepfake Detection by formulating it as a supervised binary classification task (REAL vs. FAKE).
The goal is to benchmark two distinct architectural approaches on the same Kaggle facial dataset:
- Custom CNN: A lightweight convolutional architecture designed and trained from scratch.
- ResNet-50 (Transfer Learning): A deep residual backbone with pre-trained ImageNet weights, fine-tuned for facial artifact recognition.
| Feature | Custom CNN | ResNet-50 |
|---|---|---|
| Approach | Trained from scratch | Pre-trained Transfer Learning |
| Input Resolution | 224 Γ 224 px | 224 Γ 224 px |
| Recommended Learning Rate | 0.001 |
0.0001 |
| Recommended Batch Size | 64 |
32 (or 16 / 8 for lower VRAM) |
| Regularization | Early Stopping | Early Stopping & Pretrained Weights |
βββ backbones/ # Backbone model definitions (ResNet-50, etc.)
βββ utils/ # Dataset loaders, metrics & helper utilities
βββ FINAL_DATASET.csv # Dataset annotations with image URLs and labels
βββ download_dataset.py # Automated script to fetch images locally
βββ main.py # CLI entry point for training and evaluation
βββ net.py # Custom CNN network architecture
βββ solver.py # Training loop, validation, and early stopping logic
βββ plot.py # Generates Loss/Accuracy curves & Confusion Matrices
βββ requirements.txt # Python package dependencies
βββ README.md
It is strongly recommended to use a virtual environment to manage dependencies:
# 1. Clone the repository
git clone https://github.com/BillyErMago/deepfake-deeplearning.git
cd deepfake-deeplearning
# 2. Create and activate a virtual environment
python -m venv venv
# On Linux / macOS:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
# 3. Install required packages
pip install -r requirements.txtThe training and evaluation pipeline uses image references indexed in FINAL_DATASET.csv.
Before starting training, download the dataset images locally:
python download_dataset.pyImages will be fetched and organized into ./data/images/.
The training script automatically resizes incoming images to 224x224 and includes an integrated Early Stopping mechanism to prevent overfitting.
python main.py --backbone custom --batch_size 64 --lr 0.001python main.py --backbone resnet50 --batch_size 32 --lr 0.0001π‘ GPU / VRAM Tip: If you encounter a CUDA
Out of Memory(OOM) error when training ResNet-50, lower the batch size using--batch_size 16or--batch_size 8.
python main.py --backbone resnet50 --epochs 100 --batch_size 32To evaluate a trained checkpoint on the test set and output test metrics, use the --test flag. The script retrieves the best weights from the ./checkpoints/ directory:
# Evaluate Custom CNN
python main.py --backbone custom --test
# Evaluate ResNet-50
python main.py --backbone resnet50 --testOnce training and evaluation are complete, generate performance curves (Loss/Accuracy) and Confusion Matrices:
python plot.pyAll resulting plots (.png) and performance summaries are exported directly to ./checkpoints/.
- BillyErMago - GitHub Profile