Spaces:
Runtime error
Runtime error
jinyin_chen commited on
Commit ·
4a76882
1
Parent(s): 5c642f9
readme
Browse files- README.md +80 -51
- README_zh.md +91 -0
README.md
CHANGED
|
@@ -1,77 +1,106 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
<p align='center'>
|
| 4 |
-
<img src='
|
| 5 |
</p>
|
| 6 |
|
| 7 |
-
|
| 8 |
|
| 9 |
-
##
|
| 10 |
|
| 11 |
-
|
| 12 |
-
- [Framework](#framework)
|
| 13 |
-
- [Dependency](#dependency)
|
| 14 |
-
- [Inference](#inference)
|
| 15 |
-
- [Training](#training)
|
| 16 |
-
- [Acknowledgement](#acknowledgement)
|
| 17 |
|
|
|
|
| 18 |
|
| 19 |
-
##
|
| 20 |
-
The visualization of features in the official split of training and validation sets reveals two key insights: 1) the similarity in distribution between the training and validation sets makes it challenging to evaluate the model's performance on unseen test sets; 2) the feature types of fake data are richer compared to real data. This insight inspired us to initially use unsupervised clustering to partition the challenging validation set, followed by augmenting the types of real and fake data based on adversarial learning principles. These insights led to the development of our proposed generalizable deepfake detection method.
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
|
|
|
| 26 |
|
| 27 |
-
##
|
| 28 |
-
The framework of our proposed method consists of two primary stages: Data Preparing and Training. In the Data Preparing stage, we focus on augmenting the existing dataset by generating new data through image editing and Stable Diffusion (SD) techniques. We then perform clustering to reassemble the dataset, aiming to enhance both the detection performance and the robustness of our method. In the Training stage, we introduce a series of expert models and optimize them using three types of losses: $L_{\mathsf{KL}}$, $L_{\mathsf{NCE}}$, and $L_{\mathsf{CE}}$. This multi-loss approach ensures that the model can effectively differentiate between authentic and manipulated images. Please refer to the tech report (will be on arXiv later) for more details.
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
-
- torch 1.9.0
|
| 36 |
-
- timm 1.0.8
|
| 37 |
-
- scikit-learn 1.2.1
|
| 38 |
-
- torch-ema 0.3
|
| 39 |
-
- torch_kmeans 0.2.0
|
| 40 |
-
- albumentations 1.3.1
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
```
|
| 47 |
-
|
| 48 |
-
```
|
| 49 |
-
|
| 50 |
-
>> Prediction of [demo/img_1_should_be_0.0016829653177410.jpg] being Deepfake: 0.001683078
|
| 51 |
```
|
| 52 |
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
-
The training code (e.g., unsupervised clustering and joint optimization loss) and detailed technical report will be available shortly.
|
| 57 |
|
| 58 |
-
##
|
| 59 |
-
- THIS WORK WAS PERFORMED IN PART AT SICC WHICH IS SUPPORTED BY SKL-IOTSC, UNIVERSITY OF MACAU.
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
##
|
| 68 |
-
|
| 69 |
-
[Creative Commons Attribution-NonCommercial 4.0 International License][cc-by-nc].
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
|
| 74 |
-
[cc-by-nc-image]: https://licensebuttons.net/l/by-nc/4.0/88x31.png
|
| 75 |
-
[cc-by-nc-shield]: https://img.shields.io/badge/License-CC%20BY--NC%204.0-lightgrey.svg
|
| 76 |
|
| 77 |
-
|
|
|
|
| 1 |
+
<h2 align="center"> <a href="">DeepFake Defenders</a></h2>
|
| 2 |
+
<h5 align="center"> If you like our project, please give us a star ⭐ on GitHub for latest update. </h5>
|
| 3 |
+
|
| 4 |
+
<h5 align="center">
|
| 5 |
+
|
| 6 |
+
<!-- PROJECT SHIELDS -->
|
| 7 |
+
[](https://github.com/VisionRush/DeepFakeDefenders/blob/main/LICENSE)
|
| 8 |
+

|
| 9 |
+
[](https://hits.seeyoufarm.com)
|
| 10 |
+

|
| 11 |
+
[](https://github.com/PKU-YuanGroup/MoE-LLaVA/issues?q=is%3Aopen+is%3Aissue)
|
| 12 |
+
[](https://github.com/PKU-YuanGroup/MoE-LLaVA/issues?q=is%3Aissue+is%3Aclosed) <br>
|
| 13 |
+
|
| 14 |
+
</h5>
|
| 15 |
|
| 16 |
<p align='center'>
|
| 17 |
+
<img src='./images/competition_title.png' width='850'/>
|
| 18 |
</p>
|
| 19 |
|
| 20 |
+
💡 We also provide [[中文文档 / CHINESE DOC](README_zh.md)]. We very welcome and appreciate your contributions to this project.
|
| 21 |
|
| 22 |
+
## 📣 News
|
| 23 |
|
| 24 |
+
* **[2024.09.05]** 🔥 We officially released the initial version of Deepfake defenders, and we won the third prize in the deepfake challenge at [[the conference on the bund](https://www.atecup.cn/deepfake)].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
## 🚀 Quickly Start
|
| 27 |
|
| 28 |
+
### 1. Pretrained Models Preparation
|
|
|
|
| 29 |
|
| 30 |
+
Before getting started, please place the ImageNet-1K pretrained weight files in the `./pre_model` directory. The download links for the weights are provided below:
|
| 31 |
+
```
|
| 32 |
+
RepLKNet: https://drive.google.com/file/d/1vo-P3XB6mRLUeDzmgv90dOu73uCeLfZN/view?usp=sharing
|
| 33 |
+
ConvNeXt: https://dl.fbaipublicfiles.com/convnext/convnext_base_1k_384.pth
|
| 34 |
+
```
|
| 35 |
|
| 36 |
+
### 2. Training from Scratch
|
| 37 |
|
| 38 |
+
#### 2.1 Modifying the dataset path
|
|
|
|
| 39 |
|
| 40 |
+
Place the training-set **(\*.txt)** file, validation-set **(\*.txt)** file, and label **(\*.txt)** file required for training in the dataset folder and name them with the same file name (there are various txt examples under dataset)
|
| 41 |
+
|
| 42 |
+
#### 2.2 Modifying the Hyper-parameters
|
| 43 |
|
| 44 |
+
For the two models (RepLKNet and ConvNeXt) used, the following parameters need to be changed in `main_train.py`:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
```python
|
| 47 |
+
# For RepLKNet
|
| 48 |
+
cfg.network.name = 'replknet'; cfg.train.batch_size = 16
|
| 49 |
+
# For ConvNeXt
|
| 50 |
+
cfg.network.name = 'convnext'; cfg.train.batch_size = 24
|
| 51 |
+
```
|
| 52 |
|
| 53 |
+
#### 2.3 Using the training script
|
| 54 |
+
##### Multi-GPUs:(8 GPUs were used)
|
| 55 |
+
```shell
|
| 56 |
+
bash main.sh
|
| 57 |
```
|
| 58 |
+
##### Single-GPU:
|
| 59 |
+
```shell
|
| 60 |
+
CUDA_VISIBLE_DEVICES=0 python main_train_single_gpu.py
|
|
|
|
| 61 |
```
|
| 62 |
|
| 63 |
+
#### 2.4 Model Assembling
|
| 64 |
|
| 65 |
+
Replace the ConvNeXt trained model path and the RepLKNet trained model path in `merge.py`, and execute `python merge.py` to obtain the final inference test model.
|
|
|
|
| 66 |
|
| 67 |
+
### 2.5 Inference
|
|
|
|
| 68 |
|
| 69 |
+
The following example uses the **POST** request interface to request the image path as the request parameter, and the response output is the deepfake score predicted by the model.
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
#!/usr/bin/env python
|
| 73 |
+
# -*- coding:utf-8 -*-
|
| 74 |
+
import requests
|
| 75 |
+
import json
|
| 76 |
+
import requests
|
| 77 |
+
import json
|
| 78 |
|
| 79 |
+
header = {
|
| 80 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36'
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
url = 'http://ip:10005/inter_api'
|
| 84 |
+
image_path = './dataset/val_dataset/51aa9b8d0da890cd1d0c5029e3d89e3c.jpg'
|
| 85 |
+
data_map = {'img_path':image_path}
|
| 86 |
+
response = requests.post(url, data=json.dumps(data_map), headers=header)
|
| 87 |
+
content = response.content
|
| 88 |
+
print(json.loads(content))
|
| 89 |
+
```
|
| 90 |
|
| 91 |
+
### 3. Deploy in Docker
|
| 92 |
+
#### Building
|
|
|
|
| 93 |
|
| 94 |
+
```shell
|
| 95 |
+
sudo docker build -t vision-rush-image:1.0.1 --network host .
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
#### Running
|
| 99 |
+
|
| 100 |
+
```shell
|
| 101 |
+
sudo docker run -d --name vision_rush_image --gpus=all --net host vision-rush-image:1.0.1
|
| 102 |
+
```
|
| 103 |
|
| 104 |
+
## Star History
|
|
|
|
|
|
|
| 105 |
|
| 106 |
+
[](https://star-history.com/#DeepFakeDefenders/DeepFakeDefenders&Date)
|
README_zh.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<h2 align="center"> <a href="">DeepFake Defenders</a></h2>
|
| 2 |
+
<h5 align="center"> 如果您喜欢我们的项目,请在 GitHub 上给我们一个Star ⭐ 以获取最新更新。 </h5>
|
| 3 |
+
|
| 4 |
+
<h5 align="center">
|
| 5 |
+
|
| 6 |
+
<!-- PROJECT SHIELDS -->
|
| 7 |
+
[](https://github.com/VisionRush/DeepFakeDefenders/blob/main/LICENSE)
|
| 8 |
+

|
| 9 |
+
[](https://hits.seeyoufarm.com)
|
| 10 |
+

|
| 11 |
+
[](https://github.com/PKU-YuanGroup/MoE-LLaVA/issues?q=is%3Aopen+is%3Aissue)
|
| 12 |
+
[](https://github.com/PKU-YuanGroup/MoE-LLaVA/issues?q=is%3Aissue+is%3Aclosed) <br>
|
| 13 |
+
|
| 14 |
+
</h5>
|
| 15 |
+
|
| 16 |
+
<p align='center'>
|
| 17 |
+
<img src='./images/competition_title.png' width='850'/>
|
| 18 |
+
</p>
|
| 19 |
+
|
| 20 |
+
💡 我们在这里提供了[[英文文档 / ENGLISH DOC](README.md)],我们十分欢迎和感谢您能够对我们的项目提出建议和贡献。
|
| 21 |
+
|
| 22 |
+
## 📣 News
|
| 23 |
+
|
| 24 |
+
* **[2024.09.05]** 🔥 我们正式发布了Deepfake Defenders的初始版本,并在Deepfake挑战赛中获得了三等奖
|
| 25 |
+
[[外滩大会](https://www.atecup.cn/deepfake)].
|
| 26 |
+
|
| 27 |
+
## 🚀 快速开始
|
| 28 |
+
### 一、预训练模型准备
|
| 29 |
+
在开始使用之前,请将模型的ImageNet-1K预训练权重文件放置在`./pre_model`目录下,权重下载链接如下:
|
| 30 |
+
```
|
| 31 |
+
RepLKNet: https://drive.google.com/file/d/1vo-P3XB6mRLUeDzmgv90dOu73uCeLfZN/view?usp=sharing
|
| 32 |
+
ConvNeXt: https://dl.fbaipublicfiles.com/convnext/convnext_base_1k_384.pth
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
### 二、训练
|
| 36 |
+
|
| 37 |
+
#### 1. 更改数据集路径
|
| 38 |
+
将训练所需的训练集txt文件、验证集txt文件以及标签txt文件分别放置在dataset文件夹下,并命名为相同的文件名(dataset下有各个txt示例)
|
| 39 |
+
#### 2. 更改超参数
|
| 40 |
+
针对所采用的两个模型,在main_train.py中分别需要更改如下参数:
|
| 41 |
+
```python
|
| 42 |
+
RepLKNet---cfg.network.name = 'replknet'; cfg.train.batch_size = 16
|
| 43 |
+
ConvNeXt---cfg.network.name = 'convnext'; cfg.train.batch_size = 24
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
#### 3. 启动训练
|
| 47 |
+
##### 单机多卡训练:(8卡)
|
| 48 |
+
```shell
|
| 49 |
+
bash main.sh
|
| 50 |
+
```
|
| 51 |
+
##### 单机单卡训练:
|
| 52 |
+
```shell
|
| 53 |
+
CUDA_VISIBLE_DEVICES=0 python main_train_single_gpu.py
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
#### 4. 模型融合
|
| 57 |
+
在merge.py中更改ConvNeXt模型路径以及RepLKNet模型路径,执行python merge.py后获取最终推理测试模型。
|
| 58 |
+
|
| 59 |
+
#### 5. 推理
|
| 60 |
+
|
| 61 |
+
示例如下,通过post请求接口请求,请求参数为图像路径,响应输出为模型预测的deepfake分数
|
| 62 |
+
|
| 63 |
+
```python
|
| 64 |
+
#!/usr/bin/env python
|
| 65 |
+
# -*- coding:utf-8 -*-
|
| 66 |
+
import requests
|
| 67 |
+
import json
|
| 68 |
+
import requests
|
| 69 |
+
import json
|
| 70 |
+
|
| 71 |
+
header = {
|
| 72 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36'
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
url = 'http://ip:10005/inter_api'
|
| 76 |
+
image_path = './dataset/val_dataset/51aa9b8d0da890cd1d0c5029e3d89e3c.jpg'
|
| 77 |
+
data_map = {'img_path':image_path}
|
| 78 |
+
response = requests.post(url, data=json.dumps(data_map), headers=header)
|
| 79 |
+
content = response.content
|
| 80 |
+
print(json.loads(content))
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
### 三、docker
|
| 84 |
+
#### 1. docker构建
|
| 85 |
+
sudo docker build -t vision-rush-image:1.0.1 --network host .
|
| 86 |
+
#### 2. 容器启动
|
| 87 |
+
sudo docker run -d --name vision_rush_image --gpus=all --net host vision-rush-image:1.0.1
|
| 88 |
+
|
| 89 |
+
## Star History
|
| 90 |
+
|
| 91 |
+
[](https://star-history.com/#DeepFakeDefenders/DeepFakeDefenders&Date)
|