A binary image classifier that predicts whether an image is
AI-generated
or a
real photograph
, built on an EfficientNet-B0 backbone fine-tuned with PyTorch.
Model Details
Architecture
: EfficientNet-B0 (ImageNet-pretrained backbone), with the last 3 feature blocks fine-tuned and a custom classification head (
Dropout(0.4)
+
Linear
)
Trained on
Parveshiiii/AI-vs-Real
(13,999 images: ~24% AI-generated, ~76% real), split 70/15/15 into train/val/test with stratification. Class imbalance was handled with a
WeightedRandomSampler
during training.
The near-perfect test metrics above should be read with caution. In this dataset, AI-generated and real images cluster at noticeably different resolutions (e.g. AI images concentrated around 1024×1024, real images spanning a wide range down to 178×218). A model can achieve high accuracy by picking up on resolution or compression artifacts correlated with the source, rather than learning genuine visual signatures of AI generation.
In practical testing on out-of-distribution images (photos and AI images not from this dataset), real-world performance may be noticeably lower than these benchmark numbers suggest. Treat this model as a research/demo tool, not a production-grade forensic detector.
Usage
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import models, transforms
from PIL import Image
from huggingface_hub import hf_hub_download
checkpoint_path = hf_hub_download(
repo_id="bsgcasa/ai-vs-real-image-detector",
filename="checkpoint_full.pth"
)
checkpoint = torch.load(checkpoint_path, map_location="cpu", weights_only=False)
class_names = checkpoint["class_names"]
threshold = float(checkpoint["threshold"])
img_size = checkpoint["img_size"]
model = models.efficientnet_b0(weights=None)
in_features = model.classifier[1].in_features
model.classifier = nn.Sequential(nn.Dropout(0.4), nn.Linear(in_features, len(class_names)))
model.load_state_dict(checkpoint["model_state_dict"])
model.eval()
transform = transforms.Compose([
transforms.Resize((img_size, img_size)),
transforms.ToTensor(),
transforms.Normalize(checkpoint["normalize_mean"], checkpoint["normalize_std"]),
])
image = Image.open("your_image.jpg").convert("RGB")
x = transform(image).unsqueeze(0)
with torch.no_grad():
probs = F.softmax(model(x), dim=1)[0]
real_prob = probs[1].item()
prediction = class_names[1] if real_prob >= threshold else class_names[0]
print(prediction, real_prob)
Intended Use
Educational and research purposes — exploring AI-generated image detection approaches. Not intended as a sole or authoritative source for content moderation, journalism verification, or other high-stakes decisions.
License
Apache 2.0
Runs of bsgcasa ai-vs-real-image-detector on huggingface.co
0
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs
More Information About ai-vs-real-image-detector huggingface.co Model
More ai-vs-real-image-detector license Visit here:
ai-vs-real-image-detector huggingface.co is an AI model on huggingface.co that provides ai-vs-real-image-detector's model effect (), which can be used instantly with this bsgcasa ai-vs-real-image-detector model. huggingface.co supports a free trial of the ai-vs-real-image-detector model, and also provides paid use of the ai-vs-real-image-detector. Support call ai-vs-real-image-detector model through api, including Node.js, Python, http.
ai-vs-real-image-detector huggingface.co is an online trial and call api platform, which integrates ai-vs-real-image-detector's modeling effects, including api services, and provides a free online trial of ai-vs-real-image-detector, you can try ai-vs-real-image-detector online for free by clicking the link below.
bsgcasa ai-vs-real-image-detector online free url in huggingface.co:
ai-vs-real-image-detector is an open source model from GitHub that offers a free installation service, and any user can find ai-vs-real-image-detector on GitHub to install. At the same time, huggingface.co provides the effect of ai-vs-real-image-detector install, users can directly use ai-vs-real-image-detector installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
ai-vs-real-image-detector install url in huggingface.co: