Muhammad Ahmad Faizan
Back to Portfolio
AI

Deepfake Detection System

ConvNeXt-Tiny based 6-class deepfake classifier deployed on Hugging Face Spaces via Docker.

PythonPyTorchConvNeXtHugging FaceDockerGradio

Overview

Built a deepfake detection system using a ConvNeXt-Tiny architecture fine-tuned for 6-way classification across real and AI-generated face categories. The model is containerized with Docker and deployed on Hugging Face Spaces with a Gradio inference interface.

Business Problem

Synthetic media generation has outpaced detection capabilities. Organizations need reliable tools to distinguish real photographs from AI-generated images across multiple generation methods (GANs, diffusion models, etc.).

Solution

Fine-tuned a ConvNeXt-Tiny model on a curated dataset spanning 6 classes: real faces and 5 types of AI-generated faces. Applied aggressive data augmentation to improve generalization. Containerized the full inference pipeline with Docker for reproducible deployment on Hugging Face Spaces.

Architecture

Deepfake Detection — Pipeline Input Image Preprocessing ConvNeXt-Tiny Fine-tuned 6-Class Deployment: Docker → Hugging Face Spaces Gradio Inference Interface

Key Features

  • 6-class classification: Real vs. GAN, Diffusion, VAE, StyleGAN, and Other synthetic
  • ConvNeXt-Tiny architecture optimized for inference speed
  • Docker containerized for reproducible deployment
  • Gradio web interface for easy image upload and classification
  • Data augmentation pipeline with random crops, flips, and color jitter

Gallery

Landing page that shows detailed information about the Deepfake Detection System project, including overview, architecture, and key features.

Landing page that shows detailed information about the Deepfake Detection System project, including overview, architecture, and key features.

Upload interface for submitting videos for deepfake detection

Upload interface for submitting videos for deepfake detection

Prediction results showing the classification of the uploaded video along with confidence scores

Prediction results showing the classification of the uploaded video along with confidence scores

Grad-CAM visualization for explaining deepfake detection decisions

Grad-CAM visualization for explaining deepfake detection decisions

Tech Stack

PythonPyTorchConvNeXt-TinyHugging Face TransformersDockerGradioAlbumentations

Engineering Challenges

Cross-Generator Generalization

Models trained on one generation method (e.g., GANs) don't generalize to others (e.g., diffusion). Augmented the training set with images from 5 distinct generation methods and used aggressive augmentation to prevent method-specific overfitting.

Model Size vs. Inference Speed

Larger models achieve better accuracy but are too slow for real-time use. ConvNeXt-Tiny provided the best accuracy-to-latency trade-off, achieving 94% validation accuracy with sub-100ms inference on CPU.

Docker Container Size

PyTorch-based containers are large. Optimized the Docker image using multi-stage builds and PyTorch CPU-only slim images to reduce container size from 3.2GB to 850MB.

Lessons Learned

  • Deepfake detection models must be trained on diverse generation methods to generalize in the wild
  • Model distillation can further improve inference speed without significant accuracy loss
  • Containerized deployment ensures reproducibility across environments

Results

The model achieves 94% validation accuracy across all 6 classes with sub-100ms CPU inference time. Deployed on Hugging Face Spaces with Docker, serving 50+ daily inference requests.

Let's Build Something Similar

Have a project in mind? Let's discuss how we can architect and build it together.

Discuss Your Project