Image Classification
Transformers
Safetensors
PyTorch
English
Chinese
beit
ai-detection
ai-image-detection
deepfake-detection
fake-image-detection
ai-art-detection
stable-diffusion-detection
midjourney-detection
dall-e-detection
image-forensics
digital-art-verification
vit
computer-vision
Eval Results (legacy)
Instructions to use boluobobo/ItsNotAI-ai-detector-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use boluobobo/ItsNotAI-ai-detector-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="boluobobo/ItsNotAI-ai-detector-v1") pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# Load model directly from transformers import AutoImageProcessor, AutoModelForImageClassification processor = AutoImageProcessor.from_pretrained("boluobobo/ItsNotAI-ai-detector-v1") model = AutoModelForImageClassification.from_pretrained("boluobobo/ItsNotAI-ai-detector-v1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -164,39 +164,51 @@ def detect_image(image_path):
|
|
| 164 |
outputs = model(**inputs)
|
| 165 |
probs = torch.softmax(outputs.logits, dim=-1)[0]
|
| 166 |
|
| 167 |
-
#
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
return {
|
| 183 |
-
"ai_probability": ai_prob,
|
| 184 |
-
"human_probability": human_prob,
|
| 185 |
-
"
|
|
|
|
|
|
|
| 186 |
}
|
| 187 |
|
| 188 |
# Example
|
| 189 |
result = detect_image("test.jpg")
|
| 190 |
print(f"AI Probability: {result['ai_probability']:.1%}")
|
| 191 |
print(f"Human Probability: {result['human_probability']:.1%}")
|
| 192 |
-
print(f"
|
|
|
|
| 193 |
```
|
| 194 |
|
| 195 |
**Example Output:**
|
| 196 |
```json
|
| 197 |
{
|
| 198 |
-
"ai_probability": 0.
|
| 199 |
-
"human_probability": 0.
|
|
|
|
|
|
|
| 200 |
"top3_sources": [
|
| 201 |
{"label": "stable_diffusion", "score": 0.452},
|
| 202 |
{"label": "latent_diffusion", "score": 0.213},
|
|
@@ -283,14 +295,21 @@ for i, (name, prob) in enumerate(zip(source_names, probs[0].tolist())):
|
|
| 283 |
### Calculate Real vs Fake Probability
|
| 284 |
|
| 285 |
```python
|
| 286 |
-
#
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
print(f"Real: {real_prob:.2%}")
|
| 295 |
print(f"AI Generated: {fake_prob:.2%}")
|
| 296 |
```
|
|
|
|
| 164 |
outputs = model(**inputs)
|
| 165 |
probs = torch.softmax(outputs.logits, dim=-1)[0]
|
| 166 |
|
| 167 |
+
# Top-1 决定 + 置信度
|
| 168 |
+
top_idx = probs.argmax().item()
|
| 169 |
+
top_source = model.config.id2label[str(top_idx)]
|
| 170 |
+
top_confidence = probs[top_idx].item()
|
| 171 |
+
is_real = top_source in REAL_LABELS
|
| 172 |
+
|
| 173 |
+
if is_real:
|
| 174 |
+
human_prob = top_confidence
|
| 175 |
+
ai_prob = 1.0 - human_prob
|
| 176 |
+
else:
|
| 177 |
+
ai_prob = top_confidence
|
| 178 |
+
human_prob = 1.0 - ai_prob
|
| 179 |
+
|
| 180 |
+
# Get top 3 AI sources
|
| 181 |
+
ai_sources = []
|
| 182 |
+
for i, prob in enumerate(probs.tolist()):
|
| 183 |
+
label = model.config.id2label[str(i)]
|
| 184 |
+
if label not in REAL_LABELS:
|
| 185 |
+
ai_sources.append({"label": label, "score": round(prob, 3)})
|
| 186 |
+
ai_sources.sort(key=lambda x: x["score"], reverse=True)
|
| 187 |
+
top3_sources = ai_sources[:3]
|
| 188 |
|
| 189 |
return {
|
| 190 |
+
"ai_probability": round(ai_prob, 3),
|
| 191 |
+
"human_probability": round(human_prob, 3),
|
| 192 |
+
"predicted_source": top_source,
|
| 193 |
+
"is_real": is_real,
|
| 194 |
+
"top3_sources": top3_sources
|
| 195 |
}
|
| 196 |
|
| 197 |
# Example
|
| 198 |
result = detect_image("test.jpg")
|
| 199 |
print(f"AI Probability: {result['ai_probability']:.1%}")
|
| 200 |
print(f"Human Probability: {result['human_probability']:.1%}")
|
| 201 |
+
print(f"Predicted Source: {result['predicted_source']}")
|
| 202 |
+
print(f"Is Real: {result['is_real']}")
|
| 203 |
```
|
| 204 |
|
| 205 |
**Example Output:**
|
| 206 |
```json
|
| 207 |
{
|
| 208 |
+
"ai_probability": 0.452,
|
| 209 |
+
"human_probability": 0.548,
|
| 210 |
+
"predicted_source": "stable_diffusion",
|
| 211 |
+
"is_real": false,
|
| 212 |
"top3_sources": [
|
| 213 |
{"label": "stable_diffusion", "score": 0.452},
|
| 214 |
{"label": "latent_diffusion", "score": 0.213},
|
|
|
|
| 295 |
### Calculate Real vs Fake Probability
|
| 296 |
|
| 297 |
```python
|
| 298 |
+
# Top-1 决定 + 置信度
|
| 299 |
+
top_idx = probs[0].argmax().item()
|
| 300 |
+
top_source = source_names[top_idx]
|
| 301 |
+
top_confidence = probs[0][top_idx].item()
|
| 302 |
+
is_real = source_is_real.get(top_source, False)
|
| 303 |
+
|
| 304 |
+
if is_real:
|
| 305 |
+
real_prob = top_confidence
|
| 306 |
+
fake_prob = 1.0 - real_prob
|
| 307 |
+
else:
|
| 308 |
+
fake_prob = top_confidence
|
| 309 |
+
real_prob = 1.0 - fake_prob
|
| 310 |
+
|
| 311 |
+
print(f"Predicted Source: {top_source}")
|
| 312 |
+
print(f"Is Real: {'Yes' if is_real else 'No (AI Generated)'}")
|
| 313 |
print(f"Real: {real_prob:.2%}")
|
| 314 |
print(f"AI Generated: {fake_prob:.2%}")
|
| 315 |
```
|