🚀 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許可證。
⚠️ 重要提示
- 該模型在清晰、高質量的圖像上表現最佳。
- 對於經過大量編輯的照片,模型的準確性可能會降低。
- 該模型設計用於一般的圖像檢測。
開發者信息