ash12321 commited on
Commit
76c46cc
·
verified ·
1 Parent(s): 58770e3

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ confusion_matrix.png filter=lfs diff=lfs merge=lfs -text
37
+ training_curves.png filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ tags:
5
+ - image-classification
6
+ - ai-detection
7
+ - sdxl
8
+ - vision-transformer
9
+ - fake-detection
10
+ datasets:
11
+ - huggan/wikiart
12
+ - ash12321/sdxl-generated-10k
13
+ metrics:
14
+ - accuracy
15
+ - precision
16
+ - recall
17
+ - f1
18
+ model-index:
19
+ - name: SDXL Detector ViT
20
+ results:
21
+ - task:
22
+ type: image-classification
23
+ name: AI Image Detection
24
+ metrics:
25
+ - type: accuracy
26
+ value: 0.9960
27
+ name: Test Accuracy
28
+ - type: f1
29
+ value: 0.9960
30
+ name: F1 Score
31
+ - type: precision
32
+ value: 0.9930
33
+ name: Precision
34
+ - type: recall
35
+ value: 0.9990
36
+ name: Recall
37
+ ---
38
+
39
+ # SDXL Detector - Vision Transformer
40
+
41
+ ## Model Description
42
+
43
+ This model is a **specialized binary classifier** trained to detect images generated by **Stable Diffusion XL (SDXL)**. It achieves **99.60% accuracy** on held-out test data.
44
+
45
+ ### Key Features
46
+
47
+ - 🎯 **Specialist Detector**: Optimized specifically for SDXL-generated images
48
+ - 🚀 **High Accuracy**: 99.60% test accuracy
49
+ - ⚡ **Fast Inference**: ~10ms per image on GPU
50
+ - 🛡️ **Robust**: Trained with 6-layer overfitting prevention
51
+ - 📊 **Well-Validated**: Separate train/val/test splits with no overlap
52
+
53
+ ### Model Details
54
+
55
+ - **Base Model**: google/vit-base-patch16-224 (Vision Transformer)
56
+ - **Task**: Binary Image Classification (Real vs SDXL-Fake)
57
+ - **Input**: 224×224 RGB images
58
+ - **Output**: 2 classes (0: Real, 1: SDXL-Fake)
59
+ - **Parameters**: 85.8M total
60
+
61
+ ## Performance
62
+
63
+ ### Test Set Results
64
+
65
+ ```
66
+ Accuracy: 0.9960
67
+ Precision: 0.9930
68
+ Recall: 0.9990
69
+ F1 Score: 0.9960
70
+ AUC-ROC: 0.9999
71
+
72
+ False Positive Rate: 0.0070
73
+ False Negative Rate: 0.0010
74
+ ```
75
+
76
+ ### Confusion Matrix
77
+
78
+ ```
79
+ Predicted
80
+ Real Fake
81
+ Actual Real 993 7
82
+ Actual Fake 1 999
83
+ ```
84
+
85
+ **Interpretation:**
86
+ - Out of 1,000 real images: 993 correctly identified (99.3%)
87
+ - Out of 1,000 SDXL images: 999 correctly identified (99.9%)
88
+
89
+ ## Training Details
90
+
91
+ ### Dataset
92
+
93
+ **Training Data:**
94
+ - Real Images: 8,000 (WikiArt paintings)
95
+ - SDXL Images: 8,000 (generated with SDXL base model)
96
+ - Total: 16,000 images
97
+
98
+ **Validation & Test:**
99
+ - 2,000 images each (1,000 real + 1,000 SDXL)
100
+ - Completely separate from training data
101
+
102
+ ### Training Configuration
103
+
104
+ ```python
105
+ Model: Vision Transformer (ViT-base-patch16-224)
106
+ Optimizer: AdamW
107
+ Learning Rate: 2e-5
108
+ Batch Size: 32
109
+ Epochs: 3 (early stopping from max 20)
110
+ Training Time: 21.7 minutes
111
+
112
+ Overfitting Prevention:
113
+ - Early Stopping (patience=5)
114
+ - Data Augmentation (random crops, flips, rotations, color jitter)
115
+ - Dropout (0.1)
116
+ - Label Smoothing (0.1)
117
+ - Weight Decay (0.01)
118
+ - Learning Rate Scheduling
119
+ ```
120
+
121
+ ## Usage
122
+
123
+ ### Installation
124
+
125
+ ```bash
126
+ pip install transformers torch pillow
127
+ ```
128
+
129
+ ### Quick Start
130
+
131
+ ```python
132
+ import torch
133
+ from PIL import Image
134
+ from transformers import ViTForImageClassification, ViTImageProcessor
135
+
136
+ # Load model and processor
137
+ model = ViTForImageClassification.from_pretrained(
138
+ "ash12321/sdxl-detector-vit"
139
+ )
140
+ processor = ViTImageProcessor.from_pretrained(
141
+ "google/vit-base-patch16-224"
142
+ )
143
+
144
+ # Load and preprocess image
145
+ image = Image.open("your_image.jpg")
146
+ inputs = processor(images=image, return_tensors="pt")
147
+
148
+ # Get prediction
149
+ model.eval()
150
+ with torch.no_grad():
151
+ outputs = model(**inputs)
152
+ logits = outputs.logits
153
+ probs = torch.softmax(logits, dim=1)
154
+ prediction = logits.argmax(dim=1).item()
155
+
156
+ # Interpret results
157
+ if prediction == 1:
158
+ confidence = probs[0][1].item()
159
+ print(f"SDXL-Generated (confidence: {confidence:.2%})")
160
+ else:
161
+ confidence = probs[0][0].item()
162
+ print(f"Real Image (confidence: {confidence:.2%})")
163
+ ```
164
+
165
+ ### Advanced Usage with Threshold
166
+
167
+ ```python
168
+ def detect_sdxl(image_path, threshold=0.5):
169
+ """
170
+ Detect if image is SDXL-generated
171
+
172
+ Args:
173
+ image_path: Path to image
174
+ threshold: Classification threshold (default 0.5)
175
+
176
+ Returns:
177
+ dict: {is_sdxl: bool, confidence: float, label: str}
178
+ """
179
+ image = Image.open(image_path).convert('RGB')
180
+ inputs = processor(images=image, return_tensors="pt")
181
+
182
+ with torch.no_grad():
183
+ outputs = model(**inputs)
184
+ probs = torch.softmax(outputs.logits, dim=1)
185
+ sdxl_prob = probs[0][1].item()
186
+
187
+ is_sdxl = sdxl_prob > threshold
188
+
189
+ return {
190
+ 'is_sdxl': is_sdxl,
191
+ 'confidence': sdxl_prob if is_sdxl else (1 - sdxl_prob),
192
+ 'label': 'SDXL-Generated' if is_sdxl else 'Real Image',
193
+ 'sdxl_probability': sdxl_prob,
194
+ 'real_probability': 1 - sdxl_prob
195
+ }
196
+
197
+ # Example
198
+ result = detect_sdxl("test_image.jpg")
199
+ print(f"{result['label']} ({result['confidence']:.2%} confident)")
200
+ ```
201
+
202
+ ## Limitations
203
+
204
+ ### What This Model Detects
205
+
206
+ ✅ **SDXL-generated images** (Stable Diffusion XL)
207
+
208
+ ### What This Model Does NOT Detect
209
+
210
+ ❌ Other AI generators (FLUX, Midjourney, DALL-E, etc.)
211
+ ❌ Edited/manipulated real images
212
+ ❌ Heavily compressed or low-quality images may reduce accuracy
213
+
214
+ **Recommendation**: Use as part of an ensemble with other specialized detectors for comprehensive AI detection.
215
+
216
+ ## Intended Use
217
+
218
+ ### Primary Use Cases
219
+
220
+ - Content moderation platforms
221
+ - Academic research on AI-generated content
222
+ - Watermarking and provenance systems
223
+ - Educational tools for AI literacy
224
+
225
+ ### Out-of-Scope Uses
226
+
227
+ - Sole basis for legal decisions
228
+ - Detection of non-SDXL generators without validation
229
+ - Processing of illegal or harmful content
230
+
231
+ ## Ethical Considerations
232
+
233
+ - This model should be used responsibly as part of broader content verification systems
234
+ - Performance may degrade on images outside the training distribution
235
+ - Always combine automated detection with human review for critical decisions
236
+ - Be transparent about using AI detection systems
237
+
238
+ ## Citation
239
+
240
+ ```bibtex
241
+ @misc{sdxl-detector-vit,
242
+ author = {ash12321},
243
+ title = {SDXL Detector - Vision Transformer},
244
+ year = {2024},
245
+ publisher = {HuggingFace},
246
+ howpublished = {\url{https://huggingface.co/ash12321/sdxl-detector-vit}},
247
+ }
248
+ ```
249
+
250
+ ## Model Card Authors
251
+
252
+ ash12321
253
+
254
+ ## Model Card Contact
255
+
256
+ For questions or feedback, please open an issue on the model repository.
257
+
258
+ ---
259
+
260
+ **Created**: 2025-12-31
261
+ **Framework**: PyTorch + Transformers
262
+ **License**: Apache 2.0
config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "ViTForImageClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.0,
6
+ "dtype": "float32",
7
+ "encoder_stride": 16,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.0,
10
+ "hidden_size": 768,
11
+ "image_size": 224,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 3072,
14
+ "layer_norm_eps": 1e-12,
15
+ "model_type": "vit",
16
+ "num_attention_heads": 12,
17
+ "num_channels": 3,
18
+ "num_hidden_layers": 12,
19
+ "patch_size": 16,
20
+ "pooler_act": "tanh",
21
+ "pooler_output_size": 768,
22
+ "qkv_bias": true,
23
+ "transformers_version": "4.57.3"
24
+ }
confusion_matrix.png ADDED

