Update README.md
Browse files
README.md
CHANGED
|
@@ -19,6 +19,16 @@ tags:
|
|
| 19 |
- Stable Diffusion v1-5
|
| 20 |
---
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
```py
|
| 23 |
Classification Report:
|
| 24 |
precision recall f1-score support
|
|
@@ -32,3 +42,82 @@ SD1.5_Generated 0.9301 0.9005 0.9150 10000
|
|
| 32 |
```
|
| 33 |
|
| 34 |

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
- Stable Diffusion v1-5
|
| 20 |
---
|
| 21 |
|
| 22 |
+
# OpenSDI-SD1.5-SigLIP2
|
| 23 |
+
|
| 24 |
+
> OpenSDI-SD1.5-SigLIP2 is a vision-language encoder model fine-tuned from google/siglip2-base-patch16-224 for binary image classification. It is trained to detect whether an image is a real photograph or generated using Stable Diffusion 1.5 (SD1.5), utilizing the SiglipForImageClassification architecture.
|
| 25 |
+
|
| 26 |
+
> [!note]
|
| 27 |
+
*SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features* https://arxiv.org/pdf/2502.14786
|
| 28 |
+
|
| 29 |
+
> [!note]
|
| 30 |
+
*OpenSDI: Spotting Diffusion-Generated Images in the Open World* https://arxiv.org/pdf/2503.19653, OpenSDI SD1.5 SigLIP2 works best with crisp and high-quality images. Noisy images are not recommended for validation.
|
| 31 |
+
|
| 32 |
```py
|
| 33 |
Classification Report:
|
| 34 |
precision recall f1-score support
|
|
|
|
| 42 |
```
|
| 43 |
|
| 44 |

|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## Label Space: 2 Classes
|
| 49 |
+
|
| 50 |
+
The model classifies an image as either:
|
| 51 |
+
|
| 52 |
+
```
|
| 53 |
+
Class 0: Real_Image
|
| 54 |
+
Class 1: SD1.5_Generated
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
---
|
| 58 |
+
|
| 59 |
+
## Install Dependencies
|
| 60 |
+
|
| 61 |
+
```bash
|
| 62 |
+
pip install -q transformers torch pillow gradio hf_xet
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
---
|
| 66 |
+
|
| 67 |
+
## Inference Code
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
import gradio as gr
|
| 71 |
+
from transformers import AutoImageProcessor, SiglipForImageClassification
|
| 72 |
+
from PIL import Image
|
| 73 |
+
import torch
|
| 74 |
+
|
| 75 |
+
# Load model and processor
|
| 76 |
+
model_name = "prithivMLmods/OpenSDI-SD1.5-SigLIP2" # Replace with your model path
|
| 77 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
| 78 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
| 79 |
+
|
| 80 |
+
# Label mapping
|
| 81 |
+
id2label = {
|
| 82 |
+
"0": "Real_Image",
|
| 83 |
+
"1": "SD1.5_Generated"
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
def classify_image(image):
|
| 87 |
+
image = Image.fromarray(image).convert("RGB")
|
| 88 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 89 |
+
|
| 90 |
+
with torch.no_grad():
|
| 91 |
+
outputs = model(**inputs)
|
| 92 |
+
logits = outputs.logits
|
| 93 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
| 94 |
+
|
| 95 |
+
prediction = {
|
| 96 |
+
id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
return prediction
|
| 100 |
+
|
| 101 |
+
# Gradio Interface
|
| 102 |
+
iface = gr.Interface(
|
| 103 |
+
fn=classify_image,
|
| 104 |
+
inputs=gr.Image(type="numpy"),
|
| 105 |
+
outputs=gr.Label(num_top_classes=2, label="SD1.5 Image Detection"),
|
| 106 |
+
title="OpenSDI-SD1.5-SigLIP2",
|
| 107 |
+
description="Upload an image to determine whether it is a real photograph or generated by Stable Diffusion 1.5 (SD1.5)."
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
if __name__ == "__main__":
|
| 111 |
+
iface.launch()
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
---
|
| 115 |
+
|
| 116 |
+
## Intended Use
|
| 117 |
+
|
| 118 |
+
OpenSDI-SD1.5-SigLIP2 is designed for the following use cases:
|
| 119 |
+
|
| 120 |
+
* Generative Model Evaluation – Detect SD1.5-generated images for analysis and benchmarking.
|
| 121 |
+
* Dataset Integrity – Filter out AI-generated images from real-world image datasets.
|
| 122 |
+
* Digital Media Forensics – Support visual content verification and source validation.
|
| 123 |
+
* Trust & Safety – Detect synthetic media used in deceptive or misleading contexts.
|