deepguard 0.2.0__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.
- deepguard-0.2.0/LICENSE +21 -0
- deepguard-0.2.0/PKG-INFO +370 -0
- deepguard-0.2.0/README.md +328 -0
- deepguard-0.2.0/deepguard/__init__.py +28 -0
- deepguard-0.2.0/deepguard/data/__init__.py +11 -0
- deepguard-0.2.0/deepguard/data/dataset.py +62 -0
- deepguard-0.2.0/deepguard/data/dataset_cutmix.py +195 -0
- deepguard-0.2.0/deepguard/data/dataset_cutout.py +153 -0
- deepguard-0.2.0/deepguard/data/dataset_mixup.py +115 -0
- deepguard-0.2.0/deepguard/data/handle_imbalance.py +44 -0
- deepguard-0.2.0/deepguard/data/split_data.py +83 -0
- deepguard-0.2.0/deepguard/data/transforms.py +76 -0
- deepguard-0.2.0/deepguard/layers/__init__.py +16 -0
- deepguard-0.2.0/deepguard/layers/attention.py +194 -0
- deepguard-0.2.0/deepguard/layers/drop.py +35 -0
- deepguard-0.2.0/deepguard/layers/featextractor.py +56 -0
- deepguard-0.2.0/deepguard/layers/global_query.py +65 -0
- deepguard-0.2.0/deepguard/layers/mlp.py +41 -0
- deepguard-0.2.0/deepguard/layers/patch.py +138 -0
- deepguard-0.2.0/deepguard/layers/reducesize.py +45 -0
- deepguard-0.2.0/deepguard/layers/se.py +28 -0
- deepguard-0.2.0/deepguard/layers/transformer.py +409 -0
- deepguard-0.2.0/deepguard/layers/weight_init.py +30 -0
- deepguard-0.2.0/deepguard/layers/window.py +22 -0
- deepguard-0.2.0/deepguard/models/__init__.py +0 -0
- deepguard-0.2.0/deepguard/models/ms_eff_gcvit.py +288 -0
- deepguard-0.2.0/deepguard/models/ms_eff_vit.py +264 -0
- deepguard-0.2.0/deepguard/optimizer/__init__.py +1 -0
- deepguard-0.2.0/deepguard/optimizer/build_optimizer.py +160 -0
- deepguard-0.2.0/deepguard/scheduler/__init__.py +1 -0
- deepguard-0.2.0/deepguard/scheduler/fetch_scheduler.py +59 -0
- deepguard-0.2.0/deepguard/utils/__init__.py +4 -0
- deepguard-0.2.0/deepguard/utils/build_metrics.py +23 -0
- deepguard-0.2.0/deepguard/utils/early_stopping.py +24 -0
- deepguard-0.2.0/deepguard/utils/meter.py +26 -0
- deepguard-0.2.0/deepguard/utils/seed.py +23 -0
- deepguard-0.2.0/deepguard.egg-info/PKG-INFO +370 -0
- deepguard-0.2.0/deepguard.egg-info/SOURCES.txt +57 -0
- deepguard-0.2.0/deepguard.egg-info/dependency_links.txt +1 -0
- deepguard-0.2.0/deepguard.egg-info/requires.txt +12 -0
- deepguard-0.2.0/deepguard.egg-info/top_level.txt +2 -0
- deepguard-0.2.0/preprocess/celeb_df_v2/__init__.py +0 -0
- deepguard-0.2.0/preprocess/celeb_df_v2/crop_face.py +194 -0
- deepguard-0.2.0/preprocess/celeb_df_v2/detect_original_face.py +129 -0
- deepguard-0.2.0/preprocess/celeb_df_v2/split_data.py +0 -0
- deepguard-0.2.0/preprocess/celeb_df_v2/utils.py +60 -0
- deepguard-0.2.0/preprocess/ff++/__init__.py +0 -0
- deepguard-0.2.0/preprocess/ff++/crop_face.py +201 -0
- deepguard-0.2.0/preprocess/ff++/detect_original_face.py +140 -0
- deepguard-0.2.0/preprocess/ff++/split_data.py +127 -0
- deepguard-0.2.0/preprocess/ff++/utils.py +65 -0
- deepguard-0.2.0/preprocess/kodf/__init__.py +0 -0
- deepguard-0.2.0/preprocess/kodf/crop_face.py +204 -0
- deepguard-0.2.0/preprocess/kodf/detect_original_face.py +138 -0
- deepguard-0.2.0/preprocess/kodf/generate_metadata.py +75 -0
- deepguard-0.2.0/preprocess/kodf/split_data.py +107 -0
- deepguard-0.2.0/preprocess/kodf/utils.py +72 -0
- deepguard-0.2.0/setup.cfg +4 -0
- deepguard-0.2.0/setup.py +45 -0
deepguard-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 MOONSUB HAN
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
deepguard-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
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
|
+
# Deepfakes Detection
|
|
44
|
+
|
|
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
|
+
<p align="center">
|
|
50
|
+
<img src="https://img.shields.io/github/license/HanMoonSub/DeepGuard?style=flat-square&color=555555&logo=github&logoColor=white" alt="License">
|
|
51
|
+
<img src="https://img.shields.io/github/stars/HanMoonSub/DeepGuard?style=flat-square&color=FFD700&logo=github&logoColor=white" alt="Stars">
|
|
52
|
+
<img src="https://img.shields.io/badge/Status-Active-brightgreen?style=flat-square" alt="Status">
|
|
53
|
+
<img src="https://img.shields.io/badge/Release-v0.2.0-orange?style=flat-square&logo=github&logoColor=white" alt="Release">
|
|
54
|
+
</p>
|
|
55
|
+
|
|
56
|
+
<p align="center">
|
|
57
|
+
<img src="https://img.shields.io/badge/Task-Deepfake_Detection-red?style=flat-square" alt="Task">
|
|
58
|
+
<img src="https://img.shields.io/badge/Dataset-FaceForensics%2B%2B-blue?style=flat-square" alt="FF++">
|
|
59
|
+
<img src="https://img.shields.io/badge/Dataset-Celeb--DF(v2)-green?style=flat-square" alt="Celeb-DF">
|
|
60
|
+
<img src="https://img.shields.io/badge/Dataset-KODF-yellowgreen?style=flat-square" alt="KODF">
|
|
61
|
+
</p>
|
|
62
|
+
|
|
63
|
+
<p align="center">
|
|
64
|
+
<img src="https://img.shields.io/badge/Model-MS--Eff--GCViT--B0%20%2F%20B5-orange?style=flat-square" alt="Models">
|
|
65
|
+
<img src="https://img.shields.io/badge/Python-3.10+-3776AB?style=flat-square&logo=python&logoColor=white" alt="Python">
|
|
66
|
+
<img src="https://img.shields.io/badge/PyTorch-EE4C2C?style=flat-square&logo=pytorch&logoColor=white" alt="PyTorch">
|
|
67
|
+
<img src="https://img.shields.io/badge/W%26B-Recording-FFBE00?style=flat-square&logo=weightsandbiases&logoColor=white" alt="W&B">
|
|
68
|
+
</p>
|
|
69
|
+
|
|
70
|
+
<p align="center">
|
|
71
|
+
<a href="README_KR.md"><b>🇰🇷 한국어 버전</b></a> |
|
|
72
|
+
<a href="#-model-evaluation"><b>📈 Model Evaluation</b></a> |
|
|
73
|
+
<a href="#-predict-image--video"><b>🔮 Try Demo</b></a>
|
|
74
|
+
</p>
|
|
75
|
+
|
|
76
|
+
## 📌 Contents
|
|
77
|
+
|
|
78
|
+
- [💡 Install & Requirements](#-install--requirements)
|
|
79
|
+
- [🛠 SetUp](#-setup)
|
|
80
|
+
- [📚 DeepFake Video BenchMark Datasets](#-deepfake-video-benchmark-datasets) — Overview of Celeb-DF-v2, FF++, and KoDF datasets used for training.
|
|
81
|
+
- [⚙️ Data Preparation](#data-preparation) — Efficient face detection and landmark extraction pipeline using YOLOv8
|
|
82
|
+
- [🏗 Model Architecture](#-model-architecture) — Detailed look into our hybrid CNN-ViT (MS-EffViT & MS-EffGCViT) designs.
|
|
83
|
+
- [🧬 Model Zoo](#-model-zoo) — Comparison of model variants, parameter counts, and computational complexity (FLOPs).
|
|
84
|
+
- [🚀 Training](#-training) - Step-by-step training scrips with Goolge Colab and W&B experiment tracking
|
|
85
|
+
- [📈 Model Evaluation](#-model-evaluation) - Benchmarking results
|
|
86
|
+
- [💻 Model Usage](#-model-usage) - How to integrate DeepGuard models into your own Python code or via timm
|
|
87
|
+
- [🔮 Predict Image & Video](#-predict-image--video) - Simple Inference examples for detecting deepfakes in image and video
|
|
88
|
+
- [📬 Authors](#-authors)
|
|
89
|
+
- [📝 Reference](#-reference)
|
|
90
|
+
- [⚖️ License](#-license)
|
|
91
|
+
|
|
92
|
+
## 💡 Install & Requirements
|
|
93
|
+
|
|
94
|
+
To install requirements:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
pip install -r requirements.txt
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 🛠 SetUp
|
|
101
|
+
|
|
102
|
+
Clone the repository and move into it:
|
|
103
|
+
```
|
|
104
|
+
git clone https://github.com/HanMoonSub/DeepGuard.git
|
|
105
|
+
|
|
106
|
+
cd DeepGuard
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## 📚 DeepFake Video BenchMark Datasets
|
|
110
|
+
|
|
111
|
+
To evaluate the generalization and robustness of our deepfake detection model, we utilize three large-scale, widely recognized benchmark datasets. Each dataset presents unique challenges and covers different types of forgery methods.
|
|
112
|
+
|
|
113
|
+
| Dataset | Real Videos | Fake Videos | Year | Participants | Description (Paper Title) | Details |
|
|
114
|
+
| :--- | :---: | :---: | :---: | :---: | :--- | :---: |
|
|
115
|
+
| **Celeb-DF-v2** | 890 | 5,639 | 2019 | 59 | *A Large-scale Challenging Dataset for DeepFake Forensics* | [🔗 Readme](preprocess/celeb_df_v2/README.md) |
|
|
116
|
+
| **FaceForensics++** | 1,000 | 6,000 | 2019 | 1,000 | *Learning to Detect Manipulated Facial Images* | [🔗 Readme](preprocess/ff++/README.md) |
|
|
117
|
+
| **KoDF** | 62,166 | 175,776 | 2020 | 400 | *Large-Scale Korean Deepfake Detection Dataset* | [🔗 Readme](preprocess/kodf/README.md) |
|
|
118
|
+
|
|
119
|
+
<div id="data-preparation"></div>
|
|
120
|
+
|
|
121
|
+
## ⚙️ Data Preparation
|
|
122
|
+
|
|
123
|
+
Our preprocessing pipeline is designed to efficiently extract facial features from videos and prepare them for high-accuracy deepfake detection.
|
|
124
|
+
|
|
125
|
+
### Detect Original Face
|
|
126
|
+
To maximize preprocessing efficiency, <ins>**face detection is performed only on original (real) videos.**</ins> Since mnipulated videos in DeepFake Video BenchMark Datasets share the same spatial coordinates as their sources, these bounding boxes are reused for the corresponding deepfake versions.
|
|
127
|
+
|
|
128
|
+
🚀 Efficiency Optimizations
|
|
129
|
+
- **Lightweight Model**: Uses yolov8n-face for high-speed inference without sacrificing accuracy.
|
|
130
|
+
|
|
131
|
+
- **Targeted Processing**: By detecting faces only in original videos, the total detection workload is reduced by approximately 80%.
|
|
132
|
+
|
|
133
|
+
- **Dynamic Rescaling**: To maintain consistent inference speed across different resolutions, frames are automatically resized based on their dimensions:
|
|
134
|
+
|
|
135
|
+
| Frame Size(Longest Side) | Scale Factor | Action |
|
|
136
|
+
| ------------------------ | ------------ | ------ |
|
|
137
|
+
| < 300px | 2.0 |  |
|
|
138
|
+
| 300px - 700px | 1.0 |  |
|
|
139
|
+
| 700px - 1500px | 0.5 |  |
|
|
140
|
+
| > 1500px | 0.33 |  |
|
|
141
|
+
|
|
142
|
+
### Face Cropping & Landmark Extraction
|
|
143
|
+
This module extracts face crops from both original and deepfake videos using the bounding boxes generated in the previous step. It also performs landmark detection to facilitate advanced augmentations like Landmark-based Cutout
|
|
144
|
+
|
|
145
|
+
🛠 Key Features
|
|
146
|
+
- **Dynamic Margin with Jitter**: Adds a configurable margin around the face. The margin_jitter parameter introduces random variance to the crop size, making the model more robust to different face scales.
|
|
147
|
+
|
|
148
|
+
- **Landmark Localization**: `Detects 5 primary facial landmarks` (eyes, nose, mouth corners) and saves them as .npy files.
|
|
149
|
+
|
|
150
|
+
```Plaintext
|
|
151
|
+
DATA_ROOT/
|
|
152
|
+
├── crops/
|
|
153
|
+
│ └── {video_id}/
|
|
154
|
+
│ ├── 12.png
|
|
155
|
+
│ └── ...
|
|
156
|
+
├── landmarks/
|
|
157
|
+
│ └── {video_id}/
|
|
158
|
+
│ ├── 12.npy
|
|
159
|
+
│ └── ...
|
|
160
|
+
└── train_frame_metadata.csv
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Dataset-Specific Pipelines
|
|
164
|
+
|
|
165
|
+
Click the links below to view the specific preprocessing details for each dataset:
|
|
166
|
+
|
|
167
|
+
* [**Celeb-DF V2 Preprocess**](/preprocess/celeb_df_v2/README.md)
|
|
168
|
+
* [**FaceForensics++ Preprocess**](/preprocess/ff++/README.md)
|
|
169
|
+
* [**KoDF Preprocess**](/preprocess/kodf/README.md)
|
|
170
|
+
|
|
171
|
+
## 🏗 Model Architecture
|
|
172
|
+
|
|
173
|
+
Multi Scale Efficient Global Context Vision Transformer is an optimized multi-scale hybrid architecture that integrates CNN-driven spatial inductive bias with hierarchical attention mechanisms to effectively identify subtle(local) artifacts and macro(global) artifacts for robust deepfake forensics."
|
|
174
|
+
|
|
175
|
+
#### Explore More Details
|
|
176
|
+
|
|
177
|
+
- [Model Architecture: MS-EffViT](deepguard/MS_EffViT.md) - _**Multi Scale Efficient Vision Transformer**_
|
|
178
|
+
|
|
179
|
+
- [Advanced Architecture: MS-EFFGCViT](deepguard/MS_EffGCViT.md) - _**Multi Scale Efficient Global Context Vision Transformer**_
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
<p align="center">
|
|
183
|
+
<img src="https://raw.githubusercontent.com/HanMoonSub/DeepGuard/main/Images/ms_eff_gcvit.JPG" width="100%" height="700">
|
|
184
|
+
</p>
|
|
185
|
+
|
|
186
|
+
We utilizes two distinct types of self-attention to capture both long-range and short-range information across feature maps.
|
|
187
|
+
|
|
188
|
+
- **Local Window Attention**: this model efficiently captures local textures and precise spatial details while maintaining linear computational complexity relative to the image size.
|
|
189
|
+
|
|
190
|
+
- **Global Window Attention**: Unlike Swin Transformer, this module utilizes global-queries that interact with local window keys and values. This allows each local region to incorporate global context, effectively capturing long-range dependencies and providing a comprehensive understanding of the entire spatial structure
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
<p align="center">
|
|
194
|
+
<img src=https://raw.githubusercontent.com/HanMoonSub/DeepGuard/main/Images/window_attention.JPG width="100%" height="300">
|
|
195
|
+
</p>
|
|
196
|
+
|
|
197
|
+
## 🧬 Model Zoo
|
|
198
|
+
|
|
199
|
+
| Model | Resolution | # Total Params(M) | # Backbone(M) | # L-ViT(M) | # H-ViT(M) | FLOPs (G) | Model Config |
|
|
200
|
+
| ----- | ---------- | -------------- | ----------- |------------- | ------------- | -------------- | ------- |
|
|
201
|
+
| ⚡ ms_eff_gcvit_b0 | 224 X 224 | 8.7 | 3.6(41.4%) | 1.7(19.5%) | 3.3(37.9%) | 0.87 | [spec](deepguard/config/ms_eff_gcvit_b5/celeb_df_v2.yaml) |
|
|
202
|
+
| 🔥 ms_eff_gcvit_b5 | 384 X 384 | 50.3 | 27.3(54.3%) | 6.6(13.1%) | 16.1(32.0%) | 13.64 | [spec](deepguard/config/ms_eff_gcvit_b5/celeb_df_v2.yaml) |
|
|
203
|
+
|
|
204
|
+
## 🚀 Training
|
|
205
|
+
|
|
206
|
+
We provide training scripts for both `ms_eff_vit` and `ms_eff_gcvit`. We recommend using **Google Colab** for free GPU access and **Weightes & Biases(W&B)** for experiment tracking
|
|
207
|
+
|
|
208
|
+
#### 📊 Weight & Biases Experiments
|
|
209
|
+
|
|
210
|
+
* **ms_eff_vit_b0:** [Celeb-DF-v2 🚀](https://wandb.ai/origin6165/ms_eff_vit_b0_celeb_df_v2) | [FaceForensics++ 🚀](https://wandb.ai/origin6165/ms_eff_vit_b0_ff++) | [KoDF 🚀](https://wandb.ai/origin6165/ms_eff_vit_b0_kodf)
|
|
211
|
+
* **ms_eff_vit_b5:** [Celeb-DF-v2 🚀](https://wandb.ai/origin6165/ms_eff_vit_b5_celeb_df_v2) | [FaceForensics++ 🚀](https://wandb.ai/origin6165/ms_eff_vit_b5_ff++) | [KoDF 🚀](https://wandb.ai/origin6165/ms_eff_vit_b5_kodf)
|
|
212
|
+
* **ms_eff_gcvit_b0:** [Celeb-DF-v2 🚀](https://wandb.ai/origin6165/ms_eff_gcvit_b0_celeb_df_v2) | [FaceForensics++ 🚀](https://wandb.ai/origin6165/ms_eff_gcvit_b0_ff++) | [KoDF 🚀](https://wandb.ai/origin6165/ms_eff_gcvit_b0_kodf)
|
|
213
|
+
* **ms_eff_gcvit_b5:** [Celeb-DF-v2 🚀](https://wandb.ai/origin6165/ms_eff_gcvit_b5_celeb_df_v2) | [FaceForensics++ 🚀](https://wandb.ai/origin6165/ms_eff_gcvit_b5_ff++) | [KoDF 🚀](https://wandb.ai/origin6165/ms_eff_gcvit_b5_kodf)
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
!python -m train_eff_vit \ # train_eff_gcvit
|
|
217
|
+
--root-dir DATA_ROOT \
|
|
218
|
+
--model-ver "ms_eff_vit_b5" \ # ms_eff_vit_b0, ms_eff_vit_b5, ms_eff_gcvit_b0, ms_eff_gcvit_b5
|
|
219
|
+
--dataset "ff++" \ # ff++, celeb_df_v2, kodf
|
|
220
|
+
--seed 2025 \ # for reproducibility
|
|
221
|
+
--wandb-api-key "your-api-key" # Write your own api key
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## 📈 Model Evaluation
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
!python -m inference.predict_video \
|
|
228
|
+
--root-dir DATA_ROOT \
|
|
229
|
+
--margin-ratio 0.2 \
|
|
230
|
+
--conf-thres 0.5 \
|
|
231
|
+
--min-face-ratio 0.01 \
|
|
232
|
+
--model-name "ms_eff_gcvit_b0" \ # ms_eff_vit_b0, ms_eff_vit_b5, ms_eff_gcvit_b0, ms_eff_gcvit_b5
|
|
233
|
+
--model-dataset "kodf" \ # ff++, celeb_df_v2, kodf
|
|
234
|
+
--num-frames 20 \
|
|
235
|
+
--tta-hflip 0.0 \
|
|
236
|
+
--agg-mode "conf" \
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
**Celeb DF(v2) Pretrained Models**
|
|
241
|
+
|
|
242
|
+
| Model Variant | Test@Acc | Test@Auc | Test@log_loss | Download | Train Config |
|
|
243
|
+
| ------------- | -------- | -------- | ---------- | -------- | ----- |
|
|
244
|
+
| ms_eff_gcvit_b0 | 0.9842 | 0.9965 | 0.0283 | [model](https://github.com/HanMoonSub/DeepGuard/releases/download/v0.1.0/ms_eff_gcvit_b0_celeb_df_v2.bin) | [recipe](deepguard/config/ms_eff_gcvit_b0/celeb_df_v2.yaml) |
|
|
245
|
+
| ms_eff_gcvit_b5 | 0.9981 | 0.9984 | 0.0089 | [model](https://github.com/HanMoonSub/DeepGuard/releases/download/v0.1.0/ms_eff_gcvit_b5_celeb_df_v2.bin) | [recipe](deepguard/config/ms_eff_gcvit_b5/celeb_df_v2.yaml) |
|
|
246
|
+
|
|
247
|
+
**FaceForensics++ Pretrained Models**
|
|
248
|
+
|
|
249
|
+
| Model Variant | Test@Acc | Test@Auc | Test@log_loss | Download | Train Config |
|
|
250
|
+
| ------------- | -------- | -------- | ---------- | -------- | ------ |
|
|
251
|
+
| ms_eff_gcvit_b0 | 0.9808 | 0.9969 | 0.0637| [model](https://github.com/HanMoonSub/DeepGuard/releases/download/v0.1.0/ms_eff_gcvit_b0_ff++.bin) | [recipe](deepguard/config/ms_eff_gcvit_b0/celeb_df_v2.yaml) |
|
|
252
|
+
| ms_eff_gcvit_b5 | 0.9850 | 0.9974 | 0.0492 | [model](https://github.com/HanMoonSub/DeepGuard/releases/download/v0.1.0/ms_eff_gcvit_b5_ff++.bin) | [recipe](deepguard/config/ms_eff_gcvit_b5/celeb_df_v2.yaml) |
|
|
253
|
+
|
|
254
|
+
**KoDF Pretrained Models**
|
|
255
|
+
|
|
256
|
+
| Model Variant | Test@Acc | Test@Auc | Test@log_loss | Download | Train Config |
|
|
257
|
+
| ------------- | -------- | -------- | ---------- | -------- | ------ |
|
|
258
|
+
| ms_eff_gcvit_b0 | 0.9655 | 0.9792 | 0.1237 | [model](https://github.com/HanMoonSub/DeepGuard/releases/download/v0.2.0/ms_eff_gcvit_b0_kodf.bin) | [recipe](deepguard/config/ms_eff_gcvit_b0/celeb_df_v2.yaml) |
|
|
259
|
+
| ms_eff_gcvit_b5 | 0.9850 | 0.9974 | 0.0492 | [model](https://github.com/HanMoonSub/DeepGuard/releases/download/v0.2.0/ms_eff_gcvit_b5_kodf.bin) | [recipe](deepguard/config/ms_eff_gcvit_b5/celeb_df_v2.yaml) |
|
|
260
|
+
|
|
261
|
+
## 💻 Model Usage
|
|
262
|
+
|
|
263
|
+
**Quick Start**
|
|
264
|
+
You can load the models directly via the `DeepGuard` package or through the `timm` interface.
|
|
265
|
+
|
|
266
|
+
**Available Datasets**: `celeb_df_v2`, `ff++`, `kodf`
|
|
267
|
+
|
|
268
|
+
**Installation**
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
pip install -U git+https://github.com/HanMoonSub/DeepGuard.git
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
**Option A: Direct Import (via DeepGuard)**
|
|
276
|
+
|
|
277
|
+
```python
|
|
278
|
+
from deepguard import ms_eff_gcvit_b0, ms_eff_gcvit_b5
|
|
279
|
+
|
|
280
|
+
model = ms_eff_gcvit_b0(pretrained=True, dataset="celeb_df_v2")
|
|
281
|
+
model = ms_eff_gcvit_b5(pretrained=True, dataset="ff++")
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
**Option B: Using timm Interface (via timm)**
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
import timm
|
|
288
|
+
import deepguard
|
|
289
|
+
|
|
290
|
+
model = timm.create_model("ms_eff_gcvit_b0", pretrained=True, dataset="ff++")
|
|
291
|
+
model = timm.create_model("ms_eff_gcvit_b5", pretrained=True, dataset="kodf")
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## 🔮 Predict Image & Video
|
|
295
|
+
|
|
296
|
+
#### Predict DeepFake Image
|
|
297
|
+
|
|
298
|
+
```python
|
|
299
|
+
|
|
300
|
+
from inference.image_predictor import ImagePredictor
|
|
301
|
+
|
|
302
|
+
# Initialize the predictor
|
|
303
|
+
predictor = ImagePredictor(
|
|
304
|
+
margin_ratio = 0.2, # Margin ratio around the detected face crop
|
|
305
|
+
conf_thres = 0.5, # Confidence threshold for face detection
|
|
306
|
+
min_face_ratio = 0.01, # Minimum face-toframe size ratio to process
|
|
307
|
+
model_name = "ms_eff_vit_b0", # ms_eff_vit_b5, ms_eff_gcvit_b0, ms_eff_gcvit_b5
|
|
308
|
+
dataset = "celeb_df_v2" # ff++, kodf
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
# Run Inference
|
|
312
|
+
result = predictor.predict_img(
|
|
313
|
+
img_path="path/to/image.jpg",
|
|
314
|
+
tta_hflip=0.0 # Horizontal Flip for Test-Time Augmentation
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
print(f"Deepfake Probability: {result:.4f}")
|
|
318
|
+
|
|
319
|
+
```
|
|
320
|
+
#### Predict DeepFake Video
|
|
321
|
+
|
|
322
|
+
```python
|
|
323
|
+
|
|
324
|
+
from inference.video_predictor import VideoPredictor
|
|
325
|
+
|
|
326
|
+
# Initialize the predictor
|
|
327
|
+
predictor = VideoPredictor(
|
|
328
|
+
margin_ratio = 0.2, # Margin ratio around the detected face crop
|
|
329
|
+
conf_thres = 0.5, # Confidence threshold for face detection
|
|
330
|
+
min_face_ratio = 0.01, # Minimum face-toframe size ratio to process
|
|
331
|
+
model_name = "ms_eff_vit_b0", # ms_eff_vit_b5, ms_eff_gcvit_b0, ms_eff_gcvit_b5
|
|
332
|
+
dataset = "celeb_df_v2" # ff++, kodf
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
# Run Inference
|
|
336
|
+
result = predictor.predict_video(
|
|
337
|
+
video_path = "path/to/video.mp4",
|
|
338
|
+
num_frames = 20, # Number of frames to sample per video
|
|
339
|
+
agg_mode = "conf", # Aggregation Method: 'conf', 'mean', 'vote'
|
|
340
|
+
tta_hflip=0.0 # Horizontal Flip for Test-Time Augmentation
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
print(f"Deepfake Probability: {result:.4f}")
|
|
344
|
+
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
## 📬 Authors
|
|
349
|
+
|
|
350
|
+
_**This project was developed as a Senior Graduation Project by the Department of Software at Chungbuk National University (CBNU), Republic of Korea.**_
|
|
351
|
+
|
|
352
|
+
* **한문섭**: **Data & Backend Engineering** (Data Preprocessing Pipeline, DB Schema Design) — [hanmoon3054@gmail.com](mailto:hanmoon3054@gmail.com)
|
|
353
|
+
* **이예솔**: **UI/UX & Frontend Engineering** (UI/UX Design, User Dashboard, Model Visualization) — [yesol4138@chungbuk.ac.kr](mailto:yesol4138@chungbuk.ac.kr)
|
|
354
|
+
* **서윤제**: **AI Engineering** (AI Model Architecture, Inference API Design, Model Serving) — [seoyunje2001@gmail.com](mailto:seoyunje2001@gmail.com)
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
## 📝 Reference
|
|
358
|
+
|
|
359
|
+
1. [`facenet-pytorch`](https://github.com/timesler/facenet-pytorch) - _Pretrained Face Detection(MTCNN) and Recognition(InceptionResNet) Models by Tim Esler_
|
|
360
|
+
2. [`face-cutout`](https://github.com/sowmen/face-cutout) - _Face Cutout Library by Sowmen_
|
|
361
|
+
3. [`Celeb-DF++`](https://github.com/OUC-VAS/Celeb-DF-PP) - _Celeb-DF++ Dataset by OUC-VAS Group_
|
|
362
|
+
4. [`DeeperForensics-1.0`](https://github.com/EndlessSora/DeeperForensics-1.0) - _DeeperForensics-1.0 Dataset by Endless Sora_
|
|
363
|
+
5. [`Deepfake Detection`](https://github.com/abhijithjadhav/Deepfake_detection_using_deep_learning) - _Detection of Video Deepfake using ResNext and LSTM by Abhijith Jadhav_
|
|
364
|
+
6. [`deepfake-detection-project-v4`](https://github.com/ameencaslam/deepfake-detection-project-v4) - _Multiple Deep Learning Models by Ameen Caslam_
|
|
365
|
+
7. [`Awesome-Deepfake-Detection`](https://github.com/Daisy-Zhang/Awesome-Deepfakes-Detection
|
|
366
|
+
) - _A curated list of tools, papers and code by Daisy Zhang_
|
|
367
|
+
|
|
368
|
+
## ⚖️ License
|
|
369
|
+
|
|
370
|
+
This project is licensed under the terms of the MIT license.
|