prithivMLmods commited on
Commit
b0b9a17
·
verified ·
1 Parent(s): 4af6e0d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +89 -0
README.md CHANGED
@@ -18,6 +18,16 @@ tags:
18
  - SigLIP2
19
  ---
20
 
 
 
 
 
 
 
 
 
 
 
21
  ```py
22
  Classification Report:
23
  precision recall f1-score support
@@ -31,3 +41,82 @@ SD3_Generated 0.8864 0.8458 0.8656 10000
31
  ```
32
 
33
  ![download (1).png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/MKSJZ_cv6QI5FVEtkX5R6.png)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  - SigLIP2
19
  ---
20
 
21
+ # OpenSDI-SD3-SigLIP2
22
+
23
+ > OpenSDI-SD3-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 3 (SD3), using the SiglipForImageClassification architecture.
24
+
25
+ > [!note]
26
+ *SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features* https://arxiv.org/pdf/2502.14786
27
+
28
+ > [!note]
29
+ *OpenSDI: Spotting Diffusion-Generated Images in the Open World* https://arxiv.org/pdf/2503.19653, OpenSDI SD3 SigLIP2 works best with crisp and high-quality images. Noisy images are not recommended for validation.
30
+
31
  ```py
32
  Classification Report:
33
  precision recall f1-score support
 
41
  ```
42
 
43
  ![download (1).png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/MKSJZ_cv6QI5FVEtkX5R6.png)
44
+
45
+ ---
46
+
47
+ ## Label Space: 2 Classes
48
+
49
+ The model classifies an image as either:
50
+
51
+ ```
52
+ Class 0: Real_Image
53
+ Class 1: SD3_Generated
54
+ ```
55
+
56
+ ---
57
+
58
+ ## Install Dependencies
59
+
60
+ ```bash
61
+ pip install -q transformers torch pillow gradio hf_xet
62
+ ```
63
+
64
+ ---
65
+
66
+ ## Inference Code
67
+
68
+ ```python
69
+ import gradio as gr
70
+ from transformers import AutoImageProcessor, SiglipForImageClassification
71
+ from PIL import Image
72
+ import torch
73
+
74
+ # Load model and processor
75
+ model_name = "prithivMLmods/OpenSDI-SD3-SigLIP2" # Update with the correct model path
76
+ model = SiglipForImageClassification.from_pretrained(model_name)
77
+ processor = AutoImageProcessor.from_pretrained(model_name)
78
+
79
+ # Label mapping
80
+ id2label = {
81
+ "0": "Real_Image",
82
+ "1": "SD3_Generated"
83
+ }
84
+
85
+ def classify_image(image):
86
+ image = Image.fromarray(image).convert("RGB")
87
+ inputs = processor(images=image, return_tensors="pt")
88
+
89
+ with torch.no_grad():
90
+ outputs = model(**inputs)
91
+ logits = outputs.logits
92
+ probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
93
+
94
+ prediction = {
95
+ id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))
96
+ }
97
+
98
+ return prediction
99
+
100
+ # Gradio Interface
101
+ iface = gr.Interface(
102
+ fn=classify_image,
103
+ inputs=gr.Image(type="numpy"),
104
+ outputs=gr.Label(num_top_classes=2, label="SD3 Image Detection"),
105
+ title="OpenSDI-SD3-SigLIP2",
106
+ description="Upload an image to determine whether it is a real photograph or generated by Stable Diffusion 3 (SD3)."
107
+ )
108
+
109
+ if __name__ == "__main__":
110
+ iface.launch()
111
+ ```
112
+
113
+ ---
114
+
115
+ ## Intended Use
116
+
117
+ OpenSDI-SD3-SigLIP2 is designed for tasks such as:
118
+
119
+ * Generative Image Analysis – Identify SD3-generated images for benchmarking and quality inspection.
120
+ * Dataset Validation – Ensure training or evaluation datasets are free from unintended generative artifacts.
121
+ * Content Authenticity – Verify whether visual media originates from real-world photography or AI generation.
122
+ * Digital Forensics – Aid in determining the origin of visual content in investigative scenarios.