Skip to content

ameencaslam/deepfake-detection-project-v4

Repository files navigation

🌟Deep Learning Approaches for Deepfake Detection🌟

A powerful and comprehensive deepfake detection system implementing multiple deep learning architectures, all packed into a user-friendly web interface! πŸš€

🌐 Live Web Application: Deepfake Detection Web App


πŸ” Project Overview

This project integrates cutting-edge deep learning architectures to detect deepfakes:

  • πŸ€– Xception
  • ⚑ EfficientNet
  • πŸŒ€ Swin Transformer
  • πŸ”— Cross Attention
  • 🧠 CNN-Transformer

Each model is independently trained but seamlessly combined in the web app for ensemble predictions.


Web App Screenshot

Example of the interactive web app interface


Ensemble Prediction UI

Results from multiple models displayed together


Image Analysis Example

Image mode with face detection visualization


Video Analysis Example

Video mode displaying prediction results


Cropped Faces Example

Cropped face samples from video


πŸ“œ License

This project is licensed under the Apache License 2.0. You are free to use, modify, and distribute the code, provided that the following conditions are met:

  1. Attribution: Proper credit must be given to the original authors, along with a copy of the license.
  2. State of Derivative Works: Any modifications or derivative works must be clearly identified as such.
  3. No Liability: The software is provided "as is," without any warranties or guarantees. The authors are not liable for any damages arising from its use.

For full terms and conditions, refer to the official LICENSE.md file.


πŸ“Š Dataset

The project utilizes a balanced dataset of 20,000 face-cropped images:

  • 🟒 10,000 Real Images
  • πŸ”΄ 10,000 Fake Images
  • πŸ“š Sourced from DFDC, FF++, and CelebDF-v2

πŸ“₯ Dataset Link: 3body-filtered-v2-10k


πŸ› οΈ Training the Models

πŸ“‹ Prerequisites

  • A Kaggle account with GPU access
  • Add the dataset to your Kaggle account

πŸ”§ Training Steps

  1. Use the provided train_*.py files in Kaggle notebooks
  2. Each model has a unique training configuration
  3. General training parameters:
    NUM_EPOCHS = 30  # Default
    BATCH_SIZE = 32  
    IMAGE_SIZE = 224  # Varies by model
  4. Key configurations:
    • Optimizer: AdamW with weight decay
    • Scheduler: ReduceLROnPlateau
    • Experiment tracking: MLflow integration

πŸ”„ Model Conversion

Models are converted for CPU compatibility:


🌐 Web Application Setup

βš™οΈ Environment Setup

  1. Create a virtual environment:
    python -m venv venv  
    source venv/bin/activate  # Linux/Mac  
    venv\Scripts\activate     # Windows  
  2. Install dependencies:
    pip install -r requirements.txt  

πŸ“‚ Application Structure

deepfake-detection-project-v4/  
β”œβ”€β”€ app.py                   # Main Streamlit app  
β”œβ”€β”€ video_processor.py       # Video utilities  
β”œβ”€β”€ feature_visualization.py # Visualize CNN features  
β”œβ”€β”€ data_handler.py          # Data processing  
β”œβ”€β”€ train_*.py               # Training scripts  
└── converted_models/        # Directory for pre-trained models  

▢️ Run the Application

  1. Add converted models to the converted_models/ folder
  2. Start the app:
    streamlit run app.py  

πŸ–₯️ Using the Web Application

πŸ–ΌοΈ Image Analysis

  • Upload an image containing a face
  • View:
    • πŸ“Έ Face detection visualization
    • πŸ“Š Predictions from each model
    • 🧠 Feature maps (CNN models only)

πŸŽ₯ Video Analysis

  • Upload a video file
  • Choose the number of frames to analyze (10–300)
  • View:
    • πŸ” Frame-by-frame predictions
    • πŸ˜ƒ Detected faces
    • πŸ“ˆ Confidence scores and stats

πŸ’‘ Features

  • πŸ”— Multi-model ensemble predictions
  • πŸ•΅οΈβ€β™‚οΈ Real-time face detection
  • πŸ–ΌοΈ Feature map visualization
  • πŸ“Š Confidence tracking
  • πŸŒ‘ Dark theme UI

πŸ—οΈ Model Architecture Details

Xception πŸ€–

  • Specialized in texture analysis
  • Input size: 299x299

EfficientNet ⚑

  • B3 variant: Efficiency-accuracy balance
  • Input size: 300x300

Swin Transformer πŸŒ€

  • Hierarchical feature learning
  • Input size: 224x224

Cross Attention πŸ”—

  • Focuses on enhanced feature interaction
  • Input size: 224x224

CNN-Transformer 🧠

  • Hybrid model: Combines local & global feature learning
  • Input size: 224x224

πŸ“‹ Requirements

  • Python 3.8+
  • CUDA-compatible GPU (for training)
  • CPU with 8GB+ RAM (for inference)

πŸ“ Notes

  • ⚠️ Models must be converted before use in the web app
  • πŸ–ΌοΈ Feature visualization is limited to CNN-based models
  • ⏳ Video processing speed depends on frame count