Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -28,12 +28,6 @@ model-index:
|
|
| 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
|
|
@@ -50,83 +44,20 @@ This model is a **specialized binary classifier** trained to detect images gener
|
|
| 50 |
- 🛡️ **Robust**: Trained with 6-layer overfitting prevention
|
| 51 |
- 📊 **Well-Validated**: Separate train/val/test splits with no overlap
|
| 52 |
|
| 53 |
-
###
|
| 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:
|
| 68 |
-
Recall:
|
| 69 |
-
F1 Score:
|
| 70 |
-
AUC-ROC:
|
| 71 |
|
| 72 |
False Positive Rate: 0.0070
|
| 73 |
False Negative Rate: 0.0010
|
| 74 |
```
|
| 75 |
|
| 76 |
-
##
|
| 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
|
|
@@ -141,99 +72,41 @@ processor = ViTImageProcessor.from_pretrained(
|
|
| 141 |
"google/vit-base-patch16-224"
|
| 142 |
)
|
| 143 |
|
| 144 |
-
# Load
|
| 145 |
-
image = Image.open("
|
| 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 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 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 |
-
##
|
| 166 |
|
| 167 |
```python
|
| 168 |
-
|
| 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 |
-
|
| 198 |
-
|
| 199 |
-
print(f"
|
| 200 |
```
|
| 201 |
|
| 202 |
-
##
|
| 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 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
-
|
| 221 |
-
-
|
| 222 |
-
-
|
| 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 |
|
|
@@ -247,16 +120,7 @@ print(f"{result['label']} ({result['confidence']:.2%} confident)")
|
|
| 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
|
|
|
|
| 28 |
- type: f1
|
| 29 |
value: 0.9960
|
| 30 |
name: F1 Score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
---
|
| 32 |
|
| 33 |
# SDXL Detector - Vision Transformer
|
|
|
|
| 44 |
- 🛡️ **Robust**: Trained with 6-layer overfitting prevention
|
| 45 |
- 📊 **Well-Validated**: Separate train/val/test splits with no overlap
|
| 46 |
|
| 47 |
+
### Performance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
```
|
| 50 |
+
Test Accuracy: 0.9960
|
| 51 |
+
Precision: 0.9930
|
| 52 |
+
Recall: 0.9990
|
| 53 |
+
F1 Score: 0.9960
|
| 54 |
+
AUC-ROC: 0.9999
|
| 55 |
|
| 56 |
False Positive Rate: 0.0070
|
| 57 |
False Negative Rate: 0.0010
|
| 58 |
```
|
| 59 |
|
| 60 |
+
## Quick Start
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
```python
|
| 63 |
import torch
|
|
|
|
| 72 |
"google/vit-base-patch16-224"
|
| 73 |
)
|
| 74 |
|
| 75 |
+
# Load image
|
| 76 |
+
image = Image.open("test.jpg")
|
| 77 |
inputs = processor(images=image, return_tensors="pt")
|
| 78 |
|
| 79 |
# Get prediction
|
| 80 |
model.eval()
|
| 81 |
with torch.no_grad():
|
| 82 |
outputs = model(**inputs)
|
| 83 |
+
probs = torch.softmax(outputs.logits, dim=1)
|
| 84 |
+
|
| 85 |
+
if probs[0][1] > 0.5:
|
| 86 |
+
print(f"SDXL-Generated ({probs[0][1]:.2%} confident)")
|
| 87 |
+
else:
|
| 88 |
+
print(f"Real Image ({probs[0][0]:.2%} confident)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
```
|
| 90 |
|
| 91 |
+
## Using the model.py Helper
|
| 92 |
|
| 93 |
```python
|
| 94 |
+
from model import detect_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
+
result = detect_image("test.jpg", model_path="ash12321/sdxl-detector-vit")
|
| 97 |
+
print(f"Is Fake: {result['is_fake']}")
|
| 98 |
+
print(f"Confidence: {result['confidence']:.2%}")
|
| 99 |
```
|
| 100 |
|
| 101 |
+
## Files in this Repository
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
- `pytorch_model.bin` - Model weights
|
| 104 |
+
- `config.json` - Model configuration
|
| 105 |
+
- `model.py` - Model architecture and helper functions
|
| 106 |
+
- `README.md` - This documentation
|
| 107 |
+
- `training_results.json` - Detailed training metrics
|
| 108 |
+
- `training_curves.png` - Training visualization
|
| 109 |
+
- `confusion_matrix.png` - Test set confusion matrix
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
## Citation
|
| 112 |
|
|
|
|
| 120 |
}
|
| 121 |
```
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
---
|
| 124 |
|
| 125 |
+
**License**: Apache 2.0
|
| 126 |
**Created**: 2025-12-31
|
|
|
|
|
|