yaya36095 commited on
Commit
9d150e2
·
verified ·
1 Parent(s): 0ad0fb4

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +30 -35
README.md CHANGED
@@ -13,39 +13,34 @@ license: mit
13
  This model is designed to detect whether an image is real or AI-generated. It uses Vision Transformer (VIT) architecture to provide accurate classification.
14
 
15
  ## Model Usage
16
-
17
  ```python
18
- ## Classes
19
- The model classifies images into two categories:
20
- - Real Image (0)
21
- - AI Generated (1)
22
-
23
- ## Technical Details
24
- - Model Architecture: Vision Transformer (ViT)
25
- - Input: Images (RGB)
26
- - Output: Binary classification with confidence score
27
- - Max Image Size: 224x224 (automatically resized)
28
-
29
- ## Requirements
30
- - transformers>=4.30.0
31
- - torch>=2.0.0
32
- - Pillow>=9.0.0
33
-
34
- ## Limitations
35
- - Best performance with clear, high-quality images
36
- - May have reduced accuracy with heavily edited photos
37
- - Designed for general image detection
38
-
39
- ## Web Integration Example
40
- ```javascript
41
- async function detectImage(imageFile) {
42
- const formData = new FormData();
43
- formData.append('image', imageFile);
44
-
45
- const response = await fetch('YOUR_API_ENDPOINT', {
46
- method: 'POST',
47
- body: formData
48
- });
49
-
50
- return await response.json();
51
- }
 
13
  This model is designed to detect whether an image is real or AI-generated. It uses Vision Transformer (VIT) architecture to provide accurate classification.
14
 
15
  ## Model Usage
 
16
  ```python
17
+ from transformers import ViTImageProcessor, ViTForImageClassification
18
+ from PIL import Image
19
+ import torch
20
+
21
+ # Load model and processor
22
+ processor = ViTImageProcessor.from_pretrained("yaya36095/ai-image-detector")
23
+ model = ViTForImageClassification.from_pretrained("yaya36095/ai-image-detector")
24
+
25
+ def detect_image(image_path):
26
+ # Open image
27
+ image = Image.open(image_path)
28
+
29
+ # Process image
30
+ inputs = processor(images=image, return_tensors="pt")
31
+
32
+ # Get predictions
33
+ with torch.no_grad():
34
+ outputs = model(**inputs)
35
+ predictions = outputs.logits.softmax(dim=-1)
36
+
37
+ # Get result
38
+ prediction_id = torch.argmax(predictions).item()
39
+ confidence = predictions[0][prediction_id].item() * 100
40
+
41
+ result = "AI Generated" if prediction_id == 1 else "Real Image"
42
+ return result, confidence
43
+
44
+ # Example usage
45
+ # result, confidence = detect_image("path/to/image.jpg")
46
+ # print(f"Result: {result} (Confidence: {confidence:.2f}%)")