Home

Awesome

Implementation of F3-Net​ : Frequency in Face Forgery Network

Note

This is a personal implementation of F3-Net , so there are lots of difference compared to the official version. To learn more details about F3-Net, please check the paper here.

Result

Model is tested on FaceForensics++ LQ data and reports AUC.

ModelPaperValid(Mine)Test(Mine)
Baseline89.392.089.6
FAD90.791.389.5
LFS88.987.584.7
Both92.891.088.6
Mix93.3\\

Obviously, there's something wrong with the implementation of LFS branch and I'm working on it now.

Usage

Hyperparameter

Hyperparameters are in train.py.

Variable nameDescription
dataset_pathThe path of dataset, support FF++ only.
pretrained_pathThe path of pretrained Xception model.
batch_size128 in paper.
max_epochhow many epochs to train the model.
loss_freqprint loss after how many iterations
modemode of the network, see details below.

Load a pretrained Xception

Download Xception model trained on ImageNet (through this link) or use your own pretrained Xception.

Then modify the pretrained_path variable.

Use FF++ dataset

The dataset related function is designed for FaceForensics++ dataset. Check this github repo or paper for more details of the dataset.

After preprocessing, the data should be organized as following:

|-- dataset
|   |-- train
|   |   |-- real
|   |   |	|-- 000
|   |   |	|	|-- frame0.jpg
|   |   |	|	|-- frame1.jpg
|   |   |	|	|-- ...
|   |   |	|-- 001
|   |   |	|-- ...
|   |   |-- fake
|   |   	|-- Deepfakes
|   |   	|	|-- 000_167
|   |		|	|	|-- frame0.jpg
|   |		|	|	|-- frame1.jpg
|   |		|	|	|-- ...
|   |		|	|-- 001_892
|   |		|	|-- ...
|   |   	|-- Face2Face
|   |		|	|-- ...
|   |   	|-- FaceSwap
|   |   	|-- NeuralTextures
|   |-- valid
|   |	|-- real
|   |	|	|-- ...
|   |	|-- fake
|   |		|-- ...
|   |-- test
|   |	|-- ...

Model mode

There are four modes supported in F3-Net​.

Mode(string)
'FAD'Use FAD branch only.
'LFS'Use LFS branch only.
'Both'Use both of branches and concate before classification.
'Mix'(unavailable)Use both of branches and MixBlock.

Note:

Mode 'Mix' is unavailable yet. If you're interested in this part, check 'class Mixblock' in models.py.

Run

Environment:

Pytorch, torchvision, numpy, sklearn, pillow are needed.

To train the model

python train.py

Reference

Yuyang Qian, Guojun Yin, Lu Sheng, Zixuan Chen, and Jing Shao. Thinking in frequency: Face forgery detection by mining frequency-aware clues. arXiv preprint arXiv:2007.09355, 2020

Paper Link