deepguard 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. {deepguard-0.2.0/deepguard.egg-info → deepguard-0.2.2}/PKG-INFO +185 -34
  2. deepguard-0.2.0/PKG-INFO → deepguard-0.2.2/README.md +174 -49
  3. deepguard-0.2.0/README.md → deepguard-0.2.2/deepguard.egg-info/PKG-INFO +200 -7
  4. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard.egg-info/SOURCES.txt +27 -1
  5. deepguard-0.2.2/deepguard.egg-info/requires.txt +5 -0
  6. deepguard-0.2.2/deepguard.egg-info/top_level.txt +3 -0
  7. deepguard-0.2.2/explainability/__init__.py +13 -0
  8. deepguard-0.2.2/explainability/cam_evaluator.py +48 -0
  9. deepguard-0.2.2/explainability/explainer/base_explainer.py +194 -0
  10. deepguard-0.2.2/explainability/explainer/cam_explainer.py +319 -0
  11. deepguard-0.2.2/explainability/explainer/eigenvalue_explainer.py +35 -0
  12. deepguard-0.2.2/explainability/explainer/gradient_explainer.py +47 -0
  13. deepguard-0.2.2/explainability/explainer/misc_explainer.py +13 -0
  14. deepguard-0.2.2/explainability/explainer/perturbation_explainer.py +24 -0
  15. deepguard-0.2.2/explainability/metrics/cam_mult_image.py +37 -0
  16. deepguard-0.2.2/explainability/metrics/perturbation_confidence.py +109 -0
  17. deepguard-0.2.2/explainability/metrics/road.py +154 -0
  18. deepguard-0.2.2/explainability/utils/image.py +86 -0
  19. deepguard-0.2.2/explainability/utils/model_targets.py +16 -0
  20. deepguard-0.2.2/explainability/utils/reshape_transforms.py +11 -0
  21. deepguard-0.2.2/inference/image_predictor.py +114 -0
  22. deepguard-0.2.2/inference/image_predictor_prt.py +132 -0
  23. deepguard-0.2.2/inference/predict_video.py +154 -0
  24. deepguard-0.2.2/inference/utils.py +4 -0
  25. deepguard-0.2.2/inference/video_predictor.py +195 -0
  26. deepguard-0.2.2/inference/video_predictor_prt.py +258 -0
  27. deepguard-0.2.2/preprocess/celeb_df_v2/split_data.py +0 -0
  28. deepguard-0.2.2/preprocess/face_detector.py +199 -0
  29. deepguard-0.2.2/preprocess/ff++/__init__.py +0 -0
  30. deepguard-0.2.2/preprocess/frame_extractor.py +196 -0
  31. deepguard-0.2.2/preprocess/kodf/__init__.py +0 -0
  32. deepguard-0.2.2/preprocess/landmark_detector.py +96 -0
  33. deepguard-0.2.2/pyproject.toml +44 -0
  34. deepguard-0.2.0/deepguard.egg-info/requires.txt +0 -12
  35. deepguard-0.2.0/deepguard.egg-info/top_level.txt +0 -2
  36. deepguard-0.2.0/setup.py +0 -45
  37. {deepguard-0.2.0 → deepguard-0.2.2}/LICENSE +0 -0
  38. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/__init__.py +0 -0
  39. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/data/__init__.py +0 -0
  40. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/data/dataset.py +0 -0
  41. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/data/dataset_cutmix.py +0 -0
  42. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/data/dataset_cutout.py +0 -0
  43. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/data/dataset_mixup.py +0 -0
  44. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/data/handle_imbalance.py +0 -0
  45. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/data/split_data.py +0 -0
  46. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/data/transforms.py +0 -0
  47. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/layers/__init__.py +0 -0
  48. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/layers/attention.py +0 -0
  49. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/layers/drop.py +0 -0
  50. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/layers/featextractor.py +0 -0
  51. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/layers/global_query.py +0 -0
  52. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/layers/mlp.py +0 -0
  53. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/layers/patch.py +0 -0
  54. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/layers/reducesize.py +0 -0
  55. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/layers/se.py +0 -0
  56. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/layers/transformer.py +0 -0
  57. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/layers/weight_init.py +0 -0
  58. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/layers/window.py +0 -0
  59. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/models/__init__.py +0 -0
  60. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/models/ms_eff_gcvit.py +0 -0
  61. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/models/ms_eff_vit.py +0 -0
  62. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/optimizer/__init__.py +0 -0
  63. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/optimizer/build_optimizer.py +0 -0
  64. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/scheduler/__init__.py +0 -0
  65. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/scheduler/fetch_scheduler.py +0 -0
  66. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/utils/__init__.py +0 -0
  67. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/utils/build_metrics.py +0 -0
  68. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/utils/early_stopping.py +0 -0
  69. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/utils/meter.py +0 -0
  70. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard/utils/seed.py +0 -0
  71. {deepguard-0.2.0 → deepguard-0.2.2}/deepguard.egg-info/dependency_links.txt +0 -0
  72. {deepguard-0.2.0/preprocess/celeb_df_v2 → deepguard-0.2.2/explainability/metrics}/__init__.py +0 -0
  73. {deepguard-0.2.0/preprocess/ff++ → deepguard-0.2.2/inference}/__init__.py +0 -0
  74. {deepguard-0.2.0/preprocess/kodf → deepguard-0.2.2/preprocess}/__init__.py +0 -0
  75. /deepguard-0.2.0/preprocess/celeb_df_v2/split_data.py → /deepguard-0.2.2/preprocess/celeb_df_v2/__init__.py +0 -0
  76. {deepguard-0.2.0 → deepguard-0.2.2}/preprocess/celeb_df_v2/crop_face.py +0 -0
  77. {deepguard-0.2.0 → deepguard-0.2.2}/preprocess/celeb_df_v2/detect_original_face.py +0 -0
  78. {deepguard-0.2.0 → deepguard-0.2.2}/preprocess/celeb_df_v2/utils.py +0 -0
  79. {deepguard-0.2.0 → deepguard-0.2.2}/preprocess/ff++/crop_face.py +0 -0
  80. {deepguard-0.2.0 → deepguard-0.2.2}/preprocess/ff++/detect_original_face.py +0 -0
  81. {deepguard-0.2.0 → deepguard-0.2.2}/preprocess/ff++/split_data.py +0 -0
  82. {deepguard-0.2.0 → deepguard-0.2.2}/preprocess/ff++/utils.py +0 -0
  83. {deepguard-0.2.0 → deepguard-0.2.2}/preprocess/kodf/crop_face.py +0 -0
  84. {deepguard-0.2.0 → deepguard-0.2.2}/preprocess/kodf/detect_original_face.py +0 -0
  85. {deepguard-0.2.0 → deepguard-0.2.2}/preprocess/kodf/generate_metadata.py +0 -0
  86. {deepguard-0.2.0 → deepguard-0.2.2}/preprocess/kodf/split_data.py +0 -0
  87. {deepguard-0.2.0 → deepguard-0.2.2}/preprocess/kodf/utils.py +0 -0
  88. {deepguard-0.2.0 → deepguard-0.2.2}/setup.cfg +0 -0
