🚀 AI图像检测器
本模型旨在检测图像是真实的还是由AI生成的。它采用视觉变换器(ViT)架构,能够提供准确的分类结果。
🚀 快速开始
本模型用于检测图像是否为AI生成,使用视觉变换器(ViT)架构进行准确分类。
✨ 主要特性
- 能够准确检测图像是真实的还是AI生成的。
- 使用视觉变换器(ViT)架构,保证分类的准确性。
💻 使用示例
基础用法
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)}")
高级用法
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();
}
📚 详细文档
模型将图像分为以下两类:
- 真实图像 (0):图像是真实的,并非由AI生成。
- AI生成图像 (1):图像是由AI生成的。
🔧 技术细节
属性 |
详情 |
模型类型 |
视觉变换器(ViT) |
输入 |
图像(RGB) |
输出 |
带有置信度分数的二分类结果 |
最大图像尺寸 |
224x224(自动调整大小) |
📦 安装指南
使用该模型需要安装以下依赖:
transformers>=4.30.0
torch>=2.0.0
Pillow>=9.0.0
📄 许可证
本项目采用MIT许可证。
⚠️ 重要提示
- 该模型在清晰、高质量的图像上表现最佳。
- 对于经过大量编辑的照片,模型的准确性可能会降低。
- 该模型设计用于一般的图像检测。
开发者信息