Downloads · 30 days
2
5% of all-time downloads
shunya510hi/vit-cifar10-classifier
vit-cifar10-classifier is a machine learning model from shunya510hi. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
このモデルは AI生成画像検出用にファインチューニングされた Vision Transformer です。
Downloads · 30 days
2
5% of all-time downloads
All-time downloads
38
Public
Repo size
44.3 MB
Likes
0
Public
Click a slice to open those files.
.bin22.2 MB · 100%
From the Hugging Face model README
このモデルは AI生成画像検出用にファインチューニングされた Vision Transformer です。
| Label | Class |
|---|---|
| 0 | fake (AI生成画像) |
| 1 | real (本物画像) |
import torch
import timm
from PIL import Image
from torchvision import transforms
# モデル読み込み
model = timm.create_model("vit_tiny_patch16_224", pretrained=False, num_classes=2)
state_dict = torch.hub.load_state_dict_from_url(
"https://huggingface.co/shunya510hi/vit-cifar10-classifier/resolve/main/pytorch_model.bin",
map_location="cpu"
)
model.load_state_dict(state_dict)
model.eval()
# 画像前処理
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])
# 推論
image = Image.open("test_image.jpg").convert("RGB")
input_tensor = transform(image).unsqueeze(0)
with torch.no_grad():
output = model(input_tensor)
probabilities = torch.softmax(output, dim=1)
prediction = output.argmax(1).item()
class_names = ["fake", "real"]
print(f"Prediction: {class_names[prediction]}")
print(f"Confidence: {probabilities[0][prediction].item():.2%}")