OpenFake SwinV2 generator-attribution head
Says which image generator likely made an AI-generated image, on top of the OpenFake SwinV2-base detector. The detector stays frozen; this repo adds a small linear head (1024 → 256) trained on its pooled features. One forward pass returns:
p_fake: the detector's own real/fake probability, unchangedfamily: the nearest of 15 known generator familiesmodel: the nearest of 47 known model checkpointsfamily_similarityandis_novel: how close the image is to any known family, and whether that is below a calibrated threshold (a likely unseen generator)
New generators can be added from a few example images with enroll(), without
retraining.
Attribution assumes the image is AI-generated. Check p_fake first: the head
will name a generator for a real photo too.
Usage
Download attribution.py from this repo, then:
from huggingface_hub import hf_hub_download
from PIL import Image
import importlib.util, sys
path = hf_hub_download("bendavidsteel/openfake-swinv2-base-attribution-head", "attribution.py")
spec = importlib.util.spec_from_file_location("attribution", path)
attribution = importlib.util.module_from_spec(spec); spec.loader.exec_module(attribution)
model = attribution.OpenFakeAttribution.from_pretrained(
"bendavidsteel/openfake-swinv2-base-attribution-head")
print(model([Image.open("image.jpg")]))
# one dict per image, with keys:
# p_fake, family, family_similarity, model, is_novel
# add a generator the head has never seen, from a few of its images
model.enroll("my-new-generator", [Image.open(p) for p in example_paths])
print(model.attribute_enrolled([Image.open("image.jpg")]))
Requires torch, transformers, huggingface_hub and safetensors.
Known families
| Family | Model checkpoints in training |
|---|---|
| Chroma | chroma |
| DALLE3 | dalle-3 |
| FLUX1 | flux.1-dev, flux.1-schnell, flux-1.1-pro, flux-realism, flux-mvc5000, flux-amateursnapshotphotos |
| GPT-Image | gpt-image-1 |
| Grok | grok-2-image-1212 |
| HiDream | hidream-i1-full |
| Ideogram | ideogram-3.0 |
| Imagen | imagen-3.0-002, imagen-4.0 |
| Midjourney | midjourney-6 |
| Mystic | mystic |
| SD1 | sd-1.5, stable-diffusion-v1-4, stable-diffusion-v1-5, sd-turbo, sd-1.5-dreamshaper |
| SD2 | sd-2.1 |
| SD3 | sd-3.5 |
| SDXL | sdxl, sdxl-1.0, stable-diffusion-xl-base-1.0, sd-xl-v1.0-vae-fix, sdxl-turbo, and community fine-tunes (Juggernaut, RealVis, Animagine, CyberRealistic Pony, Playground v2.5, Kolors, …); also sd-1.5-epicdream and realistic_vision_v5.1_novae (see below) |
| Sana | tiny-random-sana |
Families are the unit the head is built to separate: a fine-tune or LoRA
usually inherits its base model's decoder fingerprint. The model output is
finer but less reliable, especially between fine-tunes of the same base.
Two SD 1.5 fine-tunes, sd-1.5-epicdream and realistic_vision_v5.1_novae,
were labelled SDXL in training by a name-matching rule, so the head reports
their family as SDXL. Their model labels are correct. OpenFake's only Sana images come from tiny-random-sana, a small test
checkpoint, so the Sana family does not represent the released Sana models.
Evaluation
All numbers are on OpenFake. Known-family numbers come from held-out images whose prompts never appear in training. "Compressed" means each image went through a random downscale (0.5–1×) and JPEG re-encode (quality 35–95), which roughly imitates social-media re-upload.
| Clean | Compressed | |
|---|---|---|
| Family accuracy, 15 known families | 0.76 | 0.73 |
Known-family images flagged is_novel | 4.5% | 5.6% |
Unseen-generator images flagged is_novel | 21% | 23% |
| Novelty AUROC (known vs unseen) | 0.81 | 0.79 |
Unseen generators, 5-shot enroll() accuracy (7-way) | 0.54 | 0.47 |
Unseen generators, 100-shot enroll() accuracy (7-way) | 0.66 | 0.61 |
Unseen generators are the seven families in OpenFake's test split that never appear in training: ERNIE, FLUX.2, Lumina, Nano Banana, Recraft, Seedream and Z-Image. Chance is 1/15 for known families and 1/7 for enrollment.
is_novel is a weak signal. The threshold is set so about 5% of images from
known families are flagged; at that setting it catches only about one in five
images from unseen generators. A flagged image is worth a closer look; an
unflagged one may still come from a generator the head has never seen. Use
family_similarity directly if you need a different trade-off.
Compared on the same protocol under compression, nearest-prototype attribution
on the frozen detector features alone reaches 0.52 family accuracy and 0.60
novelty AUROC; the head raises both.
For enrolling new generators, the frozen features and the head embedding do
about equally well under compression, so enroll() uses the frozen features.
Limitations
- File properties are a strong shortcut on OpenFake. A classifier given only width, height, file format and file size reaches 0.59 accuracy on the known families. The compressed numbers above are the better guide to performance on re-uploaded images, and real platforms change images in ways the augmentation does not cover.
- Whole-image generation only. The training data is text-to-image output. Partial edits (inpainting, face swaps, lip-sync on real video) are outside what the head has seen, and the base detector is weak on them too.
- Closed vocabulary. A generator outside the 15 families gets the nearest
known label. Check
is_novelandfamily_similarity, and enroll new generators when you have examples.
Training
- Features: the base detector's pooled SwinV2 output, L2-normalised, from up to 1,500 images per family (9,684 in total). Each image contributes a clean and a compressed view.
- Head:
Linear(1024, 256)+BatchNorm1d, trained with sub-center ArcFace (3 sub-centres, margin 0.3, scale 30) on the 47 model-string labels for 40 epochs (AdamW, one-cycle LR, peak 1e-3). - Family prototypes: mean head embedding of each family's training images (both
views).
familyis the nearest prototype by cosine similarity. - Novelty threshold: the 5th percentile of
family_similarityover held-out known-family images, clean and compressed pooled (0.243).
Four head variants were compared: linear or MLP, with family or model-string labels. This one gave the best balance across known-family accuracy, novelty detection and enrollment of unseen generators.
Licence and citation
CC-BY-NC-4.0, inherited from the OpenFake dataset and the base detector. Non-commercial use only.
@misc{livernoche2025openfakeopendatasetplatform,
title={OpenFake: An Open Dataset and Platform Toward Real-World Deepfake Detection},
author={Victor Livernoche and Akshatha Arodi and Andreea Musulan and Zachary Yang and Adam Salvail and Gaétan Marceau Caron and Jean-François Godbout and Reihaneh Rabbany},
year={2025},
eprint={2509.09495},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2509.09495},
}