AlexNet β€” AI vs Human Image Detector

Binary classifier fine-tuned from ImageNet AlexNet to detect whether an image was generated by AI or captured/created by a human.

How to Use

import torch
import torch.nn as nn
from torchvision import models, transforms
from torchvision.models import AlexNet_Weights
from PIL import Image
from huggingface_hub import hf_hub_download

# Rebuild the model architecture
model = models.alexnet(weights=None)
model.classifier = nn.Sequential(
    nn.Dropout(p=0.5),
    nn.Linear(9216, 4096), nn.ReLU(inplace=True),
    nn.Dropout(p=0.5),
    nn.Linear(4096, 4096), nn.ReLU(inplace=True),
    nn.Linear(4096, 1),
)

# Load weights from HF
weights_path = hf_hub_download(
    repo_id="your-username/alexnet-ai-vs-human",
    filename="alexnet_phase2_best.pth"
)
model.load_state_dict(torch.load(weights_path, map_location="cpu"))
model.eval()

# Inference
transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.ToTensor(),
    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
])

img = Image.open("your_image.jpg").convert("RGB")
with torch.no_grad():
    prob = torch.sigmoid(model(transform(img).unsqueeze(0))).item()

print("AI" if prob > 0.5 else "Human", f"({prob:.2%} confidence)")
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Space using SeifElden2342532/AI_VS_Human 1