Skip to content

nahmahn/Deepfake_detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deepfake Detection

This project is a deep learning pipeline for detecting deepfake videos using PyTorch. It includes preprocessing, training, and evaluation scripts, and leverages a ResNeXt backbone with LSTM for temporal modeling.
Dataset Link
Download the .pth file for the Model4 from here
Project Documentation

Features

  • Face extraction and super-resolution preprocessing
  • Custom PyTorch dataset and dataloader
  • ResNeXt50 backbone with LSTM for sequence modeling
  • Training with early stopping and backbone fine-tuning
  • Evaluation with ROC, F1, and confusion matrix visualization

Directory Structure

DeepfakeModelv4/
├──ERSGAN/(git clone)
├──deepfake_dataset
├──data
   ├──faces
      ├──test
      ├──train
├── best_model.pth         # Trained model weights
├── dataset.py             # Custom dataset class
├── eval.py                # Evaluation script
├── model.py               # Model definition
├── preprocess.py          # Preprocessing (face extraction, super-resolution)
├── train.py               # Training script          
└── __init__.py            # Package marker

Requirements

  • Python 3.7+
  • PyTorch
  • torchvision
  • scikit-learn
  • tqdm
  • numpy
  • opencv-python
  • pillow
  • facenet-pytorch
  • seaborn
  • matplotlib

You may install dependencies with:

pip install torch torchvision scikit-learn tqdm numpy opencv-python pillow facenet-pytorch seaborn matplotlib

Data Preparation

  1. Place your raw videos in deepfake_dataset/train/real, deepfake_dataset/train/fake, deepfake_dataset/test/real, and deepfake_dataset/test/fake.
  2. Run the preprocessing script to extract faces and apply super-resolution:
    python preprocess.py
    This will create processed frames in data/faces/train and data/faces/test.

Training

Train the model using:

python train.py

The best model will be saved as best_model.pth.

Evaluation

Evaluate the trained model:

python eval.py

This will print metrics and show confusion matrix and ROC curve plots.

These are the comparison with other model architectures trained on the same dataset

Screenshot 2025-05-28 011025

Notes

  • The preprocessing script uses ESRGAN for super-resolution. Make sure the ESRGAN model weights and code are available as referenced in preprocess.py.
  • Adjust paths in scripts as needed for your environment.

License

MIT License

About

Deepfake detection pipeline leveraging ESRGAN-enhanced facial frames, spatial feature extraction via ResNeXt50, and temporal modeling with LSTM. Incorporates transfer learning and progressive layer unfreezing for optimized performance.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages