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.
- 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
safetensorsmodel is bundled right within the repository.
Ensure you have Python installed. You can install all necessary dependencies using pip:
pip install opencv-python mtcnn transformers pillow torch torchvision numpyBecause 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- Place an image you want to test in the project directory (e.g.,
test_image.jpg). - Update the
target_imagevariable at the bottom ofdeepfakedetector.pyto point to your image's filename. - Run the script:
python deepfakedetector.py
- The script will initialize the detector and model.
- It will export a
debug_cropped_face.jpgso 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%)
- 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 standardgit clonemight only download the LFS pointer file instead of the actual 340MB model file.