Image Classification
Transformers
Safetensors
swin-frequency-hybrid
deepfake-detection
synthetic-image-detection
swin-transformer
frequency-analysis
Instructions to use SadraCoding/SDXL-Deepfake-Detector with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use SadraCoding/SDXL-Deepfake-Detector with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="SadraCoding/SDXL-Deepfake-Detector") pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# pip install -U transformers accelerate # Load model directly from transformers import SwinFrequencyHybridDetector model = SwinFrequencyHybridDetector.from_pretrained("SadraCoding/SDXL-Deepfake-Detector", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Commit ·
bd289c2
1
Parent(s): 270c326
README Update
Browse files
README.md
CHANGED
|
@@ -12,54 +12,88 @@ base_model: Organika/sdxl-detector
|
|
| 12 |
|
| 13 |
# Spatial–Frequency Hybrid Detector for Synthetic Face Images
|
| 14 |
|
| 15 |
-
This repository contains a fine-tuned checkpoint for binary image classification.
|
| 16 |
|
| 17 |
-
> **Experimental research model.** This
|
| 18 |
|
| 19 |
-
##
|
| 20 |
|
| 21 |
-
-
|
| 22 |
-
-
|
| 23 |
-
-
|
| 24 |
-
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
## Model details
|
| 27 |
|
| 28 |
-
The model
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
| ID | Label |
|
| 33 |
| --- | --- |
|
| 34 |
| 0 | `artificial` |
|
| 35 |
| 1 | `human` |
|
| 36 |
|
| 37 |
-
|
| 38 |
|
| 39 |
## Intended use and limitations
|
| 40 |
|
| 41 |
-
The project references the Kaggle 140k Real and Fake Faces collection,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
|
| 47 |
## Using the checkpoint
|
| 48 |
|
| 49 |
-
This checkpoint uses
|
| 50 |
|
| 51 |
```bash
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
python scripts/predict.py --image /path/to/image.jpg
|
| 53 |
```
|
| 54 |
|
| 55 |
-
The script selects CUDA when available
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
## Training
|
| 58 |
|
| 59 |
-
The
|
|
|
|
|
|
|
| 60 |
|
| 61 |
## License and attribution
|
| 62 |
|
| 63 |
-
The project declares MIT for its original code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Spatial–Frequency Hybrid Detector for Synthetic Face Images
|
| 14 |
|
| 15 |
+
This repository contains a fine-tuned checkpoint for binary image classification. It predicts whether an input image belongs to the `artificial` or `human` class. The project combines a Swin image-classification backbone with a learned representation of the image's centered two-dimensional Fourier log-magnitude spectrum.
|
| 16 |
|
| 17 |
+
> **Experimental research model.** This is a classifier, not an authenticity or provenance verifier. Its output does not establish who created an image, whether a face is real, whether an image was manipulated, or whether a person consented to its use. Do not use it as the sole basis for consequential decisions.
|
| 18 |
|
| 19 |
+
## Project links
|
| 20 |
|
| 21 |
+
- [GitHub source, training and evaluation scripts](https://github.com/SadraCoding/SDXL-Deepfake-Detector)
|
| 22 |
+
- [Technical report](https://github.com/SadraCoding/SDXL-Deepfake-Detector/blob/main/REVISED_PROJECT_REPORT.md)
|
| 23 |
+
- [Research protocol](https://github.com/SadraCoding/SDXL-Deepfake-Detector/blob/main/docs/research_protocol.md)
|
| 24 |
+
- [Live demo](https://sdxldd.ir)
|
| 25 |
+
- [Base checkpoint: Organika/sdxl-detector](https://huggingface.co/Organika/sdxl-detector)
|
| 26 |
+
- [Dataset cited by the project: 140k Real and Fake Faces](https://www.kaggle.com/datasets/xhlulu/140k-real-and-fake-faces)
|
| 27 |
|
| 28 |
## Model details
|
| 29 |
|
| 30 |
+
The model uses pooled spatial features from the Swin backbone and a 128-dimensional feature vector learned from the centered FFT log-magnitude representation. It concatenates these features and classifies them with a fusion head. An auxiliary classifier on the Swin features is trained with an additional loss. The checkpoint's class mapping is:
|
| 31 |
|
| 32 |
+
| Class ID | Label |
|
|
|
|
|
|
|
| 33 |
| --- | --- |
|
| 34 |
| 0 | `artificial` |
|
| 35 |
| 1 | `human` |
|
| 36 |
|
| 37 |
+
The image processor resizes images to 224 × 224, rescales pixel values, and applies ImageNet channel normalization. The checkpoint also includes an optional confidence-based early-exit path: with adaptive inference enabled, predictions at or above the configured confidence threshold (default 0.90) use the auxiliary Swin head; less confident samples use the full spatial–frequency path. A softmax score is not a calibrated probability unless calibration has been measured separately.
|
| 38 |
|
| 39 |
## Intended use and limitations
|
| 40 |
|
| 41 |
+
The project references the Kaggle 140k Real and Fake Faces collection, commonly described as real face images and StyleGAN-generated faces. This is a narrow face-image domain. It does not establish performance on face swaps, video, SDXL or other unseen generators, or arbitrary images in the wild. The checkpoint does not include enough dataset version, split construction, and run provenance to reproduce or independently validate its reported result.
|
| 42 |
+
|
| 43 |
+
The checked-in GitHub metrics artifact reports one evaluation on 10,905 images. It reports 93.27% clean accuracy for both full and adaptive inference. These are historical results from a run with incomplete provenance, not evidence of generalization. The project Hugging Face page has also displayed a self-reported 97% accuracy; the evaluation details do not establish that it is directly comparable to the checked-in metrics. Do not combine or compare those figures as if they came from the same protocol.
|
| 44 |
+
|
| 45 |
+
The metrics artifact reports the following accuracy and weighted F1 for its clean test set and four synthetic corruption variants:
|
| 46 |
|
| 47 |
+
| Evaluation variant | Accuracy (full / adaptive) | Weighted F1 |
|
| 48 |
+
| --- | ---: | ---: |
|
| 49 |
+
| Clean | 93.27% / 93.27% | 93.26% |
|
| 50 |
+
| JPEG quality 50 | 91.30% / 91.30% | 91.25% |
|
| 51 |
+
| 5 × 5 Gaussian blur | 92.86% / 92.86% | 92.85% |
|
| 52 |
+
| Half resolution, resized back | 92.11% / 92.11% | 92.11% |
|
| 53 |
+
| Gaussian noise, σ = 15 | 91.24% / 91.24% | 91.23% |
|
| 54 |
|
| 55 |
+
These controlled degradations are not a comprehensive robustness test. The metrics artifact omits the dataset revision, split construction, per-source support, GPU model, software versions, checkpoint hash, and threshold-selection procedure. Adaptive and full modes had the same reported labels for these variants; the recorded adaptive early-exit rates were approximately 98.4–99.1%. The repository has not demonstrated that frequency fusion improves performance over a matched Swin-only baseline.
|
| 56 |
+
|
| 57 |
+
Potential dataset shortcuts, identity or duplicate overlap, source-specific artifacts, compression, preprocessing, demographic coverage, and distribution shift can affect predictions. The project is not a universal deepfake detector. See the linked [technical report](https://github.com/SadraCoding/SDXL-Deepfake-Detector/blob/main/REVISED_PROJECT_REPORT.md) and [research protocol](https://github.com/SadraCoding/SDXL-Deepfake-Detector/blob/main/docs/research_protocol.md) for detailed caveats and recommendations for controlled evaluation.
|
| 58 |
|
| 59 |
## Using the checkpoint
|
| 60 |
|
| 61 |
+
This checkpoint uses the project's custom `SwinFrequencyHybridDetector` architecture; it cannot be loaded as a standard `AutoModelForImageClassification` without the custom model code. Clone the GitHub repository, install the dependencies and a PyTorch/torchvision build for your platform, then run inference from the `model/` directory:
|
| 62 |
|
| 63 |
```bash
|
| 64 |
+
git clone https://github.com/SadraCoding/SDXL-Deepfake-Detector.git
|
| 65 |
+
cd SDXL-Deepfake-Detector
|
| 66 |
+
python -m pip install -r model/scripts/requirements.txt
|
| 67 |
+
cd model
|
| 68 |
python scripts/predict.py --image /path/to/image.jpg
|
| 69 |
```
|
| 70 |
|
| 71 |
+
The script loads the bundled fine-tuned checkpoint from `model/SDXL-Deepfake-Detector/`, selects CUDA when available (otherwise CPU), and reports the predicted label, confidence, adaptive-path status, model-call latency, and descriptive image-quality measurements. Adaptive inference is off by default. Enable it with `--adaptive`; optionally set `--confidence_threshold` to a value in `(0, 1]`. The threshold should be selected on validation data and frozen before test evaluation.
|
| 72 |
+
|
| 73 |
+
To evaluate a class-folder test set, use `python scripts/evaluate.py --test_dir ./dataset/test` from `model/`. The evaluator reports full and adaptive results and applies the synthetic corruption procedures described above. For training, arrange data in `dataset/train/{fake,real}/` and `dataset/val/{fake,real}/`, then run `python scripts/train.py --train_dir ./dataset/train --val_dir ./dataset/val`. The scripts do not download or arrange the dataset, validate split integrity, or establish that a split is leakage-free. Consult the GitHub README for complete options and defaults.
|
| 74 |
+
|
| 75 |
+
The dataset is not included. The GitHub project describes obtaining it separately from Kaggle and arranging it into `train/{fake,real}`, `val/{fake,real}`, and `test/{fake,real}` directories (`fake → artificial`, `real → human`). Review the current dataset terms, image rights, and privacy requirements before use. Keep credentials, restricted data, and identifiable examples out of public repositories.
|
| 76 |
|
| 77 |
+
## Training and evaluation context
|
| 78 |
|
| 79 |
+
The reported training hardware is one NVIDIA RTX 3060 with 12 GB VRAM. The repository's training defaults are 10 epochs, batch size 32, learning rate `2e-5`, weight decay 0.01, preprocessing chunk size 20,000, seed 42, and confidence threshold 0.90. Training uses horizontal flips, rotations up to 15 degrees, and brightness/contrast jitter; validation preprocessing is deterministic. These are implementation defaults, not tuned or statistically validated settings. The requirements specify minimum package versions rather than a locked environment.
|
| 80 |
+
|
| 81 |
+
For research use, preserve the exact code revision, checkpoint and processor hashes, dataset revision and split manifest, commands, resolved software versions, hardware, seeds, and threshold-selection procedure. Prefer identity/source-aware splits, check for duplicates and leakage, keep test data untouched during model and threshold selection, compare against a matched Swin-only baseline, and report uncertainty and per-class metrics. The [research protocol](https://github.com/SadraCoding/SDXL-Deepfake-Detector/blob/main/docs/research_protocol.md) provides a fuller checklist.
|
| 82 |
|
| 83 |
## License and attribution
|
| 84 |
|
| 85 |
+
The project declares MIT for its original code. That license does not grant rights to third-party model weights or dataset images. The upstream [`Organika/sdxl-detector`](https://huggingface.co/Organika/sdxl-detector) model card identifies a CC BY-NC 3.0 license and non-commercial restrictions; review its current terms before using or redistributing this derived checkpoint. The Kaggle dataset has separate terms and upstream image-rights considerations. Face data may also be subject to privacy, consent, and institutional requirements.
|
| 86 |
+
|
| 87 |
+
Suggested attribution:
|
| 88 |
+
|
| 89 |
+
- SadraCoding, [SDXL-Deepfake-Detector](https://github.com/SadraCoding/SDXL-Deepfake-Detector), source code and research artifacts.
|
| 90 |
+
- Organika, [SDXL Detector](https://huggingface.co/Organika/sdxl-detector), upstream checkpoint.
|
| 91 |
+
- xhlulu, [140k Real and Fake Faces](https://www.kaggle.com/datasets/xhlulu/140k-real-and-fake-faces), Kaggle dataset.
|
| 92 |
+
|
| 93 |
+
For formal work, record immutable model revisions and access dates, and cite the relevant dataset and model documentation.
|
| 94 |
+
|
| 95 |
+
## References
|
| 96 |
|
| 97 |
+
1. Liu, Z. et al. (2021). “Swin Transformer: Hierarchical Vision Transformer using Shifted Windows.” *ICCV*. [DOI](https://doi.org/10.1109/ICCV48922.2021.00986).
|
| 98 |
+
2. Frank, J. et al. (2020). “Leveraging Frequency Analysis for Deep Fake Image Recognition.” [arXiv:2003.08685](https://arxiv.org/abs/2003.08685).
|
| 99 |
+
3. Byun, J. Y. et al. (2026). “Adaptive Inference for Medical Vision Transformers: Token Reduction or Early Exit?” *Proceedings of the 9th International Conference on Medical Imaging with Deep Learning*, PMLR 315:2171–2191. [Proceedings](https://proceedings.mlr.press/v315/byun26b.html). This provides methodological context; its medical-dataset findings are not directly comparable to this project.
|