DetecAI — DINOv2 edited-region localization
Research model for predicting image regions edited using generative AI. Uses DINOv2-Base with a multi-layer feature decoder and a high-resolution detail stem. This is a custom PyTorch model; use the supplied loader rather than AutoModel.from_pretrained on this repository.
Inference
Install requirements.txt. Download inference.pt and detecai_predict.py into the same directory, then:
from PIL import Image
from detecai_predict import load_detector, predict_region
model, config = load_detector('inference.pt')
result = predict_region(model, config, 'photo.jpg')
Image.fromarray(result['mask']).save('mask.png')
print(result['edited_fraction'])
White pixels mark predicted edits. edited_fraction is the predicted image-area fraction, not a calibrated probability of AI authorship. GPU and CPU paths are supported by the loader; latency depends on the hosting hardware.
Web demo
app.py uses the same loader and preprocessing as the exported checkpoint: 644px, bilinear resize, device-aware inference and calibrated threshold 0.45. Run python app.py after installing requirements. The model is loaded on the first request and checksum-verified. The UI reports predicted regions, not proof of AI authorship.
Set DETECAI_MODEL_DIR to a directory containing inference.pt and detecai_predict.py to use local files. Otherwise the app downloads the pinned export from this repository; a private repository requires an authorized HF_TOKEN environment secret. Never put tokens in source code. Set DETECAI_SHARE=1 only when a temporary public Gradio link is intended. A model repository stores the files; it does not run the demo. Hosting in a Space requires a separate runtime.
Selected checkpoint
- Training stage3; selected epoch29.
- Input644×644; pixel threshold0.45.
- Backbone: facebook/dinov2-base.
- Training data: BRGen COCO training partition plus custom ChatGPT edits and authentic source images.
- Custom source groups:167 train,36 validation,36 test. Variants of one source image share a split.
Reported custom group-test results
| Image condition | Mean per-image IoU | Small-region IoU | Authentic-image false positive rate |
|---|---|---|---|
| Original | 0.6247 | 0.5030 | 0/36 |
| JPEG95 | 0.6270 | 0.5085 | 0/36 |
| JPEG85 | 0.6284 | 0.5112 | 0/36 |
Test contains74 edited images and36 authentic images. This same test was evaluated after multiple development stages; results should not be interpreted as an untouched external final holdout. No automated test-score-based checkpoint selection was found in the reviewed notebook. A fresh external holdout is needed to confirm generalization. Custom reference masks were generated after editing and remain approximate, requiring manual review. Zero false positives in36 examples does not establish a zero population error rate.
Use and limitations
Intended for academic experimentation and thesis demonstrations. Predictions are imperfect and should not be treated as proof that a particular image is authentic or AI-edited. The training dataset itself is not included. Check applicable backbone and dataset terms before downstream use; this model card does not grant new rights to underlying datasets.