Swin-FFT AI Image Detector
Binary image classifier: AI-generated vs real. It is fine-tuned from umm-maybe/AI-image-detector on the ArtiFact dataset.
Model
- Backbone: the pretrained Swin backbone of the base model (its original classifier was replaced)
- Frequency branch: grayscale image, Hann-windowed 2D FFT, log-magnitude spectrum, small CNN, 128-d vector
- Head: the Swin and frequency features are concatenated, then dropout (0.1) and a linear layer with 2 outputs
Frequency (FFT) branch
The Swin backbone learns from the RGB image. The second branch looks at the same picture in the frequency domain, which describes how intensity changes across space: low frequencies correspond to smooth, large-scale structure, and high frequencies to edges, texture and noise. The motivation is that image generators can leave patterns in the spectrum, such as periodic peaks from upsampling or unusual high-frequency energy, that are hard to see in the image itself. Such patterns vary between generators and can be weakened by compression or resizing.
Steps:
- Grayscale input with values in [0, 1].
- Mean removal: subtract the image mean to suppress the constant (DC) component.
- Hann window: taper the image borders to reduce spectral leakage caused by edge discontinuities.
- 2D FFT, then
fftshiftto move the zero frequency to the center. - Log magnitude:
log(1 + |F|)compresses the large dynamic range. Phase is discarded. - Per-image standardization to zero mean and unit standard deviation.
- Small CNN: four blocks of 3x3 convolution (stride 2), batch normalization and ReLU, with 32, 64, 128 and 128 channels.
- Global average pooling gives a 128-dimensional vector.
Steps 2-6 are fixed operations with no trainable parameters. The CNN has about 241K parameters and is trained jointly with the backbone. Its 128 features are concatenated with the 1024 Swin features (1152 in total) before the classification head.
RGB image ββ> Swin backbone βββββββββββββββββββββββββββββ> 1024 ββ
ββ> dropout β> linear β> AI / real
grayscale ββ> Hann + FFT ββ> log magnitude ββ> small CNN β> 128 ββ
The contribution of this branch has not been reported here: no comparison with a Swin-only model is included, so no accuracy gain is claimed for it.
Code and usage
π§ The project source code, GitHub link and usage code are coming soon on GitHub.
Until then, only the weights are available. This is a custom model, so from_pretrained /
pipeline() alone will not load it correctly.
- Output index 0 = AI-generated, index 1 = real.
- Preprocessing: convert to RGB and resize directly to 224x224 (bicubic). The Swin input uses ImageNet mean/std normalization. The frequency branch takes the grayscale version of the resized image, before ImageNet normalization.
Dataset
ArtiFact (Kaggle download). According to its authors, the full dataset has 2,496,738 images (964,989 real and 1,531,749 fake) at 200x200, from 8 real-image sources and 25 generators, including GAN and diffusion models.
These are figures for the full dataset, not the number of images used for training. The validation split used here has 124,830 images.
Training
| Setting | Value |
|---|---|
| GPU | NVIDIA RTX 3060 12GB |
| Epochs | 3 |
| Batch size | 32 |
| Optimizer | AdamW (weight decay 0.05) |
| Learning rate | 1e-5 (backbone), 1e-4 (head and frequency branch) |
| Schedule | linear warmup (5% of steps), then cosine decay |
| Precision | bfloat16 autocast |
| Loss | class-weighted cross-entropy |
| Frequency input | resized 224x224 grayscale |
| Augmentation | random horizontal flip |
Validation results
| Metric | Value |
|---|---|
| Loss | 0.0153 |
| ROC AUC | 0.9996 |
| Average precision | 0.9998 |
| Accuracy (threshold 0.5, uncalibrated) | 99.27% |
| TPR at 1% FPR | 99.44% |
These are validation results, not independent test results. No separate test set was used. The validation set was also used to select the checkpoint and to fit the calibration, so the results may be optimistic. Performance on unseen generators or on images outside ArtiFact has not been measured.
Calibration
z = logit_AI - logit_real and P(AI) = sigmoid(z / 2.075 - 0.332).
| Verdict | Condition |
|---|---|
| Likely real | z <= 0.03 |
| Uncertain | 0.03 < z < 4.95 |
| Likely AI-generated | z >= 4.95 |
On validation, expected calibration error went from 0.0062 to 0.0021 (measured on the data used for fitting).
Limitations
- The model can be wrong with high confidence, including when it reports more than 99%.
- Newer generators may not be detected reliably.
- Robustness to screenshots, editing, and additional compression or resizing has not been measured.
- Non-square images are distorted by the direct resize to 224x224.
- Do not use the output as proof that an image is real or fake, or as the only basis for decisions about a person.
License and attribution
To the extent of the author's own rights, these weights are licensed under
CC BY-NC 4.0 (see LICENSE).
Third-party material remains under its own terms.
The backbone was fine-tuned, its original classifier replaced, and an FFT branch added.
- Base model: umm-maybe/AI-image-detector. Check its license terms before using or redistributing these weights. Its notice also prohibits using that model in text-to-image systems to evade AI image detection.
- Dataset: ArtiFact has no single license. Each source has its own terms, and some are non-commercial or listed as unknown. See the ArtiFact repository.
Author
Sadra Milani Moghaddam (SadraCoding)
@misc{milanimoghaddam2026swinfft,
author = {Milani Moghaddam, Sadra},
title = {Swin-FFT AI Image Detector},
year = {2026},
howpublished = {\url{https://huggingface.co/SadraCoding/swin-fft-ai-image-detector}}
}
Citation (ArtiFact)
@inproceedings{rahman2023artifact,
author = {Rahman, Md Awsafur and Paul, Bishmoy and Sarker, Najibul Haque and Hakim, Zaber Ibn Abdul and Fattah, Shaikh Anowarul},
title = {ArtiFact: A Large-Scale Dataset With Artificial And Factual Images For Generalizable And Robust Synthetic Image Detection},
booktitle = {2023 IEEE International Conference on Image Processing (ICIP)},
pages = {2200--2204},
year = {2023},
doi = {10.1109/ICIP49359.2023.10222083}
}
Model tree for SadraCoding/swin-fft-ai-image-detector
Base model
umm-maybe/AI-image-detector