DeepGuard AI β€” EfficientNet-B4 Deepfake Detector

DeepGuard AI is a binary deepfake detection model fine-tuned on a custom face-swap dataset using EfficientNet-B4. It detects AI-generated face swaps (inswapper, SimSwap, DeepFaceLab, StyleGAN2) and provides GradCAM explainability heatmaps to highlight suspicious facial regions.

This repository also contains inswapper_128.onnx (InsightFace) used for adversarial face-swap generation in the research pipeline.


Model Files

File Size Description
efficientnet_b4_deepguard.pth 74.9 MB v1 checkpoint β€” EfficientNet-B4 binary classifier
efficientnet_b4_deepguard_v2.pth 74.9 MB v2 checkpoint (recommended) β€” fine-tuned on extended dataset
inswapper_128.onnx 554 MB InsightFace face-swap model for generation pipeline

Performance (v2 β€” Validation Set)

Metric Value
Accuracy 91.54%
Precision 91.73%
Recall 91.38%
F1 Score 0.9156
AUC-ROC 0.9486
False Positive Rate 1.27%

Cross-Method Benchmark

Method Accuracy AUC
StyleGAN2 94.8% 0.9820
inswapper_128 91.5% 0.9486
FaceSwap 89.3% 0.9380
DeepFaceLab 85.1% 0.9210
Stable Diffusion 78.4% 0.8940

Training Configuration

Parameter Value
Base model EfficientNet-B4 (timm)
Pre-training ImageNet-21k
Input size 380 Γ— 380
Training images 10,852
Optimizer AdamW (lr = 3e-5)
Scheduler Cosine annealing
Batch size 16
Epochs 8 (early-stop patience 3)
Augmentation Flip, Rotate, Color jitter
Loss Binary cross-entropy

Usage

import torch
import timm
from PIL import Image
import torchvision.transforms as T

# Load model
class DeepfakeDetector(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.backbone = timm.create_model("efficientnet_b4", pretrained=False, num_classes=0)
        self.head = torch.nn.Linear(self.backbone.num_features, 1)
    def forward(self, x):
        return self.head(self.backbone(x)).squeeze(-1)

model = DeepfakeDetector()
ckpt = torch.load("efficientnet_b4_deepguard_v2.pth", map_location="cpu")
model.load_state_dict(ckpt)
model.eval()

# Preprocess
transform = T.Compose([
    T.Resize((380, 380)),
    T.ToTensor(),
    T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])

img = Image.open("face.jpg").convert("RGB")
tensor = transform(img).unsqueeze(0)

with torch.no_grad():
    prob = torch.sigmoid(model(tensor)).item()

label = "FAKE" if prob > 0.5 else "REAL"
confidence = prob * 100 if label == "FAKE" else (1 - prob) * 100
print(f"{label} β€” {confidence:.1f}% confidence")

GradCAM Explainability

The model supports GradCAM heatmaps via hooks on model.backbone.blocks[-1] (the last MBConv block). Heatmaps highlight facial boundary regions, eye areas, and texture inconsistencies β€” the typical artifacts of face-swap deepfakes.

See the DeepGuard AI backend for the full GradCAM implementation.


Live Demo

Resource Link
Web App deep-guard-xai.vercel.app
API Backend HuggingFace Space
Source Code GitHub

Ethical Use

This model is developed for academic and research purposes only. It is intended to advance deepfake detection research, not to enable misuse. Non-consensual face swapping is strictly prohibited.


Citation

@misc{deepguard2026,
  title   = {DeepGuard AI: Explainable Deepfake Detection with EfficientNet-B4 and GradCAM},
  author  = {Arshad, Sowaiba},
  year    = {2026},
  url     = {https://huggingface.co/Sowaiba01/deepguard-ai}
}

License: MIT Β·

Downloads last month
16,394
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for Sowaiba01/deepguard-ai

Quantized
(1)
this model

Space using Sowaiba01/deepguard-ai 1