Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -28,12 +28,6 @@ model-index:
|
|
| 28 |
- type: f1
|
| 29 |
value: 0.9985
|
| 30 |
name: F1 Score
|
| 31 |
-
- type: precision
|
| 32 |
-
value: 1.0000
|
| 33 |
-
name: Precision
|
| 34 |
-
- type: recall
|
| 35 |
-
value: 0.9970
|
| 36 |
-
name: Recall
|
| 37 |
---
|
| 38 |
|
| 39 |
# FLUX Detector - Vision Transformer
|
|
@@ -50,85 +44,20 @@ This model is a **specialized binary classifier** trained to detect images gener
|
|
| 50 |
- ⚡ **Fast Inference**: ~10ms per image on GPU
|
| 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 FLUX-Fake)
|
| 57 |
-
- **Input**: 224×224 RGB images
|
| 58 |
-
- **Output**: 2 classes (0: Real, 1: FLUX-Fake)
|
| 59 |
-
- **Parameters**: 85.8M total
|
| 60 |
-
|
| 61 |
-
## Performance
|
| 62 |
-
|
| 63 |
-
### Test Set Results
|
| 64 |
|
| 65 |
```
|
| 66 |
-
Accuracy: 0.9985
|
| 67 |
-
Precision:
|
| 68 |
-
Recall:
|
| 69 |
-
F1 Score:
|
| 70 |
-
AUC-ROC:
|
| 71 |
|
| 72 |
False Positive Rate: 0.0000 (0.0%!)
|
| 73 |
False Negative Rate: 0.0030
|
| 74 |
```
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
```
|
| 79 |
-
Predicted
|
| 80 |
-
Real Fake
|
| 81 |
-
Actual Real 1000 0 ← Perfect!
|
| 82 |
-
Actual Fake 3 997
|
| 83 |
-
```
|
| 84 |
-
|
| 85 |
-
**Interpretation:**
|
| 86 |
-
- Out of 1,000 real images: **ALL 1,000 correctly identified (100%)**
|
| 87 |
-
- Out of 1,000 FLUX images: 997 correctly identified (99.7%)
|
| 88 |
-
- **ZERO false positives** - never calls real images fake!
|
| 89 |
-
|
| 90 |
-
## Training Details
|
| 91 |
-
|
| 92 |
-
### Dataset
|
| 93 |
-
|
| 94 |
-
**Training Data:**
|
| 95 |
-
- Real Images: 8,000 (WikiArt paintings)
|
| 96 |
-
- FLUX Images: 8,000 (generated with FLUX.1-dev at 20 steps)
|
| 97 |
-
- Total: 16,000 images
|
| 98 |
-
|
| 99 |
-
**Validation & Test:**
|
| 100 |
-
- 2,000 images each (1,000 real + 1,000 FLUX)
|
| 101 |
-
- Completely separate from training data
|
| 102 |
-
- Different random seed than SDXL detector (no overlap)
|
| 103 |
-
|
| 104 |
-
### Training Configuration
|
| 105 |
-
|
| 106 |
-
```python
|
| 107 |
-
Model: Vision Transformer (ViT-base-patch16-224)
|
| 108 |
-
Optimizer: AdamW
|
| 109 |
-
Learning Rate: 2e-5 (reduced to 1e-5 via scheduling)
|
| 110 |
-
Batch Size: 32
|
| 111 |
-
Epochs: 6 (early stopping from max 20)
|
| 112 |
-
Training Time: 16.2 minutes
|
| 113 |
-
|
| 114 |
-
Overfitting Prevention:
|
| 115 |
-
- Early Stopping (patience=5)
|
| 116 |
-
- Data Augmentation (random crops, flips, rotations, color jitter)
|
| 117 |
-
- Dropout (0.1)
|
| 118 |
-
- Label Smoothing (0.1)
|
| 119 |
-
- Weight Decay (0.01)
|
| 120 |
-
- Learning Rate Scheduling
|
| 121 |
-
```
|
| 122 |
-
|
| 123 |
-
## Usage
|
| 124 |
-
|
| 125 |
-
### Installation
|
| 126 |
-
|
| 127 |
-
```bash
|
| 128 |
-
pip install transformers torch pillow
|
| 129 |
-
```
|
| 130 |
-
|
| 131 |
-
### Quick Start
|
| 132 |
|
| 133 |
```python
|
| 134 |
import torch
|
|
@@ -143,105 +72,41 @@ processor = ViTImageProcessor.from_pretrained(
|
|
| 143 |
"google/vit-base-patch16-224"
|
| 144 |
)
|
| 145 |
|
| 146 |
-
# Load
|
| 147 |
-
image = Image.open("
|
| 148 |
inputs = processor(images=image, return_tensors="pt")
|
| 149 |
|
| 150 |
# Get prediction
|
| 151 |
model.eval()
|
| 152 |
with torch.no_grad():
|
| 153 |
outputs = model(**inputs)
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
confidence = probs[0][1].item()
|
| 161 |
-
print(f"FLUX-Generated (confidence: {confidence:.2%})")
|
| 162 |
-
else:
|
| 163 |
-
confidence = probs[0][0].item()
|
| 164 |
-
print(f"Real Image (confidence: {confidence:.2%})")
|
| 165 |
```
|
| 166 |
|
| 167 |
-
|
| 168 |
|
| 169 |
```python
|
| 170 |
-
|
| 171 |
-
"""
|
| 172 |
-
Detect if image is FLUX-generated
|
| 173 |
-
|
| 174 |
-
Args:
|
| 175 |
-
image_path: Path to image
|
| 176 |
-
threshold: Classification threshold (default 0.5)
|
| 177 |
-
|
| 178 |
-
Returns:
|
| 179 |
-
dict: {is_flux: bool, confidence: float, label: str}
|
| 180 |
-
"""
|
| 181 |
-
image = Image.open(image_path).convert('RGB')
|
| 182 |
-
inputs = processor(images=image, return_tensors="pt")
|
| 183 |
-
|
| 184 |
-
with torch.no_data():
|
| 185 |
-
outputs = model(**inputs)
|
| 186 |
-
probs = torch.softmax(outputs.logits, dim=1)
|
| 187 |
-
flux_prob = probs[0][1].item()
|
| 188 |
-
|
| 189 |
-
is_flux = flux_prob > threshold
|
| 190 |
-
|
| 191 |
-
return {
|
| 192 |
-
'is_flux': is_flux,
|
| 193 |
-
'confidence': flux_prob if is_flux else (1 - flux_prob),
|
| 194 |
-
'label': 'FLUX-Generated' if is_flux else 'Real Image',
|
| 195 |
-
'flux_probability': flux_prob,
|
| 196 |
-
'real_probability': 1 - flux_prob
|
| 197 |
-
}
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
print(f"
|
| 202 |
```
|
| 203 |
|
| 204 |
-
##
|
| 205 |
-
|
| 206 |
-
### What This Model Detects
|
| 207 |
-
|
| 208 |
-
✅ **FLUX.1-dev generated images** (Black Forest Labs)
|
| 209 |
-
|
| 210 |
-
### What This Model Does NOT Detect
|
| 211 |
-
|
| 212 |
-
❌ Other AI generators (SDXL, Midjourney, DALL-E, etc.)
|
| 213 |
-
❌ FLUX.1-schnell (4-step variant) - not tested
|
| 214 |
-
❌ FLUX 2 (newer version) - not tested
|
| 215 |
-
❌ Edited/manipulated real images
|
| 216 |
-
❌ Heavily compressed or low-quality images may reduce accuracy
|
| 217 |
-
|
| 218 |
-
**Note**: This model was trained on FLUX.1-dev images generated at 20 steps, but should generalize to other step counts (15-50 steps) based on research.
|
| 219 |
-
|
| 220 |
-
**Recommendation**: Use as part of an ensemble with other specialized detectors for comprehensive AI detection.
|
| 221 |
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
-
|
| 227 |
-
-
|
| 228 |
-
-
|
| 229 |
-
- Educational tools for AI literacy
|
| 230 |
-
- FLUX-specific image verification
|
| 231 |
-
|
| 232 |
-
### Out-of-Scope Uses
|
| 233 |
-
|
| 234 |
-
- Sole basis for legal decisions
|
| 235 |
-
- Detection of non-FLUX generators without validation
|
| 236 |
-
- Processing of illegal or harmful content
|
| 237 |
-
|
| 238 |
-
## Ethical Considerations
|
| 239 |
-
|
| 240 |
-
- This model should be used responsibly as part of broader content verification systems
|
| 241 |
-
- Performance may degrade on images outside the training distribution
|
| 242 |
-
- Always combine automated detection with human review for critical decisions
|
| 243 |
-
- Be transparent about using AI detection systems
|
| 244 |
-
- The model's zero false positive rate makes it particularly suitable for applications where falsely flagging real content is problematic
|
| 245 |
|
| 246 |
## Citation
|
| 247 |
|
|
@@ -255,16 +120,7 @@ print(f"{result['label']} ({result['confidence']:.2%} confident)")
|
|
| 255 |
}
|
| 256 |
```
|
| 257 |
|
| 258 |
-
## Model Card Authors
|
| 259 |
-
|
| 260 |
-
ash12321
|
| 261 |
-
|
| 262 |
-
## Model Card Contact
|
| 263 |
-
|
| 264 |
-
For questions or feedback, please open an issue on the model repository.
|
| 265 |
-
|
| 266 |
---
|
| 267 |
|
|
|
|
| 268 |
**Created**: 2025-12-31
|
| 269 |
-
**Framework**: PyTorch + Transformers
|
| 270 |
-
**License**: Apache 2.0
|
|
|
|
| 28 |
- type: f1
|
| 29 |
value: 0.9985
|
| 30 |
name: F1 Score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
---
|
| 32 |
|
| 33 |
# FLUX Detector - Vision Transformer
|
|
|
|
| 44 |
- ⚡ **Fast Inference**: ~10ms per image on GPU
|
| 45 |
- 📊 **Well-Validated**: Separate train/val/test splits with no overlap
|
| 46 |
|
| 47 |
+
### Performance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
```
|
| 50 |
+
Test Accuracy: 0.9985
|
| 51 |
+
Precision: 1.0000 (PERFECT!)
|
| 52 |
+
Recall: 0.9970
|
| 53 |
+
F1 Score: 0.9985
|
| 54 |
+
AUC-ROC: 1.0000 (PERFECT!)
|
| 55 |
|
| 56 |
False Positive Rate: 0.0000 (0.0%!)
|
| 57 |
False Negative Rate: 0.0030
|
| 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"FLUX-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/flux-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
|
|
|
|
|
|