Skip to content

About

🎭 Binary Deepfake Detection comparing a Custom CNN from scratch against a pre-trained ResNet-50 on Kaggle facial datasets.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

4 Commits

Folders and files

Repository files navigation

🎭 Deepfake Detection: Custom CNN vs. ResNet-50

A comparative deep learning study for binary facial deepfake classification (Real vs. Fake) using both a custom convolutional neural network and transfer learning.

Python PyTorch Kaggle License


πŸ“Œ Overview

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:

  1. Custom CNN: A lightweight convolutional architecture designed and trained from scratch.
  2. ResNet-50 (Transfer Learning): A deep residual backbone with pre-trained ImageNet weights, fine-tuned for facial artifact recognition.

🧠 Model Architectures

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

πŸ“ Repository Structure

β”œβ”€β”€ 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

βš™οΈ Setup & Installation

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.txt

πŸ“₯ Dataset Preparation

The training and evaluation pipeline uses image references indexed in FINAL_DATASET.csv.

Before starting training, download the dataset images locally:

python download_dataset.py

Images will be fetched and organized into ./data/images/.


πŸš€ Model Training

The training script automatically resizes incoming images to 224x224 and includes an integrated Early Stopping mechanism to prevent overfitting.

1. Train the Custom CNN (Default)

python main.py --backbone custom --batch_size 64 --lr 0.001

2. Train the ResNet-50

python 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 16 or --batch_size 8.

Custom Training Arguments

python main.py --backbone resnet50 --epochs 100 --batch_size 32

πŸ§ͺ Testing & Evaluation

To 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 --test

πŸ“Š Plotting Results & Confusion Matrices

Once training and evaluation are complete, generate performance curves (Loss/Accuracy) and Confusion Matrices:

python plot.py

All resulting plots (.png) and performance summaries are exported directly to ./checkpoints/.


πŸ‘€ Author

About

🎭 Binary Deepfake Detection comparing a Custom CNN from scratch against a pre-trained ResNet-50 on Kaggle facial datasets.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages