Spaces:
Running
Running
AMontiB
commited on
Commit
·
77570f0
1
Parent(s):
9c4b1c4
update
Browse files- README.md +30 -256
- detectors/P2G/src/.DS_Store +0 -0
README.md
CHANGED
|
@@ -1,272 +1,46 @@
|
|
| 1 |
-
# Image Deepfake Detectors Public Library
|
| 2 |
-
|
| 3 |
-
## Overview
|
| 4 |
-
|
| 5 |
-
This repository provides a unified framework for training, testing, and benchmarking multiple state-of-the-art (SoA) deepfake detection models. It supports automated benchmarking, training, demo runs, and single-image detection, with modular configuration and extensible detector support.
|
| 6 |
-
|
| 7 |
-
### Main Features
|
| 8 |
-
|
| 9 |
-
- **Multiple Detectors:** Supports CLIP-D [1], NPR [2], P2G [3], R50_TF [4], and R50_nodown [5] (an overview for each method is provided in its `README.md`: `./detectors/<DETECTOR>/README.md`)
|
| 10 |
-
- **Pretrained Weights:** All models have been pretrained on images generated with StyleGAN2 and StableDiffusionXL, and real images from the FFHQ Dataset [6] and the FORLAB Dataset [7].
|
| 11 |
-
- **Automated Training & Testing:** Use `launcher.py` to run experiments across detectors and datasets.
|
| 12 |
-
- **Demo Mode:** Easily test all detectors on sample images in `demo_images/`.
|
| 13 |
-
- **Single Image Detection:** Run detection on individual images via the command line.
|
| 14 |
-
- **Flexible Configuration:** All experiment parameters are set via YAML files in `configs/`.
|
| 15 |
-
- **Logging & Results:** Logs and results are saved per detector and scenario for easy analysis.
|
| 16 |
-
|
| 17 |
---
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
---
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
You can download the weights for each model from this [link](https://drive.google.com/file/d/1F60FN2B9skRcb3YrZwhFTZQihbj3ipJQ/view?usp=sharing).
|
| 30 |
-
|
| 31 |
-
Then, copy them into the `pretrained` folder for the corresponding model, following this structure: `./detectors/<DETECTOR>/checkpoint/pretrained/weights/best.pt`
|
| 32 |
-
|
| 33 |
-
---
|
| 34 |
-
|
| 35 |
-
### Download Benchmarking Dataset
|
| 36 |
-
|
| 37 |
-
DeepShield Dataset: [Zenodo link](https://zenodo.org/records/15648378)
|
| 38 |
-
|
| 39 |
-
Download the dataset and change the corresponding `dataset_path` in `./configs/<DETECTOR>.yaml`.
|
| 40 |
-
|
| 41 |
-
> The DeepShield dataset is a large-scale benchmark for evaluating the robustness of fake image detection systems. It contains 100,000 images, divided between real and AI-generated content produced using advanced generative models, including StyleGAN, StyleGAN2, StyleGAN3, Stable Diffusion 1.5, 2.1, 3, and XL, as well as Flux 1.0.
|
| 42 |
-
>
|
| 43 |
-
> To simulate real-world distortions, 30,000 images were shared on Facebook, X (formerly Twitter), and Telegram, then re-collected to include platform-induced compression and artifacts. This approach ensures that the dataset captures authentic distribution noise and artifacts encountered in real-world scenarios.
|
| 44 |
-
|
| 45 |
-
---
|
| 46 |
-
|
| 47 |
-
### VirtualEnv
|
| 48 |
-
|
| 49 |
-
Create a virtual environment using:
|
| 50 |
-
|
| 51 |
-
```bash
|
| 52 |
-
python -m venv IDFD_VENV
|
| 53 |
-
source IDFD_VENV/bin/activate
|
| 54 |
-
pip install -r requirements.txt
|
| 55 |
-
````
|
| 56 |
-
|
| 57 |
-
Or use conda:
|
| 58 |
-
|
| 59 |
-
```bash
|
| 60 |
-
conda env create -f environment.yml
|
| 61 |
-
conda activate IDFD_VENV
|
| 62 |
-
```
|
| 63 |
-
|
| 64 |
-
-----
|
| 65 |
-
|
| 66 |
-
### Download Demo Dataset
|
| 67 |
-
|
| 68 |
-
You can download the demo dataset from this [link](https://drive.google.com/file/d/134Bw8l9tEC7oZJpTAeMO80QRqgdJfJS9/view?usp=sharing). The demo dataset contains 200 images randomly sampled from the DeepShield Dataset.
|
| 69 |
-
|
| 70 |
-
Place sample images for quick testing in `demo_images/`, organized by platform and label:
|
| 71 |
-
|
| 72 |
-
```
|
| 73 |
-
demo_images/
|
| 74 |
-
Facebook/
|
| 75 |
-
Fake/
|
| 76 |
-
Real/
|
| 77 |
-
PreSocial/
|
| 78 |
-
Fake/
|
| 79 |
-
Real/
|
| 80 |
-
Telegram/
|
| 81 |
-
Fake/
|
| 82 |
-
Real/
|
| 83 |
-
X/
|
| 84 |
-
Fake/
|
| 85 |
-
Real/
|
| 86 |
-
```
|
| 87 |
-
|
| 88 |
-
-----
|
| 89 |
-
|
| 90 |
-
## Running Experiments
|
| 91 |
-
|
| 92 |
-
**1. Run Demo:**
|
| 93 |
-
|
| 94 |
-
Test all detectors on sample images:
|
| 95 |
-
|
| 96 |
-
```bash
|
| 97 |
-
python launcher.py --demo --demo-detector all
|
| 98 |
-
```
|
| 99 |
-
|
| 100 |
-
Test a single detector on sample images:
|
| 101 |
-
|
| 102 |
-
```bash
|
| 103 |
-
python launcher.py --demo --demo-detector <DETECTOR>
|
| 104 |
-
```
|
| 105 |
-
|
| 106 |
-
**2. Automated Train-Test (Recommended) on DeepShield Dataset:**
|
| 107 |
|
| 108 |
-
|
| 109 |
|
| 110 |
-
|
| 111 |
-
python launcher.py --detector <DETECTOR> --phases both
|
| 112 |
-
```
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
-
|
| 118 |
|
| 119 |
-
|
|
|
|
|
|
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
| 124 |
|
| 125 |
-
|
| 126 |
-
- `--phases`: `train`, `test`, or `both`
|
| 127 |
-
- `--config-dir`: Path to the detector config files (default: `configs/`)
|
| 128 |
-
- `--weights_name`: Model weights name. The default is defined in `configs/<DETECTOR>.yaml` by these lines:
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
```
|
| 133 |
-
training:
|
| 134 |
-
- data: gan2:pre&sdXL:pre&realFFHQ:pre&realFORLAB:pre
|
| 135 |
-
```
|
| 136 |
-
|
| 137 |
-
This corresponds to the training subsets used to train a detector (see the "Train on Different Generators from the DeepShield Dataset" section for more information).
|
| 138 |
-
|
| 139 |
-
**4. Test the model using pretrained weights on the DeepShield Dataset:**
|
| 140 |
-
|
| 141 |
-
```bash
|
| 142 |
-
python launcher.py --detector <DETECTOR> --phases test --weights_name pretrained
|
| 143 |
-
```
|
| 144 |
-
|
| 145 |
-
**5. Train the model using a custom weights name on the DeepShield Dataset:**
|
| 146 |
-
|
| 147 |
-
```bash
|
| 148 |
-
python launcher.py --detector <DETECTOR> --phases train --weights_name <WEIGHTS_NAME>
|
| 149 |
-
```
|
| 150 |
-
|
| 151 |
-
**6. Perform Detection on Single Images:**
|
| 152 |
-
|
| 153 |
-
```bash
|
| 154 |
-
python launcher.py --detect --detector <DETECTOR> --image <PATH_TO_IMAGE> --weights <WEIGHTS_NAME> --output <OUTPUT_PATH>
|
| 155 |
-
```
|
| 156 |
-
|
| 157 |
-
- `<DETECTOR>`: One of `CLIP-D`, `NPR`, `P2G`, `R50_TF`, `R50_nodown`
|
| 158 |
-
- `--image`: Path to the input image
|
| 159 |
-
- `--weights`: Weights name (default: `pretrained`)
|
| 160 |
-
- `--output`: Path to save detection results (default: `detection_results`)
|
| 161 |
-
|
| 162 |
-
-----
|
| 163 |
-
|
| 164 |
-
## Train on Different Generators from the DeepShield Dataset
|
| 165 |
-
|
| 166 |
-
To train a detector on generators different from StyleGAN2 and StableDiffusionXL, modify these lines in `configs/<DETECTOR>.yaml`:
|
| 167 |
-
|
| 168 |
-
```json
|
| 169 |
-
training:
|
| 170 |
-
- data: gan2:pre&sdXL:pre&realFFHQ:pre&realFORLAB:pre
|
| 171 |
-
```
|
| 172 |
-
|
| 173 |
-
Currently supported pairs of `(key, sub-dataset)` are:
|
| 174 |
-
|
| 175 |
-
```
|
| 176 |
-
'gan1':['StyleGAN']
|
| 177 |
-
'gan2':['StyleGAN2']
|
| 178 |
-
'gan3':['StyleGAN3']
|
| 179 |
-
'sd15':['StableDiffusion1.5']
|
| 180 |
-
'sd2':['StableDiffusion2']
|
| 181 |
-
'sd3':['StableDiffusion3']
|
| 182 |
-
'sdXL':['StableDiffusionXL']
|
| 183 |
-
'flux':['FLUX.1']
|
| 184 |
-
'realFFHQ':['FFHQ']
|
| 185 |
-
'realFORLAB':['FORLAB']
|
| 186 |
-
```
|
| 187 |
-
|
| 188 |
-
And supported pairs of `(key, social)` are:
|
| 189 |
-
|
| 190 |
-
```
|
| 191 |
-
'pre':[Not Shared on Social Networks],
|
| 192 |
-
'fb': [Facebook]
|
| 193 |
-
'tl': [Telegram]
|
| 194 |
-
'tw': [X Social]
|
| 195 |
-
```
|
| 196 |
-
|
| 197 |
-
Then, generate the corresponding `split.json` using `python support/json_compile.py` and use it to replace `./split.json`. NOTE: change line 9 `dataset_path=...` in `support/json_compile.py` accordingly.
|
| 198 |
-
|
| 199 |
-
## Results & Logs
|
| 200 |
-
|
| 201 |
-
- **Results:** Saved in `detectors/<DETECTOR>/results/`
|
| 202 |
-
- **Logs:** Saved in `logs/` per run and scenario
|
| 203 |
-
|
| 204 |
-
-----
|
| 205 |
-
|
| 206 |
-
## Train/Test on a New Dataset
|
| 207 |
-
|
| 208 |
-
### Data Organization
|
| 209 |
-
|
| 210 |
-
Organize your data by platform and label:
|
| 211 |
-
|
| 212 |
-
```
|
| 213 |
-
<DATASET_NAME>/
|
| 214 |
-
Facebook/
|
| 215 |
-
Fake/
|
| 216 |
-
Real/
|
| 217 |
-
PreSocial/
|
| 218 |
-
Fake/
|
| 219 |
-
Real/
|
| 220 |
-
Telegram/
|
| 221 |
-
Fake/
|
| 222 |
-
Real/
|
| 223 |
-
X/
|
| 224 |
-
Fake/
|
| 225 |
-
Real/
|
| 226 |
-
```
|
| 227 |
-
|
| 228 |
-
Generate the corresponding `split.json` using `python support/json_compile.py` and use it to replace `./split.json`. NOTE: change line 9 `dataset_path=...` in `support/json_compile.py` accordingly.
|
| 229 |
-
|
| 230 |
-
### Split Files
|
| 231 |
-
|
| 232 |
-
- **`split.json`:** Main split file for experiments. Format: JSON with `train`/`test` keys and lists of sample IDs.
|
| 233 |
-
- **`split_demo.json`:** Auto-generated for demo mode, covering all images in `demo_images/`.
|
| 234 |
-
|
| 235 |
-
-----
|
| 236 |
-
|
| 237 |
-
## Additional Configuration Options
|
| 238 |
-
|
| 239 |
-
- **YAML Files:** All detectors have a config file in `configs/` (e.g., `CLIP-D.yaml`, `NPR.yaml`).
|
| 240 |
-
- **Config Options:**
|
| 241 |
-
- `global`: Dataset path, device, split file, threads, etc.
|
| 242 |
-
- `detector_args`: Model-specific arguments.
|
| 243 |
-
- `training`: List of training scenarios.
|
| 244 |
-
- `testing`: List of test scenarios.
|
| 245 |
-
|
| 246 |
-
-----
|
| 247 |
|
| 248 |
## References
|
| 249 |
|
| 250 |
-
|
| 251 |
-
“Raising the Bar of AI-generated Image Detection with CLIP,” in 2024
|
| 252 |
-
IEEE/CVF Conference on Computer Vision and Pattern Recognition
|
| 253 |
-
Workshops (CVPRW), pp. 4356–4366, June 2024. ISSN: 2160-7516.
|
| 254 |
-
|
| 255 |
-
[2]C. Tan, H. Liu, Y. Zhao, S. Wei, G. Gu, P. Liu, and Y. Wei, “Rethinking the Up-Sampling Operations in CNN-Based Generative Network for
|
| 256 |
-
Generalizable Deepfake Detection,” in 2024 IEEE/CVF Conference on
|
| 257 |
-
Computer Vision and Pattern Recognition (CVPR), pp. 28130–28139,
|
| 258 |
-
June 2024. ISSN: 2575-7075.
|
| 259 |
-
|
| 260 |
-
[3] F. Laiti, B. Liberatori, T. De Min, and E. Ricci, “Conditioned Prompt-Optimization for Continual Deepfake Detection,” in Pattern Recognition (A. Antonacopoulos, S. Chaudhuri, R. Chellappa, C.L. Liu, S. Bhatacharya, and U. Pal, eds.), (Cham), pp. 64–79, Springer Nature Switzerland, 2025.
|
| 261 |
-
|
| 262 |
-
[4] Dell'Anna, Stefano, Andrea Montibeller, and Giulia Boato. "TrueFake: A Real World Case Dataset of Last Generation Fake Images also Shared on Social Networks." arXiv preprint arXiv:2504.20658 (2025).
|
| 263 |
-
|
| 264 |
-
[5]R. Corvi, D. Cozzolino, G. Zingarini, G. Poggi, K. Nagano, and L. Verdoliva, “On The Detection of Synthetic Images Generated by Diffusion
|
| 265 |
-
Models,” in ICASSP 2023 - 2023 IEEE International Conference on
|
| 266 |
-
Acoustics, Speech and Signal Processing (ICASSP), pp. 1–5, June 2023.
|
| 267 |
-
ISSN: 2379-190X.
|
| 268 |
|
| 269 |
-
|
| 270 |
|
| 271 |
-
|
| 272 |
-
identification—questioning fingerprint uniqueness,” IEEE Access, vol. 9, pp. 52455–52463, 2021.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Deepfake Detection Library
|
| 3 |
+
emoji: 🔍
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: orange
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# Deepfake Detection Library
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
This Space provides a unified interface to test multiple state-of-the-art deepfake detection models on your images.
|
| 16 |
|
| 17 |
+
## Available Detectors
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
- **R50_TF** - ResNet-50 based detector trained on TrueFake dataset
|
| 20 |
+
- **R50_nodown** - ResNet-50 without downsampling operations
|
| 21 |
+
- **CLIP-D** - CLIP-based deepfake detector
|
| 22 |
+
- **P2G** - Prompt2Guard: Conditioned prompt-optimization for continual deepfake detection
|
| 23 |
+
- **NPR** - Neural Posterior Regularization
|
| 24 |
|
| 25 |
+
## Usage
|
| 26 |
|
| 27 |
+
1. Upload an image
|
| 28 |
+
2. Select a detector from the dropdown
|
| 29 |
+
3. Click "Detect" to get the prediction
|
| 30 |
|
| 31 |
+
The detector will return:
|
| 32 |
+
- **Prediction**: Real or Fake
|
| 33 |
+
- **Confidence**: Model confidence score (0-1)
|
| 34 |
+
- **Elapsed Time**: Processing time
|
| 35 |
|
| 36 |
+
## Models
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
All models have been pretrained on images generated with StyleGAN2 and StableDiffusionXL, and real images from the FFHQ Dataset and the FORLAB Dataset.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
## References
|
| 41 |
|
| 42 |
+
For more information about the implementation and benchmarking, visit the [GitHub repository](https://github.com/truebees-ai/Image-Deepfake-Detectors-Public-Library).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
## Note
|
| 45 |
|
| 46 |
+
⚠️ Due to file size limitations, model weights need to be downloaded automatically on first use. This may take a few moments.
|
|
|
detectors/P2G/src/.DS_Store
CHANGED
|
Binary files a/detectors/P2G/src/.DS_Store and b/detectors/P2G/src/.DS_Store differ
|
|
|