File size: 2,982 Bytes
4108d72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
title: Enhanced AI Image Detector
emoji: πŸ”
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 3.50.2
app_file: app.py
pinned: false
---

# Enhanced AI Image Detector

This model detects whether an image is real or AI-generated using a trained PyTorch neural network.

## Model Description

The Enhanced AI Image Detector uses a trained PyTorch neural network to analyze images and determine whether they are authentic photographs or generated by AI tools like DALL-E, Midjourney, or Stable Diffusion.

### Key Features

- **Deep Learning Model**: Uses a convolutional neural network trained on thousands of real and AI-generated images
- **High Accuracy**: Achieves over 85% accuracy in detecting AI-generated content
- **Fast Inference**: Optimized for quick analysis even on CPU-only systems
- **Simple API**: Easy to use with a straightforward Python interface

## How It Works

The model uses a deep convolutional neural network trained on a large dataset of real and AI-generated images. The network learns to detect subtle patterns and artifacts that are characteristic of AI-generated content, including:

1. **Noise and Artifact Patterns**:
   - Specific noise patterns introduced by AI generation methods
   - Artifacts and inconsistencies in image details

2. **Texture Inconsistencies**:
   - Unnatural texture patterns
   - Texture smoothness and regularity

3. **Color and Lighting Anomalies**:
   - Unusual color distributions
   - Lighting inconsistencies

4. **Structural Patterns**:
   - Geometric inconsistencies
   - Unnatural object boundaries
   - Perspective and proportion issues

## Usage

```python
from ai_detector import EnhancedAIDetector

# Initialize the detector with the path to the model file
detector = EnhancedAIDetector(model_path='best_model_improved.pth')

# Analyze an image
result = detector.analyze_image("path/to/image.jpg")

# Check the result
if result["is_ai_generated"]:
    print("This image is likely AI-generated")
    print(f"Confidence score: {result['overall_score']:.2f}")
else:
    print("This image is likely authentic")
    print(f"Confidence score: {1 - result['overall_score']:.2f}")

# View model information
print(f"Model: {result.get('model_name', 'Enhanced AI Image Detector')}")
print(f"Version: {result.get('model_version', '1.0.0')}")
```

## Requirements

- PyTorch
- TorchVision
- OpenCV (cv2)
- NumPy
- PIL (Pillow)

## Limitations

- The model may struggle with highly realistic AI-generated images from newer generation models
- Some real images with unusual characteristics may be misclassified
- Performance depends on image quality and resolution
- The model works best with images similar to those in its training dataset

## Citation

If you use this model in your research or application, please cite:

```
@software{enhanced_ai_detector,
  author = {Your Name},
  title = {Enhanced AI Image Detector},
  year = {2025},
  url = {https://huggingface.co/yourusername/enhanced-ai-detector}
}
```