đ AI Image Detector
This AI Image Detector is a powerful tool designed to distinguish between real and AI - generated images. It leverages the Vision Transformer (ViT) architecture to offer accurate classification results.
đ Quick Start
The AI Image Detector can quickly and accurately classify whether an image is real or AI - generated. You can use the provided Python code to start detecting images right away.
⨠Features
- Accurate Classification: Utilizes the Vision Transformer (ViT) architecture for precise image classification.
- Binary Classification: Classifies images into two clear - cut categories: real and AI - generated.
- Confidence Score: Provides a confidence score for each prediction.
đģ Usage Examples
Basic Usage
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("\nImage analysis results:")
print(f"Classification: {result['prediction']}")
print(f"Confidence: {result['confidence']}")
print("\nDetails:")
for score in result['detailed_scores']:
print(f"- {score}")
except Exception as e:
print(f"An error occurred: {str(e)}")
Advanced Usage
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();
}
đ Documentation
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
Property |
Details |
Model Type |
Vision Transformer (ViT) |
Input |
Images (RGB) |
Output |
Binary classification with confidence score |
Max Image Size |
224x224 (automatically resized) |
đĻ Installation
To use this model, you need to install the following dependencies:
transformers>=4.30.0
torch>=2.0.0
Pillow>=9.0.0
â ī¸ Limitations
- Image Quality: The model performs best with clear, high - quality images.
- Edited Photos: Accuracy may be reduced for heavily edited photos.
- General Purpose: It is designed for general image detection.
đ License