@@ -1,12 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deepguard
3
- Version: 0.2.0
4
- Summary: Multi-Scale Efficient Vision Transformer for Robust Deepfake Detection
5
- Home-page: https://github.com/HanMoonSub/DeepGuard
6
- Author: seoyunje
7
- Author-email: seoyunje2001@gmail.com
3
+ Version: 0.2.2
4
+ Summary: Multi-Scale Efficient Global Context Vision Transformer for Robust Deepfake Detection
5
+ Author-email: seoyunje <seoyunje2001@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/HanMoonSub/DeepGuard
8
8
  Project-URL: Bug Tracker, https://github.com/HanMoonSub/DeepGuard/issues
9
9
  Project-URL: Source Code, https://github.com/HanMoonSub/DeepGuard
10
+ Project-URL: Hugging Face, https://huggingface.co/KoreaPeter/ms-eff-gcvit-deepfake
10
11
  Classifier: Programming Language :: Python :: 3
11
12
  Classifier: Programming Language :: Python :: 3.10
12
13
  Classifier: Programming Language :: Python :: 3.11
@@ -16,41 +17,27 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
17
  Requires-Python: >=3.10
17
18
  Description-Content-Type: text/markdown
18
19
  License-File: LICENSE
19
- Requires-Dist: torch==2.6.0
20
- Requires-Dist: timm==1.0.12
21
- Requires-Dist: torchmetrics==1.6.1
22
- Requires-Dist: opencv-python==4.11.0.86
23
- Requires-Dist: albumentations==2.0.8
24
- Requires-Dist: Pillow==11.1.0
25
- Requires-Dist: numpy==2.2.0
26
- Requires-Dist: pandas==2.2.3
27
- Requires-Dist: scikit-learn==1.6.1
28
- Requires-Dist: matplotlib==3.10.0
29
- Requires-Dist: seaborn==0.13.2
30
- Requires-Dist: colorama==0.4.6
31
- Dynamic: author
32
- Dynamic: author-email
33
- Dynamic: classifier
34
- Dynamic: description
35
- Dynamic: description-content-type
36
- Dynamic: home-page
20
+ Requires-Dist: torchmetrics>=1.6.1
21
+ Requires-Dist: ultralytics>=8.4.41
22
+ Requires-Dist: grad-cam>=1.5.5
23
+ Requires-Dist: timm>=1.0.12
24
+ Requires-Dist: torch>=2.10.0
37
25
  Dynamic: license-file
38
- Dynamic: project-url
39
- Dynamic: requires-dist
40
- Dynamic: requires-python
41
- Dynamic: summary
42
26
 
43
27
  # Deepfakes Detection
44
28
 
45
- <p align="center">
46
- <img src="https://raw.githubusercontent.com/HanMoonSub/DeepGuard/main/Images/deepfake2.png" alt="DeepGuard Banner" width="800" height="400">
47
- </p>
48
-
49
29
  <p align="center">
50
30
  <img src="https://img.shields.io/github/license/HanMoonSub/DeepGuard?style=flat-square&color=555555&logo=github&logoColor=white" alt="License">
51
31
  <img src="https://img.shields.io/github/stars/HanMoonSub/DeepGuard?style=flat-square&color=FFD700&logo=github&logoColor=white" alt="Stars">
