AdityaManojShinde commited on
Commit
349f738
Β·
verified Β·
1 Parent(s): 5a657bd

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +87 -9
README.md CHANGED
@@ -1,12 +1,90 @@
1
  ---
2
- title: Deepfake Detector App
3
- emoji: πŸŒ–
4
- colorFrom: blue
5
- colorTo: green
6
- sdk: gradio
7
- sdk_version: 6.9.0
8
- app_file: app.py
9
- pinned: false
 
 
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: mit
3
+ tags:
4
+ - deepfake-detection
5
+ - computer-vision
6
+ - transfer-learning
7
+ - hybrid-cnn
8
+ - pytorch
9
+ datasets:
10
+ - xhlulu/140k-real-and-fake-faces
11
+ metrics:
12
+ - accuracy
13
  ---
14
 
15
+ # Deepfake Face Detector
16
+
17
+ A hybrid CNN model for detecting AI-generated (deepfake) face images, built using transfer learning on a dual-stream architecture.
18
+
19
+ ## Model Architecture
20
+
21
+ This model combines two parallel CNN streams:
22
+
23
+ - **Spatial Stream** β€” EfficientNet-B4 pretrained on ImageNet, fine-tuned to detect visible artifacts such as unnatural skin texture, blending edges, and facial inconsistencies
24
+ - **Frequency Stream** β€” Xception backbone with fixed SRM (Steganalysis Rich Model) filters to detect invisible GAN noise fingerprints in pixel residuals
25
+ - **Fusion Module** β€” Both stream outputs are concatenated (1792 + 2048 = 3840 features) and passed through a classification head with Dropout regularization
26
+ - **Output** β€” Sigmoid activation producing a probability score (0 = fake, 1 = real)
27
+
28
+ ## Training Strategy
29
+
30
+ Three-phase transfer learning approach:
31
+
32
+ | Phase | Layers Trained | Learning Rate | Epochs |
33
+ |-------|---------------|---------------|--------|
34
+ | 1 | Classifier head only | 1e-3 | 3 |
35
+ | 2 | Top EfficientNet blocks + classifier | 1e-4 | 3 |
36
+
37
+ ## Dataset
38
+
39
+ Trained and evaluated on [140k Real and Fake Faces](https://www.kaggle.com/datasets/xhlulu/140k-real-and-fake-faces)
40
+
41
+ | Split | Real | Fake | Total |
42
+ |-------|------|------|-------|
43
+ | Train | 50,000 | 50,000 | 100,000 |
44
+ | Valid | 10,000 | 10,000 | 20,000 |
45
+ | Test | 10,000 | 10,000 | 20,000 |
46
+
47
+ Fake images are StyleGAN2-generated faces. Real images are sourced from Flickr-Faces-HQ (FFHQ).
48
+
49
+ ## Performance
50
+
51
+ | Metric | Score |
52
+ |--------|-------|
53
+ | Test Accuracy | 98.59% |
54
+ | Validation Accuracy | 98.55% |
55
+
56
+ ## Usage
57
+ ```python
58
+ import torch
59
+ from torchvision import transforms
60
+ from PIL import Image
61
+
62
+ model = HybridDeepfakeDetector()
63
+ model.load_state_dict(torch.load("deepfake_detector_phase2.pth", map_location="cpu"))
64
+ model.eval()
65
+
66
+ transform = transforms.Compose([
67
+ transforms.Resize((224, 224)),
68
+ transforms.ToTensor(),
69
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
70
+ ])
71
+
72
+ image = Image.open("face.jpg").convert("RGB")
73
+ tensor = transform(image).unsqueeze(0)
74
+
75
+ with torch.no_grad():
76
+ prob = model(tensor).item()
77
+
78
+ label = "REAL" if prob > 0.5 else "FAKE"
79
+ print(f"{label} ({prob*100:.1f}% confidence)")
80
+ ```
81
+
82
+ ## Limitations
83
+
84
+ - Optimized for StyleGAN2 generated faces β€” may perform differently on other GAN architectures
85
+ - Best results on frontal face images
86
+ - Not tested on video deepfakes
87
+
88
+ ## Try It
89
+
90
+ Live demo available at [Hugging Face Spaces](https://huggingface.co/spaces/AdityaManojShinde/deepfake-detector-app)