DenseNet121 AI Image and Real Photo Classifier
2 min readupdated
This model handles binary image classification, determining whether a picture is AI-generated (fake) or a real photograph (real). Built on the DenseNet121 architecture, it is trained using specialized degradation augmentation to prevent false positives on compressed or blurred shots. It fixes the shortcut learning issue where models previously mistook sharpness for a sign of reality. This release is useful for developers and researchers who need a reliable fake detector robust against JPEG compression.
Key features
- Binary image classification into fakes and real photos
- Robustness against blur, noise, and JPEG compression
- High quality metrics (AUC test of 0.9807 on clean data)
- Strict preprocessing pipeline included for precise inference
What you can do
- Integrate the detector into a web service or Telegram bot to check user-uploaded images
- Use it in spam and fake content filtering pipelines on social networks
- Test your own datasets for generation artifacts
Example
from safetensors.torch import load_file
import torch, torch.nn as nn
from torchvision import models
model = models.densenet121(weights=None)
model.classifier = nn.Sequential(
nn.Dropout(0.3), nn.Linear(model.classifier.in_features, 2))
model.load_state_dict(load_file('model.safetensors'))
model.eval()
p_real = torch.softmax(model(x), 1)[0, 1].item()
label = 'real' if p_real >= 0.4667 else 'fake'Read more
DetailsAUC test clean: 0.9807, Accuracy: 0.9306
AUC test (JPEG q50): 0.9758, Real class recall: 0.9143
Limitations: does not work with screenshots, drawings, or rare generators
Trained on 24,000 images per class from the Kaggle dataset










Comments