32
+ <img src="https://img.shields.io/github/downloads/HanMoonSub/DeepGuard/total?style=flat-square&color=brightgreen&logo=github&logoColor=white" alt="Downloads">
33
+ <img src="https://img.shields.io/github/last-commit/HanMoonSub/DeepGuard?style=flat-square&color=lightgrey&logo=github&logoColor=white" alt="Last Commit">
52
34
  <img src="https://img.shields.io/badge/Status-Active-brightgreen?style=flat-square" alt="Status">
53
35
  <img src="https://img.shields.io/badge/Release-v0.2.0-orange?style=flat-square&logo=github&logoColor=white" alt="Release">
36
+ <img src="https://img.shields.io/github/repo-size/HanMoonSub/DeepGuard?style=flat-square&color=blueviolet" alt="Repo Size">
37
+ </p>
38
+
39
+ <p align="center">
40
+ <img src="docs/samples/deepfake_thumbnails.png" alt="DeepGuard Banner" width="800" height="400">
54
41
  </p>
55
42
 
56
43
  <p align="center">
@@ -69,6 +56,7 @@ Dynamic: summary
69
56
 
70
57
  <p align="center">
71
58
  <a href="README_KR.md"><b>🇰🇷 한국어 버전</b></a> |
59
+ <a href="README_JP.md"><b>🇯🇵 日本語版</b></a> |
72
60
  <a href="#-model-evaluation"><b>📈 Model Evaluation</b></a> |
73
61
  <a href="#-predict-image--video"><b>🔮 Try Demo</b></a>
74
62
  </p>
