Skip to content

Pranavkalkur/deep-fake-detector

Repository files navigation

Deep Fake Detector

A powerful, standalone Python-based deepfake detection tool. This project uses MTCNN to automatically detect and crop human faces from an input image, and then analyzes the cropped face using a fine-tuned Vision Transformer (ViT) model to classify it as either "Realism" or "Deepfake".

The fine-tuned classification model is included directly within this repository, making it fully self-contained and easy to deploy.

Features

  • Automatic Face Detection: Uses MTCNN to locate the most prominent face in an image.
  • Artifact Preservation: Adds a margin when cropping the face to ensure Deepfake artifacts common around the jawline or forehead are kept intact to ensure accurate classification.
  • Deepfake Classification: Evaluates the cropped face using a custom Vision Transformer model for highly accurate, real-time binary classification.
  • Self-Contained: No need to download external models manually; the safetensors model is bundled right within the repository.

Requirements and Installation

Ensure you have Python installed. You can install all necessary dependencies using pip:

pip install opencv-python mtcnn transformers pillow torch torchvision numpy

Because the repository contains large model files, ensure you have Git LFS (Large File Storage) installed when cloning this repository, otherwise the model files will not download correctly:

git lfs install
git clone https://github.com/Pranavkalkur/deep-fake-detector.git

Usage

  1. Place an image you want to test in the project directory (e.g., test_image.jpg).
  2. Update the target_image variable at the bottom of deepfakedetector.py to point to your image's filename.
  3. Run the script:
    python deepfakedetector.py

Output

  • The script will initialize the detector and model.
  • It will export a debug_cropped_face.jpg so you can verify the exact crop passed to the ViT model.
  • Finally, it outputs the classification result with a confidence probability: FINAL PREDICTION: DEEPFAKE (Confidence: 99.12%)

Troubleshooting

  • No face detected: MTCNN might fail if the input image is too blurry, too small, or poorly lit. Ensure your image has a clear, prominent human face.
  • Model Loading Errors: If you experience errors loading the model.safetensors, ensure you cloned the repository using Git LFS, as a standard git clone might only download the LFS pointer file instead of the actual 340MB model file.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors