AMontiB commited on
Commit
65d0705
Β·
1 Parent(s): c4321f9
Files changed (2) hide show
  1. __pycache__/app.cpython-310.pyc +0 -0
  2. app.py +19 -38
__pycache__/app.cpython-310.pyc CHANGED
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
 
app.py CHANGED
@@ -34,29 +34,12 @@ if os.environ.get("SPACE_ID"):
34
  # Available detectors based on launcher.py
35
  DETECTORS = ['ALL', 'R50_TF', 'R50_nodown', 'CLIP-D', 'P2G', 'NPR']
36
 
37
- # Performance weights from Table III (Non-shared) and Table IV (Social Media: FB, TL, X)
38
- # Weights are averaged between Non-shared and Social Media performance.
39
- # R50_TF (R50-E2P):
40
- # Real (TNR): (0.98 + 0.91) / 2 = 0.95
41
- # Fake (TPR): (0.85 + 0.65) / 2 = 0.75
42
- # R50_nodown (R50-ND):
43
- # Real (TNR): (1.00 + 0.97) / 2 = 0.98
44
- # Fake (TPR): (0.79 + 0.76) / 2 = 0.77
45
- # CLIP-D:
46
- # Real (TNR): (0.97 + 0.94) / 2 = 0.95
47
- # Fake (TPR): (0.93 + 0.91) / 2 = 0.92
48
- # P2G:
49
- # Real (TNR): (1.00 + 1.00) / 2 = 1.00
50
- # Fake (TPR): (0.91 + 0.56) / 2 = 0.74
51
- # NPR:
52
- # Real (TNR): (0.99 + 1.00) / 2 = 1.00
53
- # Fake (TPR): (0.60 + 0.12) / 2 = 0.36
54
  DETECTOR_WEIGHTS = {
55
- 'R50_TF': {'real': 0.95, 'fake': 0.75},
56
- 'R50_nodown': {'real': 0.98, 'fake': 0.77},
57
- 'CLIP-D': {'real': 0.95, 'fake': 0.92},
58
- 'P2G': {'real': 1.00, 'fake': 0.74},
59
- 'NPR': {'real': 1.00, 'fake': 0.36}
60
  }
61
 
62
  def process_image(image_path):
@@ -187,15 +170,13 @@ def predict(image_path, detector_name):
187
  # Weighted Voting logic
188
  # Only count vote if confidence > 0.6
189
  if score > 0.6:
190
- weights = DETECTOR_WEIGHTS.get(det, {'real': 1.0, 'fake': 1.0})
191
  if pred == 'fake':
192
- w = weights['fake']
193
- votes_fake += w * score
194
- total_weight_used += w
195
  elif pred == 'real':
196
- w = weights['real']
197
- votes_real += w * score
198
- total_weight_used += w
199
 
200
  # Majority Voting
201
  if votes_real > votes_fake:
@@ -302,7 +283,7 @@ with demo:
302
 
303
  ### Understanding the Results produced by "ALL"
304
  * Runs all available detectors (R50_TF, R50_nodown, CLIP-D, P2G, NPR) sequentially on the input image.
305
- * Produces a **Weighted Majority Vote** verdict (Real/Fake). Each model's vote is weighted by its historical performance (TPR for Fakes, TNR for Reals) on benchmark datasets **and its confidence score**. Only confident predictions (> 0.6) are counted.
306
  * You can find the specific weights used for each model in the **"βš–οΈ Weight Details"** menu below.
307
  * Also generates a **Confidence Plot** visualizing each model's score and a textual **Explanation** of the consensus.
308
  * In the plot, **Green** bars indicate a **Real** prediction, while **Red** bars indicate a **Fake** prediction.
@@ -336,15 +317,15 @@ with demo:
336
  with gr.Accordion("βš–οΈ Weight Details", open=False):
