pabberpe commited on
Commit
352bfeb
1 Parent(s): 41b7087

Improve Interface Description and README

Browse files
Files changed (2) hide show
  1. README.md +303 -1
  2. app.py +20 -17
README.md CHANGED
@@ -11,4 +11,306 @@ license: apache-2.0
11
  short_description: Spot AI-Generated images with SuSy!
12
  ---
13
 
14
- SuSy is a Spatial-Based Synthetic Image Detection and Recognition Model, designed and trained to detect synthetic images and attribute them to a generative model (i.e., two StableDiffusion models, two Midjourney versions and DALL路E 3)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  short_description: Spot AI-Generated images with SuSy!
12
  ---
13
 
14
+ # SuSy - Synthetic Image Detector
15
+
16
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/62f7a16192950415b637e201/NobqlpFbFkTyBi1LsT9JE.png" alt="image" width="300" height="auto">
17
+
18
+
19
+ - **Paper:** https://arxiv.org/abs/2409.14128
20
+ - **Code:** https://github.com/HPAI-BSC/SuSy
21
+ - **Dataset:** https://huggingface.co/datasets/HPAI-BSC/SuSy-Dataset
22
+
23
+ **Model Results**
24
+
25
+ | Dataset | Type | Model | Year | Recall |
26
+ |:-------------------:|:---------:|:-------------------------:|:----:|:------:|
27
+ | Flickr30k | Authentic | - | 2014 | 90.53 |
28
+ | Google Landmarks v2 | Authentic | - | 2020 | 64.54 |
29
+ | Synthbuster | Synthetic | Glide | 2021 | 53.50 |
30
+ | Synthbuster | Synthetic | Stable Diffusion 1.3 | 2022 | 87.00 |
31
+ | Synthbuster | Synthetic | Stable Diffusion 1.4 | 2022 | 87.10 |
32
+ | Synthbuster | Synthetic | Stable Diffusion 2 | 2022 | 68.40 |
33
+ | Synthbuster | Synthetic | DALL-E 2 | 2022 | 20.70 |
34
+ | Synthbuster | Synthetic | MidJourney V5 | 2023 | 73.10 |
35
+ | Synthbuster | Synthetic | Stable Diffusion XL | 2023 | 79.50 |
36
+ | Synthbuster | Synthetic | Firefly | 2023 | 40.90 |
37
+ | Synthbuster | Synthetic | DALL-E 3 | 2023 | 88.60 |
38
+ | Authors | Synthetic | Stable Diffusion 3 Medium | 2024 | 93.23 |
39
+ | Authors | Synthetic | Flux.1-dev | 2024 | 96.46 |
40
+ | In-the-wild | Synthetic | Mixed/Unknown | 2024 | 89.90 |
41
+ | In-the-wild | Authentic | - | 2024 | 33.06 |
42
+
43
+ ## Model Details
44
+
45
+ <!-- Provide a longer summary of what this model is. -->
46
+
47
+ SuSy is a Spatial-Based Synthetic Image Detection and Recognition Model, designed and trained to detect synthetic images and attribute them to a generative model (i.e., two StableDiffusion models, two Midjourney versions and DALL路E 3). The model takes image patches of size 224x224 as input, and outputs the probability of the image being authentic or having been created by each of the aforementioned generative models.
48
+
49
+ <img src="model_architecture.png" alt="image" width="900" height="auto">
50
+
51
+ The model is based on a CNN architecture and is trained using a supervised learning approach. It's design is based on [previous work](https://upcommons.upc.edu/handle/2117/395959), originally intended for video superresolution detection, adapted here for the tasks of synthetic image detection and recognition. The architecture consists of two modules: a feature extractor and a multi-layer perceptron (MLP), as it's quite light weight. SuSy has a total of 12.7M parameters, with the feature extractor accounting for 12.5M parameters and the MLP accounting for the remaining 197K.
52
+
53
+ The CNN feature extractor consists of five stages following a ResNet-18 scheme. The output of each of the blocks is used as input for various bottleneck modules that are arranged in a staircase pattern. The bottleneck modules consist of three 2D convolutional layers. Each level of bottlenecks takes input at a later stage than the previous level, and each bottleneck module takes input from the current stage and, except the first bottleneck of each level, from the previous bottleneck module.
54
+
55
+ The outputs of each level of bottlenecks and stage 4 are passed to a 2D adaptative average pooling layer and then concatenated to form the feature map feeding the MLP. The MLP consists of three fully connected layers with 512, 256 and 256 units, respectively. Between each layer, a dropout layer (rate of 0.5) prevents overfitting. The output of the MLP has 6 units, corresponding to the number of classes in the dataset (5 synthetic models and 1 real image class).
56
+
57
+ The model can be used as a detector by either taking the class with the highest probability as the output or summing the probabilities of the synthetic classes and comparing them to the real class. The model can also be used as an recognition model by taking the class with the highest probability as the output.
58
+
59
+ ### Model Description
60
+
61
+ - **Developed by:** [Pablo Bernabeu Perez](https://huggingface.co/pabberpe), [Enrique Lopez Cuena](https://huggingface.co/Cuena) and [Dario Garcia Gasulla](https://huggingface.co/dariog) from [HPAI](https://hpai.bsc.es/)
62
+ - **Model type:** Spatial-Based Synthetic Image Detection and Recognition Convolutional Neural Network
63
+ - **License:** [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
64
+
65
+ ## Uses
66
+
67
+ This model can be used to detect synthetic images in a scalable manner, thanks to its small size. Since it operates on patches of 224x224, a moving window should be implemented in inference when applied on larger inputs (the most likely scenario, and the one it was trained under). This also enables the capacity for synthetic content localization within a high resolution input.
68
+
69
+ Any individual or organization seeking for support on the identification of synthetic content can use this model. However, it should not be used as the only source of evidence, particularly when applied to inputs produced by generative models not included in its training (see details in Training Data below).
70
+
71
+ ### Intended Uses
72
+
73
+ Intended uses include the following:
74
+
75
+ * Detection of authentic and synthetic images
76
+ * Attribution of synthetic images to their generative model (if included in the training data)
77
+ * Localization of image patches likely to be synthetic or tampered.
78
+
79
+ ### Out-of-Scope Uses
80
+
81
+ Out-of-scope uses include the following:
82
+
83
+ * Detection of manually edited images using traditional tools.
84
+ * Detection of images automatically downscaled and/or upscaled. These are considered as non-synthetic samples in the model training phase.
85
+ * Detection of inpainted images.
86
+ * Detection of synthetic vs manually crafted illustrations. The model is trained mainly on photorealistic samples.
87
+ * Attribution of synthetic images to their generative model if the model was not included in the training data. AThis model may not be used to train generative models or tools aimed at lthough some generalization capabilities are expected, reliability in this case cannot be estimated.
88
+
89
+ ### Forbidden Uses
90
+
91
+ This model may not be used to train generative models or tools aimed at purposefully deceiving the model or creating misleading content.
92
+
93
+ ## Bias, Risks, and Limitations
94
+
95
+ The model may be biased in the following ways:
96
+
97
+ * The model may be biased towards the training data, which may not be representative of all authentic and synthetic images. Particularly for the class of real world images, which were obtained from a single source.
98
+ * The model may be biased towards the generative models included in the training data, which may not be representative of all possible generative models. Particularly new ones, since all models included were released between 2022 and 2023.
99
+ * The model may be biased towards certain type of images or contents. While it is trained using roughly 18K synthetic images, no assessment was made on which domains and profiles are included in those.
100
+
101
+ The model has the following technical limitations:
102
+
103
+ * The performance of the model may be influenced by transformations and editions performed on the images. While the model was trained on some alterations (blur, brightness, compression and gamma) there are other alterations applicable to images that could reduce the model accuracy.
104
+ * The performance of the model might vary depending on the type and source of images
105
+ * The model will not be able to attribute synthetic images to their generative model if the model was not included in the training data.
106
+ * The model is trained on patches with high gray-level contrast. For images composed entirely by low contrast regions, the model may not work as expected.
107
+
108
+ ### Recommendations
109
+
110
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
111
+
112
+ ## How to Get Started with the Model
113
+
114
+ Use the code below to get started with the model.
115
+
116
+ ```python
117
+ import torch
118
+ from PIL import Image
119
+ from torchvision import transforms
120
+
121
+ # Load the model
122
+ model = torch.jit.load("SuSy.pt")
123
+
124
+ # Load patch
125
+ patch = Image.open("midjourney-images-example-patch0.png")
126
+
127
+ # Transform patch to tensor
128
+ patch = transforms.PILToTensor()(patch).unsqueeze(0) / 255.
129
+
130
+ # Predict patch
131
+ model.eval()
132
+ with torch.no_grad():
133
+ preds = model(patch)
134
+
135
+ print(preds)
136
+ ```
137
+
138
+ See `test_image.py` and `test_patch.py` for other examples on how to use the model.
139
+
140
+ ## Training Details
141
+
142
+ ### Training Data
143
+
144
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
145
+
146
+ The dataset is available at: https://huggingface.co/datasets/HPAI-BSC/SuSy-Dataset
147
+
148
+ | Dataset | Year | Train | Validation | Test | Total |
149
+ |:-----------------:|:----:|:-----:|:----------:|:-----:|:-----:|
150
+ | COCO | 2017 | 2,967 | 1,234 | 1,234 | 5,435 |
151
+ | dalle-3-images | 2023 | 987 | 330 | 330 | 1,647 |
152
+ | diffusiondb | 2022 | 2,967 | 1,234 | 1,234 | 5,435 |
153
+ | realisticSDXL | 2023 | 2,967 | 1,234 | 1,234 | 5,435 |
154
+ | midjourney-tti | 2022 | 2,718 | 906 | 906 | 4,530 |
155
+ | midjourney-images | 2023 | 1,845 | 617 | 617 | 3,079 |
156
+
157
+ #### Authentic Images
158
+
159
+ - [COCO](https://cocodataset.org/)
160
+
161
+ We use a random subset of the COCO dataset, containing 5,435 images, for the authentic images in our training dataset. The partitions are made respecting the original COCO splits, with 2,967 images in the training partition and 1,234 in the validation and test partitions.
162
+
163
+ #### Synthetic Images
164
+
165
+ - [dalle-3-images](https://huggingface.co/datasets/ehristoforu/dalle-3-images)
166
+ - [diffusiondb](https://poloclub.github.io/diffusiondb/)
167
+ - [midjourney-images](https://huggingface.co/datasets/ehristoforu/midjourney-images)
168
+ - [midjourney-texttoimage](https://www.kaggle.com/datasets/succinctlyai/midjourney-texttoimage)
169
+ - [realistic-SDXL](https://huggingface.co/datasets/DucHaiten/DucHaiten-realistic-SDXL)
170
+
171
+ For the diffusiondb dataset, we use a random subset of 5,435 images, with 2,967 in the training partition and 1,234 in the validation and test partitions. We use only the realistic images from the realisticSDXL dataset, with images in the realistic-2.2 split in our training data and the realistic-1 split for our test partition. The remaining datasets are used in their entirety, with 60% of the images in the training partition, 20% in the validation partition and 20% in the test partition.
172
+
173
+ ### Training Procedure
174
+
175
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
176
+
177
+ The training code is available at: https://github.com/HPAI-BSC/SuSy
178
+
179
+ #### Preprocessing
180
+
181
+ **Patch Extraction**
182
+
183
+ To prepare the training data, we extract 240x240 patches from the images, minimizing the overlap between them. We then select the most informative patches by calculating the gray-level co-occurrence matrix (GLCM) for each patch. Given the GLCM, we calculate the contrast and select the five patches with the highest contrast. These patches are then passed to the model in their original RGB format and cropped to 224x224.
184
+
185
+ **Data Augmentation**
186
+
187
+ | Technique | Probability | Other Parameters |
188
+ |:------------------------:|:-----------:|:-----------------------------------------:|
189
+ | HorizontalFlip | 0.50 | - |
190
+ | RandomBrightnessContrast | 0.20 | brightness\_limit=0.2 contrast\_limit=0.2 |
191
+ | RandomGamma | 0.20 | gamma\_limit=(80, 120) |
192
+ | AdvancedBlur | 0.20 | |
193
+ | GaussianBlur | 0.20 | |
194
+ | JPEGCompression | 0.20 | quality\_lower=75 quality\_upper=100 |
195
+
196
+
197
+ #### Training Hyperparameters
198
+
199
+ - Loss Function: Cross-Entropy Loss
200
+ - Optimizer: Adam
201
+ - Learning Rate: 0.0001
202
+ - Weight Decay: 0
203
+ - Scheduler: ReduceLROnPlateau
204
+ - Factor: 0.1
205
+ - Patience: 4
206
+ - Batch Size: 128
207
+ - Epochs: 10
208
+ - Early Stopping: 2
209
+
210
+ ## Evaluation
211
+
212
+ <!-- This section describes the evaluation protocols and provides the results. -->
213
+
214
+ The evaluation code is available at: https://github.com/HPAI-BSC/SuSy
215
+
216
+ ### Testing Data, Factors & Metrics
217
+
218
+ #### Testing Data
219
+
220
+ <!-- This should link to a Dataset Card if possible. -->
221
+
222
+ - Test Split of our Training Dataset
223
+ - Synthetic Images generated with [Stable Diffusion 3 Medium](https://huggingface.co/stabilityai/stable-diffusion-3-medium) and [FLUX.1-dev](https://huggingface.co/black-forest-labs/FLUX.1-dev) using prompts from [Gustavosta/Stable-Diffusion-Prompts](https://huggingface.co/datasets/Gustavosta/Stable-Diffusion-Prompts)
224
+ - Synthetic Images in the Wild: Dataset containing 210 Authentic and Synthetic Images obtained from Social Media Platforms
225
+ - [Flickr 30k Dataset](https://www.kaggle.com/datasets/hsankesara/flickr-image-dataset)
226
+ - [Google Landmarks v2](https://github.com/cvdfoundation/google-landmark)
227
+ - [Synthbuster](https://zenodo.org/records/10066460)
228
+
229
+ #### Metrics
230
+
231
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
232
+
233
+ - Recall: The proportion of correctly classified positive instances out of all actual positive instances in a dataset.
234
+
235
+ ### Results
236
+
237
+ <!-- This section provides the results of the evaluation. -->
238
+
239
+ #### Authentic Sources
240
+
241
+ | Dataset | Year | Recall |
242
+ |:-------------------:|:----:|:------:|
243
+ | Flickr30k | 2014 | 90.53 |
244
+ | Google Landmarks v2 | 2020 | 64.54 |
245
+ | In-the-wild | 2024 | 33.06 |
246
+
247
+ #### Synthetic Sources
248
+
249
+ | Dataset | Model | Year | Recall |
250
+ |:-----------:|:-------------------------:|:----:|:------:|
251
+ | Synthbuster | Glide | 2021 | 53.50 |
252
+ | Synthbuster | Stable Diffusion 1.3 | 2022 | 87.00 |
253
+ | Synthbuster | Stable Diffusion 1.4 | 2022 | 87.10 |
254
+ | Synthbuster | Stable Diffusion 2 | 2022 | 68.40 |
255
+ | Synthbuster | DALL-E 2 | 2022 | 20.70 |
256
+ | Synthbuster | MidJourney V5 | 2023 | 73.10 |
257
+ | Synthbuster | Stable Diffusion XL | 2023 | 79.50 |
258
+ | Synthbuster | Firefly | 2023 | 40.90 |
259
+ | Synthbuster | DALL-E 3 | 2023 | 88.60 |
260
+ | Authors | Stable Diffusion 3 Medium | 2024 | 93.23 |
261
+ | Authors | Flux.1-dev | 2024 | 96.46 |
262
+ | In-the-wild | Mixed/Unknown | 2024 | 89.90 |
263
+
264
+ ### Summary
265
+
266
+ The results for authentic image datasets reveal varying detection performance across different sources. Recall rates range from 33.06% for the In-the-wild dataset to 90.53% for the Flickr30k dataset. The Google Landmarks v2 dataset shows an intermediate recall rate of 64.54%. These results indicate a significant disparity in the detectability of authentic images across different datasets, with the In-the-wild dataset presenting the most challenging case for SuSy.
267
+
268
+ The results for synthetic image datasets show varying detection performance across different image generation models. Recall rates range from 20.70% for DALL-E 2 (2022) to 96.46% for Flux.1-dev (2024). Stable Diffusion models generally exhibited high detectability, with versions 1.3 and 1.4 (2022) showing recall rates above 87%. More recent models tested by the authors, such as Stable Diffusion 3 Medium (2024) and Flux.1-dev (2024), demonstrate even higher detectability with recall rates above 93%. The in-the-wild mixed/unknown synthetic dataset from 2024 showed a high recall of 89.90%, indicating effective detection across various unknown generation methods. These results suggest an overall trend of improving detection capabilities for synthetic images, with newer generation models generally being more easily detectable.
269
+
270
+ It must be noted that these metrics were computed using the center-patch of images, instead of using the patch voting mechanisms described previously. This strategy allows a more fair comparison with other state-of-the-art methods although it hinders the performance of SuSy.
271
+
272
+ ## Environmental Impact
273
+
274
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
275
+
276
+ - **Hardware Type:** H100
277
+ - **Hours used:** 16
278
+ - **Hardware Provider:** Barcelona Supercomputing Center (BSC)
279
+ - **Compute Region:** Spain
280
+ - **Carbon Emitted:** 0.63kg
281
+
282
+ ## Citation
283
+
284
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
285
+
286
+ **BibTeX:**
287
+
288
+ ```bibtex
289
+ @misc{bernabeu2024susy,
290
+ title={Present and Future Generalization of Synthetic Image Detectors},
291
+ author={Pablo Bernabeu-Perez and Enrique Lopez-Cuena and Dario Garcia-Gasulla},
292
+ year={2024},
293
+ eprint={2409.14128},
294
+ archivePrefix={arXiv},
295
+ primaryClass={cs.CV},
296
+ url={https://arxiv.org/abs/2409.14128},
297
+ }
298
+ ```
299
+
300
+ ```bibtex
301
+ @thesis{bernabeu2024aidetection,
302
+ title={Detecting and Attributing AI-Generated Images with Machine Learning},
303
+ author={Bernabeu Perez, Pablo},
304
+ school={UPC, Facultat d'Inform脿tica de Barcelona, Departament de Ci猫ncies de la Computaci贸},
305
+ year={2024},
306
+ month={06}
307
+ }
308
+ ```
309
+
310
+ ## Model Card Authors
311
+
312
+ [Pablo Bernabeu Perez](https://huggingface.co/pabberpe) and [Dario Garcia Gasulla](https://huggingface.co/dariog)
313
+
314
+ ## Model Card Contact
315
+
316
+ For further inquiries, please contact [HPAI](mailto:[email protected])
app.py CHANGED
@@ -67,28 +67,31 @@ iface = gr.Interface(
67
  inputs=gr.Image(type="pil"),
68
  outputs=gr.Label(num_top_classes=6),
69
  title="SuSy: Synthetic Image Detector",
70
- description="Upload an image or select an example to classify it into different categories.",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  examples=[
72
  ["example_authentic.jpg"],
73
  ["example_dalle3.jpg"],
74
  ["example_mjv5.jpg"],
75
  ["example_sdxl.jpg"]
76
- ],
77
- article="""
78
- <div style="text-align: center;">
79
- <h3>About SuSy</h3>
80
- <p>SuSy is an advanced synthetic image detector that can distinguish between authentic images and various types of AI-generated images. It analyzes patches of the input image to make its classification.</p>
81
- <h4>Categories:</h4>
82
- <ul style="list-style-type: none; padding: 0;">
83
- <li>Authentic: Real, non-AI-generated images</li>
84
- <li>DALL路E 3: Images generated by DALL-E 3</li>
85
- <li>MJ V1/V2: Images generated by Midjourney versions 1 or 2</li>
86
- <li>MJ V5/V6: Images generated by Midjourney versions 5 or 6</li>
87
- <li>Stable Diffusion 1.x: Images generated by Stable Diffusion 1.x Models</li>
88
- <li>Stable Diffusion XL: Images generated by Stable Diffusion XL</li>
89
- </ul>
90
- </div>
91
- """
92
  )
93
 
94
  # Launch the interface
 
67
  inputs=gr.Image(type="pil"),
68
  outputs=gr.Label(num_top_classes=6),
69
  title="SuSy: Synthetic Image Detector",
70
+ description="""
71
+ <table style="border-collapse: collapse; border: none; padding: 20px;">
72
+ <tr style="border: none;">
73
+ <td style="border: none; vertical-align: top; padding-right: 30px; padding-left: 30px;">
74
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/62f7a16192950415b637e201/NobqlpFbFkTyBi1LsT9JE.png" alt="SuSy Logo" width="120" style="margin-bottom: 10px;">
75
+ </td>
76
+ <td style="border: none; vertical-align: top; padding: 10px;">
77
+ <p style="margin-bottom: 15px;">Detect synthetic images with SuSy, an advanced AI model trained on various AI-generated and authentic images.</p>
78
+ <p style="margin-top: 15px;">SuSy can distinguish between authentic images and those generated by <a href="https://openai.com/dall-e-3">DALL路E</a>, <a href="https://www.midjourney.com/">Midjourney</a> and <a href="https://stability.ai/stable-diffusion">Stable Diffusion</a>.</p>
79
+ <p style="margin-top: 15px;">
80
+ Learn more:
81
+ <a href="https://arxiv.org/abs/2409.14128">Paper</a> |
82
+ <a href="https://github.com/HPAI-BSC/SuSy">Code</a> |
83
+ <a href="https://huggingface.co/datasets/HPAI-BSC/SuSy-Dataset">Dataset</a>
84
+ </p>
85
+ </td>
86
+ </tr>
87
+ </table>
88
+ """,
89
  examples=[
90
  ["example_authentic.jpg"],
91
  ["example_dalle3.jpg"],
92
  ["example_mjv5.jpg"],
93
  ["example_sdxl.jpg"]
94
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  )
96
 
97
  # Launch the interface