Git LFS Details

  • SHA256: 2000270e8ff56256b1873396f29493e69b2011dd0851a8ea079b38fd978d1f1b
  • Pointer size: 131 Bytes
  • Size of remote file: 114 kB
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:309145ceb0de80a47ff158557d032f6d3946bb3c255b2b829942b87a59d473a4
3
+ size 343223968
training_curves.png ADDED

Git LFS Details

  • SHA256: 3a0c4dc9327dc143cfb37602dee197000806ae2f76ed477f84048a518590e713
  • Pointer size: 131 Bytes
  • Size of remote file: 331 kB
training_results.json ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "detector_name": "SDXL",
3
+ "random_seed": 42,
4
+ "best_epoch": 3,
5
+ "best_val_acc": 0.9975,
6
+ "training_time_seconds": 1299.7091298103333,
7
+ "test_metrics": {
8
+ "accuracy": 0.996,
9
+ "precision": 0.9930417495029821,
10
+ "recall": 0.999,
11
+ "f1": 0.996011964107677,
12
+ "auc": 0.999919,
13
+ "fpr": 0.007,
14
+ "fnr": 0.001
15
+ },
16
+ "confusion_matrix": [
17
+ [
18
+ 993,
19
+ 7
20
+ ],
21
+ [
22
+ 1,
23
+ 999
24
+ ]
25
+ ],
26
+ "training_history": {
27
+ "train_loss": [
28
+ 0.237593307107687,
29
+ 0.20456762167811393,
30
+ 0.2024222546517849,
31
+ 0.2007896138727665,
32
+ 0.20122809171676637,
33
+ 0.2011393434405327,
34
+ 0.2014675495028496,
35
+ 0.1998926806151867,
36
+ 0.20160003173351287,
37
+ 0.20079970782995224,
38
+ 0.20000070515275,
39
+ 0.20020837017893792
40
+ ],
41
+ "train_acc": [
42
+ 0.979125,
43
+ 0.9974375,
44
+ 0.9981875,
45
+ 0.999125,
46
+ 0.9989375,
47
+ 0.998875,
48
+ 0.99875,
49
+ 0.9995,
50
+ 0.998625,
51
+ 0.9988125,
52
+ 0.9994375,
53
+ 0.99925
54
+ ],
55
+ "val_loss": [
56
+ 0.21416716017420329,
57
+ 0.20845685946562933,
58
+ 0.20591867182935988,
59
+ 0.20520150283026317,
60
+ 0.2066837553940122,
61
+ 0.20536757390650492,
62
+ 0.20409096872049665,
63
+ 0.20484876656343068,
64
+ 0.20928849303533162,
65
+ 0.20644679760176038,
66
+ 0.20396651351262654,
67
+ 0.205487027527794
68
+ ],
69
+ "val_acc": [
70
+ 0.996,
71
+ 0.997,
72
+ 0.9975,
73
+ 0.9975,
74
+ 0.9955,
75
+ 0.997,
76
+ 0.9975,
77
+ 0.9965,
78
+ 0.995,
79
+ 0.995,
80
+ 0.997,
81
+ 0.9965
82
+ ],
83
+ "val_precision": [
84
+ 0.9940239043824701,
85
+ 0.9960079840319361,
86
+ 0.9950248756218906,
87
+ 0.996011964107677,
88
+ 0.9979899497487437,
89
+ 0.998995983935743,
90
+ 0.9950248756218906,
91
+ 0.996996996996997,
92
+ 0.9969879518072289,
93
+ 0.9969879518072289,
94
+ 0.9950199203187251,
95
+ 0.996996996996997
96
+ ],
97
+ "val_recall": [
98
+ 0.998,
99
+ 0.998,
100
+ 1.0,
101
+ 0.999,
102
+ 0.993,
103
+ 0.995,
104
+ 1.0,
105
+ 0.996,
106
+ 0.993,
107
+ 0.993,
108
+ 0.999,
109
+ 0.996
110
+ ],
111
+ "val_f1": [
112
+ 0.9960079840319361,
113
+ 0.997002997002997,
114
+ 0.9975062344139651,
115
+ 0.9975037443834248,
116
+ 0.9954887218045113,
117
+ 0.996993987975952,
118
+ 0.9975062344139651,
119
+ 0.9964982491245623,
120
+ 0.9949899799599199,
121
+ 0.9949899799599199,
122
+ 0.9970059880239521,
123
+ 0.9964982491245623
124
+ ],
125
+ "val_auc": [
126
+ 0.9995489999999999,
127
+ 0.999897,
128
+ 0.999853,
129
+ 0.99961,
130
+ 0.999957,
131
+ 0.999959,
132
+ 0.99996,
133
+ 0.999961,
134
+ 0.999934,
135
+ 0.999937,
136
+ 0.999919,
137
+ 0.9999610000000001
138
+ ]
139
+ },
140
+ "config": {
141
+ "model_name": "google/vit-base-patch16-224",
142
+ "image_size": 224,
143
+ "num_classes": 2,
144
+ "batch_size": 32,
145
+ "learning_rate": 2e-05,
146
+ "num_epochs": 20,
147
+ "early_stopping_patience": 5,
148
+ "dropout_rate": 0.1,
149
+ "label_smoothing": 0.1,
150
+ "weight_decay": 0.01
151
+ },
152
+ "dataset_info": {
153
+ "train_real": 8000,
154
+ "train_fake": 8000,
155
+ "val_real": 1000,
156
+ "val_fake": 1000,
157
+ "test_real": 1000,
158
+ "test_fake": 1000
159
+ }
160
+ }