Update README.md
Browse files
README.md
CHANGED
@@ -7,7 +7,65 @@ base_model:
|
|
7 |
pipeline_tag: image-classification
|
8 |
library_name: transformers
|
9 |
---
|
|
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
Classification report:
|
12 |
|
13 |
precision recall f1-score support
|
@@ -18,4 +76,14 @@ library_name: transformers
|
|
18 |
|
19 |
accuracy 0.9905 4000
|
20 |
macro avg 0.9906 0.9905 0.9905 4000
|
21 |
-
weighted avg 0.9906 0.9905 0.9905 4000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
pipeline_tag: image-classification
|
8 |
library_name: transformers
|
9 |
---
|
10 |
+
Here is the updated version with the new name **AI-vs-Deepfake-vs-Real-Siglip2**, classifying images into **AI-generated, deepfake, or real** categories.
|
11 |
|
12 |
+
---
|
13 |
+
|
14 |
+
# **AI-vs-Deepfake-vs-Real-Siglip2**
|
15 |
+
**AI-vs-Deepfake-vs-Real-Siglip2** is an image classification vision-language encoder model fine-tuned from **google/siglip2-base-patch16-224** for a single-label classification task. It is designed to **distinguish AI-generated images, deepfake images, and real images** using the **SiglipForImageClassification** architecture.
|
16 |
+
|
17 |
+
The model categorizes images into three classes:
|
18 |
+
- **Class 0:** "AI" – The image is fully AI-generated, created by machine learning models.
|
19 |
+
- **Class 1:** "Deepfake" – The image is a manipulated deepfake, where real content has been altered.
|
20 |
+
- **Class 2:** "Real" – The image is an authentic, unaltered photograph.
|
21 |
+
|
22 |
+
# **Run with Transformers**
|
23 |
+
|
24 |
+
```python
|
25 |
+
!pip install -q transformers torch pillow gradio
|
26 |
+
```
|
27 |
+
|
28 |
+
```python
|
29 |
+
import gradio as gr
|
30 |
+
from transformers import AutoImageProcessor
|
31 |
+
from transformers import SiglipForImageClassification
|
32 |
+
from transformers.image_utils import load_image
|
33 |
+
from PIL import Image
|
34 |
+
import torch
|
35 |
+
|
36 |
+
# Load model and processor
|
37 |
+
model_name = "prithivMLmods/AI-vs-Deepfake-vs-Real-Siglip2"
|
38 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
39 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
40 |
+
|
41 |
+
def image_classification(image):
|
42 |
+
"""Classifies an image as AI-generated, deepfake, or real."""
|
43 |
+
image = Image.fromarray(image).convert("RGB")
|
44 |
+
inputs = processor(images=image, return_tensors="pt")
|
45 |
+
|
46 |
+
with torch.no_grad():
|
47 |
+
outputs = model(**inputs)
|
48 |
+
logits = outputs.logits
|
49 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
50 |
+
|
51 |
+
labels = model.config.id2label
|
52 |
+
predictions = {labels[i]: round(probs[i], 3) for i in range(len(probs))}
|
53 |
+
|
54 |
+
return predictions
|
55 |
+
|
56 |
+
# Create Gradio interface
|
57 |
+
iface = gr.Interface(
|
58 |
+
fn=image_classification,
|
59 |
+
inputs=gr.Image(type="numpy"),
|
60 |
+
outputs=gr.Label(label="Classification Result"),
|
61 |
+
title="AI vs Deepfake vs Real Image Classification",
|
62 |
+
description="Upload an image to determine whether it is AI-generated, a deepfake, or a real image."
|
63 |
+
)
|
64 |
+
|
65 |
+
# Launch the app
|
66 |
+
if __name__ == "__main__":
|
67 |
+
iface.launch()
|
68 |
+
```
|
69 |
Classification report:
|
70 |
|
71 |
precision recall f1-score support
|
|
|
76 |
|
77 |
accuracy 0.9905 4000
|
78 |
macro avg 0.9906 0.9905 0.9905 4000
|
79 |
+
weighted avg 0.9906 0.9905 0.9905 4000
|
80 |
+
|
81 |
+
# **Intended Use:**
|
82 |
+
|
83 |
+
The **AI-vs-Deepfake-vs-Real-Siglip2** model is designed to classify images into three categories: **AI-generated, deepfake, or real**. It helps in identifying whether an image is fully synthetic, altered through deepfake techniques, or an unaltered real image.
|
84 |
+
|
85 |
+
### Potential Use Cases:
|
86 |
+
- **Deepfake Detection:** Identifying manipulated deepfake content in media.
|
87 |
+
- **AI-Generated Image Identification:** Distinguishing AI-generated images from real or deepfake images.
|
88 |
+
- **Content Verification:** Supporting fact-checking and digital forensics in assessing image authenticity.
|
89 |
+
- **Social Media and News Filtering:** Helping platforms flag AI-generated or deepfake content.
|