337
  gr.Markdown(f"""
338
  ### **Detector Weights**
339
- These weights are derived from performance on benchmark datasets (FFHQ, FORLAB, SG2, SDXL) and social media data (FB, TL, X).
340
 
341
- | Detector | Real (TNR) Weight | Fake (TPR) Weight |
342
- | :--- | :---: | :---: |
343
- | **R50_TF** | {DETECTOR_WEIGHTS['R50_TF']['real']:.2f} | {DETECTOR_WEIGHTS['R50_TF']['fake']:.2f} |
344
- | **R50_nodown** | {DETECTOR_WEIGHTS['R50_nodown']['real']:.2f} | {DETECTOR_WEIGHTS['R50_nodown']['fake']:.2f} |
345
- | **CLIP-D** | {DETECTOR_WEIGHTS['CLIP-D']['real']:.2f} | {DETECTOR_WEIGHTS['CLIP-D']['fake']:.2f} |
346
- | **P2G** | {DETECTOR_WEIGHTS['P2G']['real']:.2f} | {DETECTOR_WEIGHTS['P2G']['fake']:.2f} |
347
- | **NPR** | {DETECTOR_WEIGHTS['NPR']['real']:.2f} | {DETECTOR_WEIGHTS['NPR']['fake']:.2f} |
348
  """)
349
 
350
  with gr.Accordion("πŸ“š Model Details", open=False):
 
34
  # Available detectors based on launcher.py
35
  DETECTORS = ['ALL', 'R50_TF', 'R50_nodown', 'CLIP-D', 'P2G', 'NPR']
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  DETECTOR_WEIGHTS = {
38
+ 'CLIP-D': 0.30,
39
+ 'R50_TF': 0.25,
40
+ 'R50_nodown': 0.20,
41
+ 'P2G': 0.15,
42
+ 'NPR': 0.10
43
  }
44
 
45
  def process_image(image_path):
 
170
  # Weighted Voting logic
171
  # Only count vote if confidence > 0.6
172
  if score > 0.6:
173
+ weight = DETECTOR_WEIGHTS.get(det, 0.0)
174
  if pred == 'fake':
175
+ votes_fake += weight * score
176
+ total_weight_used += weight
 
177
  elif pred == 'real':
178
+ votes_real += weight * score
179
+ total_weight_used += weight
 
180
 
181
  # Majority Voting
182
  if votes_real > votes_fake:
 
283
 
284
  ### Understanding the Results produced by "ALL"
285
  * Runs all available detectors (R50_TF, R50_nodown, CLIP-D, P2G, NPR) sequentially on the input image.
286
+ * Produces a **Weighted Majority Vote** verdict (Real/Fake). Each model's vote is weighted by a fixed importance score (summing to 1) based on user ranking **and its confidence score**. Only confident predictions (> 0.6) are counted.
287
  * You can find the specific weights used for each model in the **"βš–οΈ Weight Details"** menu below.
288
  * Also generates a **Confidence Plot** visualizing each model's score and a textual **Explanation** of the consensus.
289
  * In the plot, **Green** bars indicate a **Real** prediction, while **Red** bars indicate a **Fake** prediction.
 
317
  with gr.Accordion("βš–οΈ Weight Details", open=False):
318
  gr.Markdown(f"""
319
  ### **Detector Weights**
320
+ The weights are assigned based on the ranking (based on the results of [TrueFake: A Real World Case Dataset of Last Generation Fake Images also Shared on Social Networks](https://arxiv.org/pdf/2504.20658)): **CLIP-D > R50_TF > R50_nodown > P2G > NPR**, such that their sum equals 1.
321
 
322
+ | Detector | Weight |
323
+ | :--- | :---: |
324
+ | **CLIP-D** | {DETECTOR_WEIGHTS['CLIP-D']:.2f} |
325
+ | **R50_TF** | {DETECTOR_WEIGHTS['R50_TF']:.2f} |
326
+ | **R50_nodown** | {DETECTOR_WEIGHTS['R50_nodown']:.2f} |
327
+ | **P2G** | {DETECTOR_WEIGHTS['P2G']:.2f} |
328
+ | **NPR** | {DETECTOR_WEIGHTS['NPR']:.2f} |
329
  """)
330
 
331
  with gr.Accordion("πŸ“š Model Details", open=False):