@@ -85,6 +73,7 @@ Dynamic: summary
85
73
  - [📈 Model Evaluation](#-model-evaluation) - Benchmarking results
86
74
  - [💻 Model Usage](#-model-usage) - How to integrate DeepGuard models into your own Python code or via timm
87
75
  - [🔮 Predict Image & Video](#-predict-image--video) - Simple Inference examples for detecting deepfakes in image and video
76
+ - [🎨 DeepFake AI Explainability](#-deepfake-ai-explainability) - Visualizing model focus using Grad-CAM and attention maps
88
77
  - [📬 Authors](#-authors)
89
78
  - [📝 Reference](#-reference)
90
79
  - [⚖️ License](#-license)
@@ -180,7 +169,7 @@ Multi Scale Efficient Global Context Vision Transformer is an optimized multi-sc
180
169
 
181
170
 
182
171
  <p align="center">
183
- <img src="https://raw.githubusercontent.com/HanMoonSub/DeepGuard/main/Images/ms_eff_gcvit.JPG" width="100%" height="700">
172
+ <img src="docs/architectures/ms_eff_gcvit.JPG" width="100%" height="700">
184
173
  </p>
185
174
 
186
175
  We utilizes two distinct types of self-attention to capture both long-range and short-range information across feature maps.
@@ -191,7 +180,7 @@ We utilizes two distinct types of self-attention to capture both long-range and
191
180
 
192
181
 
193
182
  <p align="center">
194
- <img src=https://raw.githubusercontent.com/HanMoonSub/DeepGuard/main/Images/window_attention.JPG width="100%" height="300">
183
+ <img src=docs/architectures/window_attention.JPG width="100%" height="300">
195
184
  </p>
196
185
 
197
186
  ## 🧬 Model Zoo
@@ -268,7 +257,8 @@ You can load the models directly via the `DeepGuard` package or through the `tim
268
257
  **Installation**
269
258
 
270
259
  ```bash
271
- pip install -U git+https://github.com/HanMoonSub/DeepGuard.git
260
+ # pip install -U git+https://github.com/HanMoonSub/DeepGuard.git
261
+ pip install deepguard
272
262
  ```
273
263
 
274
264
 
@@ -291,6 +281,21 @@ model = timm.create_model("ms_eff_gcvit_b0", pretrained=True, dataset="ff++")
291
281
  model = timm.create_model("ms_eff_gcvit_b5", pretrained=True, dataset="kodf")
292
282
  ```
293
283
 
284
+ **Option C: Hugging Face Hub**
285
+
286
+ ```python
287
+ import torch
288
+ from huggingface_hub import hf_hub_download
289
+ from deepguard import ms_eff_gcvit_b0 # or ms_eff_gcvit_b5
290
+
291
+ REPO_ID = "KoreaPeter/ms-eff-gcvit-deepfake"
292
+
293
+ ckpt = hf_hub_download(REPO_ID, "ms_eff_gcvit_b0_kodf.bin") # celeb_df_v2 | ff++ | kodf
294
+ model = ms_eff_gcvit_b0(pretrained=False)
295
+ model.load_state_dict(torch.load(ckpt, map_location="cpu"))
296
+ model.eval()
297
+ ```
298
+
294
299
  ## 🔮 Predict Image & Video
295
300
 
296
301
  #### Predict DeepFake Image
@@ -344,6 +349,151 @@ print(f"Deepfake Probability: {result:.4f}")
344
349
 
345
350
  ```
346
351
 
352
+ ## 🎨 DeepFake AI Explainability
353
+
354
+ Deepfake detection is only as trustworthy as its explanations. DeepGuard integrates a production-ready XAI Toolkit that visualizes where and why the model flags a face as manipulated — turning a black-box score into actionable forensic evidence.
355
+
356
+ ⭐ Validated on hybrid CNN-ViT architectures, specifically `MS-EffViT` and `MS-EffGCViT`.
357
+ ⭐ Dual-Branch Analysis: Dual-branch design mirrors the model's own multi-scale reasoning
358
+
359
+ ### 🧠 How Dual-Branch XAI Works
360
+
361
+ <p align="center">
362
+ <img src="docs/architectures/dual_branch.gif" width="70%" height="300">
363
+ </p>
364
+
365
+
366
+ | Branch | Feature Map | Focus | Best For |
367
+ | ------ | ----------- | ----- | -------- |
368
+ | ![](https://img.shields.io/badge/Low_level-blue?style=flat-square) | High Resolution | Local Forgery artifacts | Skin texture, boundary blending, compression traces |
369
+ | ![](https://img.shields.io/badge/High_level-red?style=flat-square) | Low Resolution | Global Semantic Structure | Lighting inconsistency, facial geometry, Shadow artifacts |
370
+
371
+ ### 📐 XAI Methods
372
+
373
+ Each method is assigned to the branch where it performs best empirically.
374
+
375
+ | Branch | Method | 🎯 Core Idea |
376
+ | :--- | :--- | :--- |
377
+ | **`low level`** | **HiResCAM** | Like GradCAM but element-wise multiply the activations with the gradients; provably guaranteed faithfulness for certain models |
378
+ | **`low level`** | **GradCAMElementWise** | Like GradCAM but element-wise multiply the activations with the gradients then apply a ReLU operation before summing |
379
+ | **`low level`** | **LayerCAM** | Spatially weight the activations by positive gradients. Works better especially in lower layers |
380
+ | --- | --- | --- | --- |
381
+ | **`high level`** | **EigenGradCAM** | Like EigenCAM but with class discrimination: First principle component of Activations*Grad. Looks like GradCAM, but cleaner |
382
+ | **`high level`** | **GradCAM++** | Like GradCAM but uses second order gradients |
383
+ | **`high level`** | **XGradCAM** | Like GradCAM but scale the gradients by the normalized activations |
384
+
385
+ - **`aug_smooth`** applies TTA (horizontal flips) before averaging CAMs → smoother, more object-aligned maps
386
+ - **`eigen_smooth`** applies PCA noise reduction → retains dominant forgery pattern only
387
+
388
+ ### 💡 DeepFake XAI Usage
389
+
390
+ **Low-Level Branch — Local Artifact Detection**
391
+
392
+ ```python
393
+ from explainability import HiResCAMExplainer, GradCAMElementWiseExplainer, LayerCAMExplainer
394
+
395
+ explainer = HiResCAMExplainer(
396
+ model_name = "ms_eff_gcvit_b0", # or ms_eff_vit_b0, ms_eff_gcvit_b5, ms_eff_vit_b5
397
+ dataset = "celeb_df_v2", # or ff++, kodf
398
+ branch_level = "low",
399
+ )
400
+ ```
401
+
402
+ **High-Level Branch — Global Semantic Detection**
403
+ ```python
404
+ from explainability import EigenGradCAMExplainer, GradCAMPlusPlusExplainer, XGradCAMExplainer
405
+
406
+ explainer = EigenGradCAMExplainer(
407
+ model_name = "ms_eff_gcvit_b0",
408
+ dataset = "celeb_df_v2",
409
+ branch_level = "high",
410
+ )
411
+ ```
412
+
413
+ ### 🎨 Visualization Modes
414
+
415
+ <p align="center">
416
+ <img src="docs/xai-results/xai_demo.gif" width="80%" height=300>
417
+ </p>
418
+
419
+ **1. Heatmap — Continuous activation distribution**
420
+
421
+ ```python
422
+ result = explainer.display_heatmap_on_image(
423
+ img_path = "path/to/image.jpg",
424
+ category = 1, # 0: Real, 1: Fake
425
+ threshold = 0.5, # binarization cutoff (0.5~1.0), or "auto" for Otsu
426
+ image_weight = 0.5, # 0.0: heatmap only ← → 1.0: original only
427
+ aug_smooth = False, # TTA smoothing (not supported on 'pro' models)
428
+ eigen_smooth = False, # PCA noise reduction
429
+ )
430
+ ```
431
+
432
+ **2. Bounding Box — Discrete forgery region localization**
433
+
434
+ ```python
435
+ result = explainer.display_bbox_on_image(
436
+ img_path = "path/to/image.jpg",
437
+ category = 1,
438
+ threshold = 0.5,
439
+ thickness = 1,
440
+ aug_smooth = False,
441
+ eigen_smooth = False,
442
+ )
443
+ ```
444
+
445
+ **3. Heatmap + BBox — Full overlay (recommended for reporting)**
446
+ ```python
447
+ result = explainer.display_heatmap_bbox_on_image(
448
+ img_path = "path/to/image.jpg",
449
+ category = 1,
450
+ threshold = 0.5,
451
+ image_weight = 0.5,
452
+ aug_smooth = False,
453
+ eigen_smooth = False,
454
+ )
455
+ ```
456
+
457
+ ### 📊 Visual Results
458
+
459
+ <p align="center">
460
+ <table>
461
+ <tr>
462
+ <td><img src="docs/architectures/low_branch.gif" width="100%"></td>
463
+ <td width="20%"></td>
464
+ <td><img src="docs/architectures/high_branch.gif" width="100%"></td>
465
+ </tr>
466
+ </table>
467
+ </p>
468
+
469
+ #### MS-EFF-VIT — Low-Level Branch
470
+
471
+ | Model | Branch-Level | Image | HiresCam | GradCamElementwise | LayerCam |
472
+ | :--- | :---: | :---: | :---: | :---: | :---: |
473
+ | **⚡ ms-eff-vit-b0** | ![](https://img.shields.io/badge/Low_level_Branch-blue?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b0_low_hirescam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b0_low_gradcamelementwise.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b0_low_layercam.JPG" width="100"> |
474
+ | **🔥 ms-eff-vit-b5** | ![](https://img.shields.io/badge/Low_level_Branch-blue?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b5_low_hirescam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b5_low_gradcamelementwise.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b5_low_layercam.JPG" width="100"> |
475
+
476
+ #### MS-Eff-ViT — High-Level Branch
477
+
478
+ | Model | Branch-Level | Image | EigenGradCam | GradCamPlusPlus | XGradCam |
479
+ | :--- | :---: | :---: | :---: | :---: | :---: |
480
+ | **⚡ ms-eff-vit-b0** | ![](https://img.shields.io/badge/High_level_Branch-red?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b0_high_eigengradcam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b0_high_gradcamplusplus.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b0_high_xgradcam.JPG" width="100"> |
481
+ | **🔥 ms-eff-vit-b5** | ![](https://img.shields.io/badge/High_level_Branch-red?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b5_high_eigengradcam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b5_high_gradcamplusplus.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b5_high_xgradcam.JPG" width="100"> |
482
+
483
+ #### MS-EFF-GCVIT — Low-Level Branch
484
+
485
+ | Model | Branch-Level | Image | HiresCam | GradCamElementwise | LayerCam |
486
+ | :--- | :---: | :---: | :---: | :---: | :---: |
487
+ | **⚡ ms-eff-gcvit-b0** | ![](https://img.shields.io/badge/Low_level_Branch-blue?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b0_low_hirescam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b0_low_gradcamelementwise.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b0_low_layercam.JPG" width="100"> |
488
+ | **🔥 ms-eff-gcvit-b5** | ![](https://img.shields.io/badge/Low_level_Branch-blue?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b5_low_hirescam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b5_low_gradcamelementwise.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b5_low_layercam.JPG" width="100"> |
489
+
490
+ #### MS-Eff-GCViT — High-Level Branch
491
+
492
+ | Model | Branch-Level | Image | EigenGradCam | GradCamPlusPlus | XGradCam |
493
+ | :--- | :---: | :---: | :---: | :---: | :---: |
494
+ | **⚡ ms-eff-gcvit-b0** | ![](https://img.shields.io/badge/High_level_Branch-red?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b0_high_eigengradcam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b0_high_gradcamplusplus.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b0_high_xgradcam.JPG" width="100"> |
495
+ | **🔥 ms-eff-gcvit-b5** | ![](https://img.shields.io/badge/High_level_Branch-red?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b5_high_eigengradcam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b5_high_gradcamplusplus.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b5_high_xgradcam.JPG" width="100"> |
496
+
347
497
 
348
498
  ## 📬 Authors
349
499
 
@@ -364,6 +514,7 @@ _**This project was developed as a Senior Graduation Project by the Department o
364
514
  6. [`deepfake-detection-project-v4`](https://github.com/ameencaslam/deepfake-detection-project-v4) - _Multiple Deep Learning Models by Ameen Caslam_
365
515
  7. [`Awesome-Deepfake-Detection`](https://github.com/Daisy-Zhang/Awesome-Deepfakes-Detection
366
516
  ) - _A curated list of tools, papers and code by Daisy Zhang_
517
+ 8. [`Pytorch-Grad-Cam`](https://github.com/jacobgil/pytorch-grad-cam) - _Advanced Visual Explanations for PyTorch Models_
367
518
 
368
519
  ## ⚖️ License
369
520
 
@@ -1,56 +1,17 @@
1
- Metadata-Version: 2.4
2
- Name: deepguard
3
- Version: 0.2.0
4
- Summary: Multi-Scale Efficient Vision Transformer for Robust Deepfake Detection
5
- Home-page: https://github.com/HanMoonSub/DeepGuard
6
- Author: seoyunje
7
- Author-email: seoyunje2001@gmail.com
8
- Project-URL: Bug Tracker, https://github.com/HanMoonSub/DeepGuard/issues
9
- Project-URL: Source Code, https://github.com/HanMoonSub/DeepGuard
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.10
12
- Classifier: Programming Language :: Python :: 3.11
13
- Classifier: License :: OSI Approved :: MIT License
14
- Classifier: Operating System :: OS Independent
15
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
- Requires-Python: >=3.10
17
- Description-Content-Type: text/markdown
18
- License-File: LICENSE
19
- Requires-Dist: torch==2.6.0
20
- Requires-Dist: timm==1.0.12
21
- Requires-Dist: torchmetrics==1.6.1
22
- Requires-Dist: opencv-python==4.11.0.86
23
- Requires-Dist: albumentations==2.0.8
24
- Requires-Dist: Pillow==11.1.0
25
- Requires-Dist: numpy==2.2.0
26
- Requires-Dist: pandas==2.2.3
27
- Requires-Dist: scikit-learn==1.6.1
28
- Requires-Dist: matplotlib==3.10.0
29
- Requires-Dist: seaborn==0.13.2
30
- Requires-Dist: colorama==0.4.6
31
- Dynamic: author
32
- Dynamic: author-email
33
- Dynamic: classifier
34
- Dynamic: description
35
- Dynamic: description-content-type
36
- Dynamic: home-page
37
- Dynamic: license-file
38
- Dynamic: project-url
39
- Dynamic: requires-dist
40
- Dynamic: requires-python
41
- Dynamic: summary
42
-
43
1
  # Deepfakes Detection
44
2
 
45
- <p align="center">
46
- <img src="https://raw.githubusercontent.com/HanMoonSub/DeepGuard/main/Images/deepfake2.png" alt="DeepGuard Banner" width="800" height="400">
47
- </p>
48
-
49
3
  <p align="center">
50
4
  <img src="https://img.shields.io/github/license/HanMoonSub/DeepGuard?style=flat-square&color=555555&logo=github&logoColor=white" alt="License">
51
5
  <img src="https://img.shields.io/github/stars/HanMoonSub/DeepGuard?style=flat-square&color=FFD700&logo=github&logoColor=white" alt="Stars">
6
+ <img src="https://img.shields.io/github/downloads/HanMoonSub/DeepGuard/total?style=flat-square&color=brightgreen&logo=github&logoColor=white" alt="Downloads">
7
+ <img src="https://img.shields.io/github/last-commit/HanMoonSub/DeepGuard?style=flat-square&color=lightgrey&logo=github&logoColor=white" alt="Last Commit">
52
8
  <img src="https://img.shields.io/badge/Status-Active-brightgreen?style=flat-square" alt="Status">
53
9
  <img src="https://img.shields.io/badge/Release-v0.2.0-orange?style=flat-square&logo=github&logoColor=white" alt="Release">
10
+ <img src="https://img.shields.io/github/repo-size/HanMoonSub/DeepGuard?style=flat-square&color=blueviolet" alt="Repo Size">
11
+ </p>
12
+
13
+ <p align="center">
14
+ <img src="docs/samples/deepfake_thumbnails.png" alt="DeepGuard Banner" width="800" height="400">
54
15
  </p>
55
16
 
56
17
  <p align="center">
@@ -69,6 +30,7 @@ Dynamic: summary
69
30
 
70
31
  <p align="center">
71
32
  <a href="README_KR.md"><b>🇰🇷 한국어 버전</b></a> |
33
+ <a href="README_JP.md"><b>🇯🇵 日本語版</b></a> |
72
34
  <a href="#-model-evaluation"><b>📈 Model Evaluation</b></a> |
73
35
  <a href="#-predict-image--video"><b>🔮 Try Demo</b></a>
74
36
  </p>
@@ -85,6 +47,7 @@ Dynamic: summary
85
47
  - [📈 Model Evaluation](#-model-evaluation) - Benchmarking results
86
48
  - [💻 Model Usage](#-model-usage) - How to integrate DeepGuard models into your own Python code or via timm
87
49
  - [🔮 Predict Image & Video](#-predict-image--video) - Simple Inference examples for detecting deepfakes in image and video
50
+ - [🎨 DeepFake AI Explainability](#-deepfake-ai-explainability) - Visualizing model focus using Grad-CAM and attention maps
88
51
  - [📬 Authors](#-authors)
89
52
  - [📝 Reference](#-reference)
90
53
  - [⚖️ License](#-license)
@@ -180,7 +143,7 @@ Multi Scale Efficient Global Context Vision Transformer is an optimized multi-sc
180
143
 
181
144
 
182
145
  <p align="center">
183
- <img src="https://raw.githubusercontent.com/HanMoonSub/DeepGuard/main/Images/ms_eff_gcvit.JPG" width="100%" height="700">
146
+ <img src="docs/architectures/ms_eff_gcvit.JPG" width="100%" height="700">
184
147
  </p>
185
148
 
186
149
  We utilizes two distinct types of self-attention to capture both long-range and short-range information across feature maps.
@@ -191,7 +154,7 @@ We utilizes two distinct types of self-attention to capture both long-range and
191
154
 
192
155
 
193
156
  <p align="center">
194
- <img src=https://raw.githubusercontent.com/HanMoonSub/DeepGuard/main/Images/window_attention.JPG width="100%" height="300">
157
+ <img src=docs/architectures/window_attention.JPG width="100%" height="300">
195
158
  </p>
196
159
 
197
160
  ## 🧬 Model Zoo
@@ -268,7 +231,8 @@ You can load the models directly via the `DeepGuard` package or through the `tim
268
231
  **Installation**
269
232
 
270
233
  ```bash
271
- pip install -U git+https://github.com/HanMoonSub/DeepGuard.git
234
+ # pip install -U git+https://github.com/HanMoonSub/DeepGuard.git
235
+ pip install deepguard
272
236
  ```
273
237
 
274
238
 
@@ -291,6 +255,21 @@ model = timm.create_model("ms_eff_gcvit_b0", pretrained=True, dataset="ff++")
291
255
  model = timm.create_model("ms_eff_gcvit_b5", pretrained=True, dataset="kodf")
292
256
  ```
293
257
 
258
+ **Option C: Hugging Face Hub**
259
+
260
+ ```python
261
+ import torch
262
+ from huggingface_hub import hf_hub_download
263
+ from deepguard import ms_eff_gcvit_b0 # or ms_eff_gcvit_b5
264
+
265
+ REPO_ID = "KoreaPeter/ms-eff-gcvit-deepfake"
266
+
267
+ ckpt = hf_hub_download(REPO_ID, "ms_eff_gcvit_b0_kodf.bin") # celeb_df_v2 | ff++ | kodf
268
+ model = ms_eff_gcvit_b0(pretrained=False)
269
+ model.load_state_dict(torch.load(ckpt, map_location="cpu"))
270
+ model.eval()
271
+ ```
272
+
294
273
  ## 🔮 Predict Image & Video
295
274
 
296
275
  #### Predict DeepFake Image
@@ -344,6 +323,151 @@ print(f"Deepfake Probability: {result:.4f}")
344
323
 
345
324
  ```
346
325
 
326
+ ## 🎨 DeepFake AI Explainability
327
+
328
+ Deepfake detection is only as trustworthy as its explanations. DeepGuard integrates a production-ready XAI Toolkit that visualizes where and why the model flags a face as manipulated — turning a black-box score into actionable forensic evidence.
329
+
330
+ ⭐ Validated on hybrid CNN-ViT architectures, specifically `MS-EffViT` and `MS-EffGCViT`.
331
+ ⭐ Dual-Branch Analysis: Dual-branch design mirrors the model's own multi-scale reasoning
332
+
333
+ ### 🧠 How Dual-Branch XAI Works
334
+
335
+ <p align="center">
336
+ <img src="docs/architectures/dual_branch.gif" width="70%" height="300">
337
+ </p>
338
+
339
+
340
+ | Branch | Feature Map | Focus | Best For |
341
+ | ------ | ----------- | ----- | -------- |
342
+ | ![](https://img.shields.io/badge/Low_level-blue?style=flat-square) | High Resolution | Local Forgery artifacts | Skin texture, boundary blending, compression traces |
343
+ | ![](https://img.shields.io/badge/High_level-red?style=flat-square) | Low Resolution | Global Semantic Structure | Lighting inconsistency, facial geometry, Shadow artifacts |
344
+
345
+ ### 📐 XAI Methods
346
+
347
+ Each method is assigned to the branch where it performs best empirically.
348
+
349
+ | Branch | Method | 🎯 Core Idea |
350
+ | :--- | :--- | :--- |
351
+ | **`low level`** | **HiResCAM** | Like GradCAM but element-wise multiply the activations with the gradients; provably guaranteed faithfulness for certain models |
352
+ | **`low level`** | **GradCAMElementWise** | Like GradCAM but element-wise multiply the activations with the gradients then apply a ReLU operation before summing |
353
+ | **`low level`** | **LayerCAM** | Spatially weight the activations by positive gradients. Works better especially in lower layers |
354
+ | --- | --- | --- | --- |
355
+ | **`high level`** | **EigenGradCAM** | Like EigenCAM but with class discrimination: First principle component of Activations*Grad. Looks like GradCAM, but cleaner |
356
+ | **`high level`** | **GradCAM++** | Like GradCAM but uses second order gradients |
357
+ | **`high level`** | **XGradCAM** | Like GradCAM but scale the gradients by the normalized activations |
358
+
359
+ - **`aug_smooth`** applies TTA (horizontal flips) before averaging CAMs → smoother, more object-aligned maps
360
+ - **`eigen_smooth`** applies PCA noise reduction → retains dominant forgery pattern only
361
+
362
+ ### 💡 DeepFake XAI Usage
363
+
364
+ **Low-Level Branch — Local Artifact Detection**
365
+
366
+ ```python
367
+ from explainability import HiResCAMExplainer, GradCAMElementWiseExplainer, LayerCAMExplainer
368
+
369
+ explainer = HiResCAMExplainer(
370
+ model_name = "ms_eff_gcvit_b0", # or ms_eff_vit_b0, ms_eff_gcvit_b5, ms_eff_vit_b5
371
+ dataset = "celeb_df_v2", # or ff++, kodf
372
+ branch_level = "low",
373
+ )
374
+ ```
375
+
376
+ **High-Level Branch — Global Semantic Detection**
377
+ ```python
378
+ from explainability import EigenGradCAMExplainer, GradCAMPlusPlusExplainer, XGradCAMExplainer
379
+
380
+ explainer = EigenGradCAMExplainer(
381
+ model_name = "ms_eff_gcvit_b0",
382
+ dataset = "celeb_df_v2",
383
+ branch_level = "high",
384
+ )
385
+ ```
386
+
387
+ ### 🎨 Visualization Modes
388
+
389
+ <p align="center">
390
+ <img src="docs/xai-results/xai_demo.gif" width="80%" height=300>
391
+ </p>
392
+
393
+ **1. Heatmap — Continuous activation distribution**
394
+
395
+ ```python
396
+ result = explainer.display_heatmap_on_image(
397
+ img_path = "path/to/image.jpg",
398
+ category = 1, # 0: Real, 1: Fake
399
+ threshold = 0.5, # binarization cutoff (0.5~1.0), or "auto" for Otsu
400
+ image_weight = 0.5, # 0.0: heatmap only ← → 1.0: original only
401
+ aug_smooth = False, # TTA smoothing (not supported on 'pro' models)
402
+ eigen_smooth = False, # PCA noise reduction
403
+ )
404
+ ```
405
+
406
+ **2. Bounding Box — Discrete forgery region localization**
407
+
408
+ ```python
409
+ result = explainer.display_bbox_on_image(
410
+ img_path = "path/to/image.jpg",
411
+ category = 1,
412
+ threshold = 0.5,
413
+ thickness = 1,
414
+ aug_smooth = False,
415
+ eigen_smooth = False,
416
+ )
417
+ ```
418
+
419
+ **3. Heatmap + BBox — Full overlay (recommended for reporting)**
420
+ ```python
421
+ result = explainer.display_heatmap_bbox_on_image(
422
+ img_path = "path/to/image.jpg",
423
+ category = 1,
424
+ threshold = 0.5,
425
+ image_weight = 0.5,
426
+ aug_smooth = False,
427
+ eigen_smooth = False,
428
+ )
429
+ ```
430
+
431
+ ### 📊 Visual Results
432
+
433
+ <p align="center">
434
+ <table>
435
+ <tr>
436
+ <td><img src="docs/architectures/low_branch.gif" width="100%"></td>
437
+ <td width="20%"></td>
438
+ <td><img src="docs/architectures/high_branch.gif" width="100%"></td>
439
+ </tr>
440
+ </table>
441
+ </p>
442
+
443
+ #### MS-EFF-VIT — Low-Level Branch
444
+
445
+ | Model | Branch-Level | Image | HiresCam | GradCamElementwise | LayerCam |
446
+ | :--- | :---: | :---: | :---: | :---: | :---: |
447
+ | **⚡ ms-eff-vit-b0** | ![](https://img.shields.io/badge/Low_level_Branch-blue?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b0_low_hirescam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b0_low_gradcamelementwise.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b0_low_layercam.JPG" width="100"> |
448
+ | **🔥 ms-eff-vit-b5** | ![](https://img.shields.io/badge/Low_level_Branch-blue?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b5_low_hirescam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b5_low_gradcamelementwise.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b5_low_layercam.JPG" width="100"> |
449
+
450
+ #### MS-Eff-ViT — High-Level Branch
451
+
452
+ | Model | Branch-Level | Image | EigenGradCam | GradCamPlusPlus | XGradCam |
453
+ | :--- | :---: | :---: | :---: | :---: | :---: |
454
+ | **⚡ ms-eff-vit-b0** | ![](https://img.shields.io/badge/High_level_Branch-red?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b0_high_eigengradcam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b0_high_gradcamplusplus.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b0_high_xgradcam.JPG" width="100"> |
455
+ | **🔥 ms-eff-vit-b5** | ![](https://img.shields.io/badge/High_level_Branch-red?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b5_high_eigengradcam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b5_high_gradcamplusplus.JPG" width="100"> | <img src="docs/xai-results/ms_eff_vit_b5_high_xgradcam.JPG" width="100"> |
456
+
457
+ #### MS-EFF-GCVIT — Low-Level Branch
458
+
459
+ | Model | Branch-Level | Image | HiresCam | GradCamElementwise | LayerCam |
460
+ | :--- | :---: | :---: | :---: | :---: | :---: |
461
+ | **⚡ ms-eff-gcvit-b0** | ![](https://img.shields.io/badge/Low_level_Branch-blue?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b0_low_hirescam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b0_low_gradcamelementwise.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b0_low_layercam.JPG" width="100"> |
462
+ | **🔥 ms-eff-gcvit-b5** | ![](https://img.shields.io/badge/Low_level_Branch-blue?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b5_low_hirescam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b5_low_gradcamelementwise.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b5_low_layercam.JPG" width="100"> |
463
+
464
+ #### MS-Eff-GCViT — High-Level Branch
465
+
466
+ | Model | Branch-Level | Image | EigenGradCam | GradCamPlusPlus | XGradCam |
467
+ | :--- | :---: | :---: | :---: | :---: | :---: |
468
+ | **⚡ ms-eff-gcvit-b0** | ![](https://img.shields.io/badge/High_level_Branch-red?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b0_high_eigengradcam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b0_high_gradcamplusplus.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b0_high_xgradcam.JPG" width="100"> |
469
+ | **🔥 ms-eff-gcvit-b5** | ![](https://img.shields.io/badge/High_level_Branch-red?style=flat-square) | <img src="docs/samples/images/western/western_fake_1.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b5_high_eigengradcam.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b5_high_gradcamplusplus.JPG" width="100"> | <img src="docs/xai-results/ms_eff_gcvit_b5_high_xgradcam.JPG" width="100"> |
470
+
347
471
 
348
472
  ## 📬 Authors
349
473
 
@@ -364,6 +488,7 @@ _**This project was developed as a Senior Graduation Project by the Department o
364
488
  6. [`deepfake-detection-project-v4`](https://github.com/ameencaslam/deepfake-detection-project-v4) - _Multiple Deep Learning Models by Ameen Caslam_
365
489
  7. [`Awesome-Deepfake-Detection`](https://github.com/Daisy-Zhang/Awesome-Deepfakes-Detection
366
490
  ) - _A curated list of tools, papers and code by Daisy Zhang_
491
+ 8. [`Pytorch-Grad-Cam`](https://github.com/jacobgil/pytorch-grad-cam) - _Advanced Visual Explanations for PyTorch Models_
367
492
 
368
493
  ## ⚖️ License
369
494