Upload README.md
Browse files
README.md
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# DeepFake Detection with CNNs & Transfer Learning
|
3 |
+
|
4 |
+
This assignment is part of the **CENG 481 - Artificial Neural Networks** course assignment.
|
5 |
+
It addresses the task of detecting deepfake content using image-based CNN classification and transfer learning techniques.
|
6 |
+
|
7 |
+
---
|
8 |
+
|
9 |
+
## 🎯 Objective
|
10 |
+
|
11 |
+
- Build an end-to-end image-based deepfake detection pipeline
|
12 |
+
- Extract and align 10 frames per video clip
|
13 |
+
- Pair each real frame with a corresponding fake variation
|
14 |
+
- Train a CNN model using EfficientNetB0 with ImageNet weights
|
15 |
+
- Apply regularization, checkpointing, and early stopping for best performance
|
16 |
+
- Evaluate using AUC-ROC, accuracy, precision, recall, F1-score
|
17 |
+
|
18 |
+
---
|
19 |
+
|
20 |
+
## 📦 Dataset
|
21 |
+
|
22 |
+
- **Source**: [DFDC Part-34 on Kaggle](https://www.kaggle.com/datasets/greatgamedota/dfdc-part-34)
|
23 |
+
- **Metadata**: `metadata34.csv`
|
24 |
+
- Each video is represented by 10 frames: `0.jpg`, `30.jpg`, ..., `270.jpg`
|
25 |
+
- Fake videos are linked to their originals via metadata
|
26 |
+
|
27 |
+
---
|
28 |
+
|
29 |
+
## 🧠 Model
|
30 |
+
|
31 |
+
- Base: `EfficientNetB0`, pretrained on ImageNet
|
32 |
+
- Frozen base trained with custom head; then base unfrozen and fine-tuned
|
33 |
+
- Architecture: GlobalAveragePooling2D → Dropout(0.4) → Dense(1, sigmoid)
|
34 |
+
- Input size: 224×224×3
|
35 |
+
- Optimizer: Adam (`lr=1e-4` frozen, `lr=1e-5` unfrozen)
|
36 |
+
- Loss: Binary Crossentropy
|
37 |
+
- Metrics: AUC, Accuracy, Precision, Recall, F1
|
38 |
+
|
39 |
+
---
|
40 |
+
|
41 |
+
## 🏋️ Training
|
42 |
+
|
43 |
+
- Balanced dataset from 6784 images (REAL + FAKE)
|
44 |
+
- Train/Test split: 79% / 21% (stratified)
|
45 |
+
- Batch size: 32
|
46 |
+
- Epochs: max 100 (early stopping with patience=8)
|
47 |
+
- Model checkpointing enabled (.keras format)
|
48 |
+
- TensorBoard used for experiment tracking
|
49 |
+
- Platform: Google Colab (GPU)
|
50 |
+
|
51 |
+
---
|
52 |
+
|
53 |
+
## 🧪 Evaluation (Final Results)
|
54 |
+
|
55 |
+
- Accuracy: 0.80
|
56 |
+
- AUC-ROC: 0.88
|
57 |
+
- Precision: 0.78
|
58 |
+
- Recall: 0.82
|
59 |
+
- F1-Score: 0.80
|
60 |
+
|
61 |
+
---
|
62 |
+
|
63 |
+
## 💾 How to Use
|
64 |
+
|
65 |
+
```python
|
66 |
+
from huggingface_hub import hf_hub_download
|
67 |
+
from tensorflow.keras.models import load_model
|
68 |
+
import numpy as np
|
69 |
+
import cv2
|
70 |
+
|
71 |
+
# Load and preprocess image
|
72 |
+
def preprocess_image(path):
|
73 |
+
img = cv2.imread(path)
|
74 |
+
img = cv2.resize(img, (224, 224))
|
75 |
+
img = img / 255.0
|
76 |
+
return img.astype(np.float32)
|
77 |
+
|
78 |
+
# Download and load model
|
79 |
+
model_path = hf_hub_download(repo_id="fc63/deepfake-detection-cnn_v2", filename="best_model.keras")
|
80 |
+
model = load_model(model_path)
|
81 |
+
|
82 |
+
# Predict
|
83 |
+
img = preprocess_image("frame.jpg")
|
84 |
+
pred = model.predict(img[np.newaxis, ...])
|
85 |
+
|
86 |
+
print("FAKE" if pred[0][0] > 0.5 else "REAL")
|
87 |
+
```
|
88 |
+
|
89 |
+
---
|
90 |
+
|
91 |
+
## 📁 Requirements
|
92 |
+
|
93 |
+
```
|
94 |
+
tensorflow
|
95 |
+
scikit-learn
|
96 |
+
pandas
|
97 |
+
matplotlib
|
98 |
+
opencv-python
|
99 |
+
huggingface_hub
|
100 |
+
```
|
101 |
+
|
102 |
+
---
|
103 |
+
|
104 |
+
## 🔗 Repositories
|
105 |
+
|
106 |
+
- 🤗 Model: https://huggingface.co/fc63/deepfake-detection-cnn_v2
|
107 |
+
- 💻 Codebase: https://github.com/fc63/Deep-Fake-Video-Detection
|
108 |
+
|
109 |
+
---
|
110 |
+
|
111 |
+
## ⚠️ Ethical Considerations
|
112 |
+
|
113 |
+
Deepfake technology poses threats to media trust, privacy, and security. This assignment aims to mitigate misuse by improving detection accuracy while acknowledging dataset limitations and the risk of bias.
|
114 |
+
|
115 |
+
---
|
116 |
+
|
117 |
+
## 👤 Author
|
118 |
+
|
119 |
+
**Furkan Çoban**
|
120 |
+
Çankaya University
|
121 |
+
|
122 |
+
---
|
123 |
+
|
124 |
+
## 🧑🏫 Instructor
|
125 |
+
|
126 |
+
This assignment was completed as part of the CENG 481 - Artificial Neural Networks course
|
127 |
+
at Çankaya University under the supervision of **Dr. Nurdan Saran**.
|