metadata
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
from transformers import ViTImageProcessor, ViTForImageClassification
from PIL import Image
import torch
# Load model and processor
processor = ViTImageProcessor.from_pretrained("yaya36095/ai-image-detector")
model = ViTForImageClassification.from_pretrained("yaya36095/ai-image-detector")
def detect_image(image_path):
# Open image
image = Image.open(image_path)
# Process image
inputs = processor(images=image, return_tensors="pt")
# Get predictions
with torch.no_grad():
outputs = model(**inputs)
predictions = outputs.logits.softmax(dim=-1)
# Get result
prediction_id = torch.argmax(predictions).item()
confidence = predictions[0][prediction_id].item() * 100
result = "AI Generated" if prediction_id == 1 else "Real Image"
return result, confidence
# Example usage
# result, confidence = detect_image("path/to/image.jpg")
# print(f"Result: {result} (Confidence: {confidence:.2f}%)")
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
markdown