Update README.md
Browse files
README.md
CHANGED
|
@@ -1,52 +1,41 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
- image-classification
|
| 4 |
-
- computer-vision
|
| 5 |
-
- deepfake-detection
|
| 6 |
-
- fine-tuned
|
| 7 |
-
license: mit
|
| 8 |
-
datasets:
|
| 9 |
-
- 140k-real-and-fake-faces
|
| 10 |
-
metrics:
|
| 11 |
-
- accuracy
|
| 12 |
-
---
|
| 13 |
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
Developed by **[Sadra Milani Moghaddam](https://sadramilani.ir/)**, this model is designed to detect faces generated by state-of-the-art synthesis models—including those based on SDXL and similar architectures—while maintaining strong generalization across diverse image sources.
|
| 19 |
|
| 20 |
-
##
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
|
| 24 |
-
|
| 25 |
|
| 26 |
-
- **
|
| 27 |
-
- **Training Dataset**: [140k Real and Fake Faces (Kaggle)](https://www.kaggle.com/datasets/xhlulu/140k-real-and-fake-faces)
|
| 28 |
-
- **Test Accuracy**: **91%** on an independent hold-out test set
|
| 29 |
-
- **Hardware Used for Training**: NVIDIA RTX 3060 (12GB VRAM)
|
| 30 |
-
- **License**: [MIT](https://opensource.org/licenses/MIT)
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
---
|
| 35 |
|
| 36 |
-
## 💻
|
| 37 |
-
|
| 38 |
-
You can easily load and run inference with this model using the Hugging Face `transformers` library.
|
| 39 |
-
|
| 40 |
-
### Installation
|
| 41 |
|
|
|
|
| 42 |
```bash
|
| 43 |
pip install transformers torch pillow
|
| 44 |
```
|
|
|
|
| 45 |
```python
|
| 46 |
import argparse
|
| 47 |
from transformers import AutoModelForImageClassification, AutoFeatureExtractor
|
| 48 |
from PIL import Image
|
| 49 |
import torch
|
|
|
|
| 50 |
|
| 51 |
def main():
|
| 52 |
parser = argparse.ArgumentParser(
|
|
@@ -55,41 +44,39 @@ def main():
|
|
| 55 |
parser.add_argument("--image", type=str, required=True, help="Path to the input image file")
|
| 56 |
args = parser.parse_args()
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
model_name = "SADRACODING/SDXL-Deepfake-Detector"
|
|
|
|
| 59 |
model = AutoModelForImageClassification.from_pretrained(model_name)
|
| 60 |
feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
|
| 61 |
|
|
|
|
| 62 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 63 |
model.to(device)
|
| 64 |
model.eval()
|
|
|
|
| 65 |
|
|
|
|
| 66 |
image = Image.open(args.image).convert("RGB")
|
| 67 |
inputs = feature_extractor(images=image, return_tensors="pt").to(device)
|
| 68 |
|
|
|
|
| 69 |
with torch.no_grad():
|
| 70 |
outputs = model(**inputs)
|
| 71 |
-
|
| 72 |
logits = outputs.logits
|
| 73 |
predicted_class_idx = logits.argmax(-1).item()
|
| 74 |
predicted_label = model.config.id2label[predicted_class_idx]
|
| 75 |
|
| 76 |
-
|
| 77 |
-
print(f"
|
|
|
|
|
|
|
| 78 |
|
| 79 |
if __name__ == "__main__":
|
| 80 |
main()
|
| 81 |
-
```
|
| 82 |
-
|
| 83 |
-
```bash
|
| 84 |
-
python predict.py --image path/to/face_image.jpg
|
| 85 |
-
```
|
| 86 |
-
## 📄 License
|
| 87 |
-
|
| 88 |
-
This model is released under the [MIT License](https://opensource.org/licenses/MIT), allowing for both commercial and non-commercial use with proper attribution.
|
| 89 |
-
|
| 90 |
-
## 🙌 Acknowledgements
|
| 91 |
-
|
| 92 |
-
- **Dataset**: [140k Real and Fake Faces](https://www.kaggle.com/datasets/xhlulu/140k-real-and-fake-faces) by xhlulu
|
| 93 |
-
- **Framework**: [Hugging Face Transformers](https://huggingface.co/docs/transformers)
|
| 94 |
-
- **Github**: [SDXL-Deepfake-Detector](https://github.com/SadraCoding/SDXL-Deepfake-Detector)
|
| 95 |
-
- **Developer**: [Sadra Milani Moghaddam](https://sadramilani.ir/)
|
|
|
|
| 1 |
+
# 🎭 SDXL-Deepfake-Detector
|
| 2 |
+
### Detecting AI-Generated Faces with Precision and Purpose
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
> *"Not just another classifier — a tool for digital truth."*
|
| 5 |
+
> Developed by **[Sadra Milani Moghaddam](https://sadramilani.ir/)**
|
| 6 |
|
| 7 |
+
---
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
## 🌍 Why This Matters
|
| 10 |
+
As generative AI (like SDXL, DALL·E, and Midjourney) becomes more accessible, the line between real and synthetic media blurs — especially for vulnerable communities. This project started as a technical experiment but evolved into a **privacy-aware, open-source defense** against visual misinformation, with a focus on **ethical AI deployment**.
|
| 11 |
|
| 12 |
+
---
|
| 13 |
|
| 14 |
+
## 🚀 Model Overview
|
| 15 |
|
| 16 |
+
**SDXL-Deepfake-Detector** is a fine-tuned vision transformer that classifies human faces as **Real (0)** or **AI-Generated (1)**. Trained on the [140k Real and Fake Faces](https://www.kaggle.com/datasets/xhlulu/140k-real-and-fake-faces) dataset, it achieves **91% accuracy** on held-out test data and generalizes well across diverse synthesis methods.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
### ✅ Key Highlights
|
| 19 |
+
- **Architecture**: Fine-tuned Vision Transformer (ViT) via Hugging Face `transformers`
|
| 20 |
+
- **Dataset**: 140k balanced real/fake face images
|
| 21 |
+
- **License**: [MIT](https://opensource.org/licenses/MIT) — free for research and commercial use
|
| 22 |
+
- **Hardware**: Trained on a single NVIDIA RTX 3060 (12GB VRAM) — proving high impact doesn’t require massive resources
|
| 23 |
|
| 24 |
---
|
| 25 |
|
| 26 |
+
## 💻 Quick Start
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
### Dependencies
|
| 29 |
```bash
|
| 30 |
pip install transformers torch pillow
|
| 31 |
```
|
| 32 |
+
### Python Script
|
| 33 |
```python
|
| 34 |
import argparse
|
| 35 |
from transformers import AutoModelForImageClassification, AutoFeatureExtractor
|
| 36 |
from PIL import Image
|
| 37 |
import torch
|
| 38 |
+
import os
|
| 39 |
|
| 40 |
def main():
|
| 41 |
parser = argparse.ArgumentParser(
|
|
|
|
| 44 |
parser.add_argument("--image", type=str, required=True, help="Path to the input image file")
|
| 45 |
args = parser.parse_args()
|
| 46 |
|
| 47 |
+
# Validate image path
|
| 48 |
+
if not os.path.isfile(args.image):
|
| 49 |
+
raise FileNotFoundError(f"Image file not found: {args.image}")
|
| 50 |
+
|
| 51 |
+
# Load model and feature extractor from Hugging Face Hub
|
| 52 |
model_name = "SADRACODING/SDXL-Deepfake-Detector"
|
| 53 |
+
print(f"Loading model '{model_name}'...")
|
| 54 |
model = AutoModelForImageClassification.from_pretrained(model_name)
|
| 55 |
feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
|
| 56 |
|
| 57 |
+
# Set device (GPU if available)
|
| 58 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 59 |
model.to(device)
|
| 60 |
model.eval()
|
| 61 |
+
print(f"Running on device: {device}")
|
| 62 |
|
| 63 |
+
# Load and preprocess image
|
| 64 |
image = Image.open(args.image).convert("RGB")
|
| 65 |
inputs = feature_extractor(images=image, return_tensors="pt").to(device)
|
| 66 |
|
| 67 |
+
# Inference
|
| 68 |
with torch.no_grad():
|
| 69 |
outputs = model(**inputs)
|
| 70 |
+
|
| 71 |
logits = outputs.logits
|
| 72 |
predicted_class_idx = logits.argmax(-1).item()
|
| 73 |
predicted_label = model.config.id2label[predicted_class_idx]
|
| 74 |
|
| 75 |
+
# Output
|
| 76 |
+
print(f"Prediction Result")
|
| 77 |
+
print(f"Class Index: {predicted_class_idx}")
|
| 78 |
+
print(f"Label : {predicted_label}")
|
| 79 |
|
| 80 |
if __name__ == "__main__":
|
| 81 |
main()
|
| 82 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|