Update README.md
Browse files
README.md
CHANGED
@@ -15,6 +15,14 @@ tags:
|
|
15 |
- art
|
16 |
- synthetic
|
17 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
```py
|
20 |
Classification Report:
|
@@ -28,4 +36,98 @@ Classification Report:
|
|
28 |
weighted avg 0.9459 0.9444 0.9444 19999
|
29 |
```
|
30 |
|
31 |
-

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
- art
|
16 |
- synthetic
|
17 |
---
|
18 |
+
# open-deepfake-detection
|
19 |
+
|
20 |
+
> open-deepfake-detection is a vision-language encoder model fine-tuned from `siglip2-base-patch16-512` for binary image classification. It is trained to detect whether an image is fake (AI-generated) or real using the **OpenDeepfake-Preview** dataset. The model uses the `SiglipForImageClassification` architecture.
|
21 |
+
|
22 |
+
> \[!note]
|
23 |
+
> *SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features*
|
24 |
+
> [https://arxiv.org/pdf/2502.14786](https://arxiv.org/pdf/2502.14786)
|
25 |
+
|
26 |
|
27 |
```py
|
28 |
Classification Report:
|
|
|
36 |
weighted avg 0.9459 0.9444 0.9444 19999
|
37 |
```
|
38 |
|
39 |
+

|
40 |
+
|
41 |
+
---
|
42 |
+
|
43 |
+
## Label Space: 2 Classes
|
44 |
+
|
45 |
+
The model classifies an image as either:
|
46 |
+
|
47 |
+
```
|
48 |
+
Class 0: Fake
|
49 |
+
Class 1: Real
|
50 |
+
```
|
51 |
+
|
52 |
+
---
|
53 |
+
|
54 |
+
## Install Dependencies
|
55 |
+
|
56 |
+
```bash
|
57 |
+
pip install -q transformers torch pillow gradio hf_xet
|
58 |
+
```
|
59 |
+
|
60 |
+
---
|
61 |
+
|
62 |
+
## Inference Code
|
63 |
+
|
64 |
+
```python
|
65 |
+
import gradio as gr
|
66 |
+
from transformers import AutoImageProcessor, SiglipForImageClassification
|
67 |
+
from PIL import Image
|
68 |
+
import torch
|
69 |
+
|
70 |
+
# Load model and processor
|
71 |
+
model_name = "prithivMLmods/open-deepfake-detection" # Updated model name
|
72 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
73 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
74 |
+
|
75 |
+
# Updated label mapping
|
76 |
+
id2label = {
|
77 |
+
"0": "Fake",
|
78 |
+
"1": "Real"
|
79 |
+
}
|
80 |
+
|
81 |
+
def classify_image(image):
|
82 |
+
image = Image.fromarray(image).convert("RGB")
|
83 |
+
inputs = processor(images=image, return_tensors="pt")
|
84 |
+
|
85 |
+
with torch.no_grad():
|
86 |
+
outputs = model(**inputs)
|
87 |
+
logits = outputs.logits
|
88 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
89 |
+
|
90 |
+
prediction = {
|
91 |
+
id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))
|
92 |
+
}
|
93 |
+
|
94 |
+
return prediction
|
95 |
+
|
96 |
+
# Gradio Interface
|
97 |
+
iface = gr.Interface(
|
98 |
+
fn=classify_image,
|
99 |
+
inputs=gr.Image(type="numpy"),
|
100 |
+
outputs=gr.Label(num_top_classes=2, label="Deepfake Detection"),
|
101 |
+
title="open-deepfake-detection",
|
102 |
+
description="Upload an image to detect whether it is AI-generated (Fake) or a real photograph (Real), using the OpenDeepfake-Preview dataset."
|
103 |
+
)
|
104 |
+
|
105 |
+
if __name__ == "__main__":
|
106 |
+
iface.launch()
|
107 |
+
```
|
108 |
+
|
109 |
+
---
|
110 |
+
|
111 |
+
## Demo Inference
|
112 |
+
|
113 |
+
> [!warning]
|
114 |
+
real
|
115 |
+
|
116 |
+

|
117 |
+

|
118 |
+
|
119 |
+
> [!warning]
|
120 |
+
real
|
121 |
+
|
122 |
+

|
123 |
+

|
124 |
+
|
125 |
+
## Intended Use
|
126 |
+
|
127 |
+
`open-deepfake-detection` is designed for:
|
128 |
+
|
129 |
+
* **Deepfake Detection** – Identify AI-generated or manipulated images.
|
130 |
+
* **Content Moderation** – Flag synthetic or fake visual content.
|
131 |
+
* **Dataset Curation** – Remove synthetic samples from mixed datasets.
|
132 |
+
* **Visual Authenticity Verification** – Check the integrity of visual media.
|
133 |
+
* **Digital Forensics** – Support image source verification and traceability.
|