ai-image-detector / README.md
yaya36095's picture
Update README.md
a5b71d8 verified
---
language: en
tags:
- image-classification
- ai-detection
- vit
license: mit
---
# AI Image Detector
## Model Description
This model is designed to detect whether an image is real or AI-generated. It uses Vision Transformer (ViT) architecture to provide accurate classification.
## Model Usage
```python
from transformers import ViTImageProcessor, ViTForImageClassification
from PIL import Image
import torch
# تحميل النموذج والمعالج
processor = ViTImageProcessor.from_pretrained("C:/Users/SUPREME TECH/Desktop/SAM3/ai-image-detector")
model = ViTForImageClassification.from_pretrained("C:/Users/SUPREME TECH/Desktop/SAM3/ai-image-detector")
def detect_image(image_path):
# فتح وتجهيز الصورة
image = Image.open(image_path)
if image.mode != 'RGB':
image = image.convert('RGB')
# معالجة الصورة
inputs = processor(images=image, return_tensors="pt")
# الحصول على التنبؤات
with torch.no_grad():
outputs = model(**inputs)
predictions = outputs.logits.softmax(dim=-1)
# تحليل النتائج
scores = predictions[0].tolist()
results = [
{"label": "REAL", "score": scores[0]},
{"label": "FAKE", "score": scores[1]}
]
# ترتيب النتائج حسب درجة الثقة
results.sort(key=lambda x: x["score"], reverse=True)
return {
"prediction": results[0]["label"],
"confidence": f"{results[0]['score']*100:.2f}%",
"detailed_scores": [
f"{r['label']}: {r['score']*100:.2f}%"
for r in results
]
}
# كود للاختبار
if __name__ == "__main__":
# يمكنك تغيير مسار الصورة هنا
image_path = "path/to/your/image.jpg"
try:
result = detect_image(image_path)
print("\nنتائج تحليل الصورة:")
print(f"التصنيف: {result['prediction']}")
print(f"درجة الثقة: {result['confidence']}")
print("\nالتفاصيل:")
for score in result['detailed_scores']:
print(f"- {score}")
except Exception as e:
print(f"حدث خطأ: {str(e)}")
```
## Classes
The model classifies images into two categories:
- **Real Image (0)**: The image is real and not AI-generated.
- **AI Generated (1)**: The image is generated by AI.
## Technical Details
- **Model Architecture**: Vision Transformer (ViT)
- **Input**: Images (RGB)
- **Output**: Binary classification with confidence score
- **Max Image Size**: 224x224 (automatically resized)
## Requirements
- `transformers>=4.30.0`
- `torch>=2.0.0`
- `Pillow>=9.0.0`
## Limitations
- Best performance with clear, high-quality images.
- May have reduced accuracy with heavily edited photos.
- Designed for general image detection.
## Web Integration Example
```javascript
async function detectImage(imageFile) {
const formData = new FormData();
formData.append('image', imageFile);
const response = await fetch('YOUR_API_ENDPOINT', {
method: 'POST',
body: formData
});
return await response.json();
}
```
## Developer
- **Created by**: yaya36095
- **License**: MIT
- **Repository**: [https://huggingface.co/yaya36095/ai-image-detector](https://huggingface.co/yaya36095/ai-image-detector)