jinyin_chen commited on
Commit
4a76882
·
1 Parent(s): 5c642f9
Files changed (2) hide show
  1. README.md +80 -51
  2. README_zh.md +91 -0
README.md CHANGED
@@ -1,77 +1,106 @@
1
- # DeepFakeDefenders
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  <p align='center'>
4
- <img src='https://github.com/HighwayWu/DeepFakeDefenders/blob/main/imgs/competition.png' width='850'/>
5
  </p>
6
 
7
- 1st place solution for [The Global Multimedia Deepfake Detection (Image Track)](https://www.kaggle.com/competitions/multi-ffdi/overview) by "JTGroup" team.
8
 
9
- ## Table of Contents
10
 
11
- - [Motivation](#motivation)
12
- - [Framework](#framework)
13
- - [Dependency](#dependency)
14
- - [Inference](#inference)
15
- - [Training](#training)
16
- - [Acknowledgement](#acknowledgement)
17
 
 
18
 
19
- ## Motivation
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
- <p align='center'>
23
- <img src='https://github.com/HighwayWu/DeepFakeDefenders/blob/main/imgs/motivation.jpg' width='850'/>
24
- </p>
 
 
25
 
 
26
 
27
- ## Framework
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
- <p align='center'>
31
- <img src='https://github.com/HighwayWu/DeepFakeDefenders/blob/main/imgs/framework.jpg' width='850'/>
32
- </p>
33
 
34
- ## Dependency
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
- ## Inference
 
 
 
 
 
43
 
44
- ```bash
45
- >> python infer.py
 
 
46
  ```
47
- Enter the image path and expect the following result:
48
- ```bash
49
- >> demo/img_1_should_be_0.0016829653177410.jpg
50
- >> Prediction of [demo/img_1_should_be_0.0016829653177410.jpg] being Deepfake: 0.001683078
51
  ```
52
 
53
- **Note: The pretrained weights can be downloaded from [Baidu Pan](https://pan.baidu.com/s/1hh6Rub60T7UXok5rqACffQ?pwd=gxu5).**
54
 
55
- ## Training
56
- The training code (e.g., unsupervised clustering and joint optimization loss) and detailed technical report will be available shortly.
57
 
58
- ## Acknowledgement
59
- - THIS WORK WAS PERFORMED IN PART AT SICC WHICH IS SUPPORTED BY SKL-IOTSC, UNIVERSITY OF MACAU.
60
 
61
- <p align='left'>
62
- <img src='https://github.com/HighwayWu/DeepFakeDefenders/blob/main/imgs/organization.png' width='450'/>
63
- </p>
 
 
 
 
 
 
64
 
65
- - INCLUSION·CONFERENCE ON THE BUND, THE ORGANIZER OF THE COMPETITION.
 
 
 
 
 
 
 
 
 
 
66
 
67
- ## License
68
- This work is licensed under a
69
- [Creative Commons Attribution-NonCommercial 4.0 International License][cc-by-nc].
70
 
71
- [![CC BY-NC 4.0][cc-by-nc-image]][cc-by-nc]
 
 
 
 
 
 
 
 
72
 
73
- [cc-by-nc]: https://creativecommons.org/licenses/by-nc/4.0/
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
- For inquiries or to obtain permission for commercial use, please contact Yiming Chen (yc17486@umac.mo).
 
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
+ [![License](https://img.shields.io/badge/License-Apache%202.0-yellow)](https://github.com/VisionRush/DeepFakeDefenders/blob/main/LICENSE)
8
+ ![GitHub contributors](https://img.shields.io/github/contributors/VisionRush/DeepFakeDefenders)
9
+ [![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FVisionRush%2FDeepFakeDefenders&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=Visitors&edge_flat=false)](https://hits.seeyoufarm.com)
10
+ ![GitHub Repo stars](https://img.shields.io/github/stars/VisionRush/DeepFakeDefenders)
11
+ [![GitHub issues](https://img.shields.io/github/issues/VisionRush/DeepFakeDefenders?color=critical&label=Issues)](https://github.com/PKU-YuanGroup/MoE-LLaVA/issues?q=is%3Aopen+is%3Aissue)
12
+ [![GitHub closed issues](https://img.shields.io/github/issues-closed/VisionRush/DeepFakeDefenders?color=success&label=Issues)](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
+ [![Star History Chart](https://api.star-history.com/svg?repos=VisionRush/DeepFakeDefenders&type=Date)](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
+ [![License](https://img.shields.io/badge/License-Apache%202.0-yellow)](https://github.com/VisionRush/DeepFakeDefenders/blob/main/LICENSE)
8
+ ![GitHub contributors](https://img.shields.io/github/contributors/VisionRush/DeepFakeDefenders)
9
+ [![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FVisionRush%2FDeepFakeDefenders&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=Visitors&edge_flat=false)](https://hits.seeyoufarm.com)
10
+ ![GitHub Repo stars](https://img.shields.io/github/stars/VisionRush/DeepFakeDefenders)
11
+ [![GitHub issues](https://img.shields.io/github/issues/VisionRush/DeepFakeDefenders?color=critical&label=Issues)](https://github.com/PKU-YuanGroup/MoE-LLaVA/issues?q=is%3Aopen+is%3Aissue)
12
+ [![GitHub closed issues](https://img.shields.io/github/issues-closed/VisionRush/DeepFakeDefenders?color=success&label=Issues)](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
+ [![Star History Chart](https://api.star-history.com/svg?repos=VisionRush/DeepFakeDefenders&type=Date)](https://star-history.com/#DeepFakeDefenders/DeepFakeDefenders&Date)