DeepFake Detector (DFD) is a CLI program used to test how well one of supported DeepFake detection methods1
differentiate DeepFake's from images altered by common image modification methods such as gamma correction. This tool
was used in my bachelor
thesis Testing robustness of DeepFake recognition methods against non-malicious image modification
Videos can be used as evidences in judicial cases and police investigations. In such scenario it is crucial for DeepFake recognition method used to properly discriminate DeepFake from authentic video whose brightness was adjusted.
- CLI program allowing to:
- Preprocess dataset containing real and fake videos. Chosen part of negatives is modified by selected non-malicious
image modifications based on settings assigned by user.
- Preprocessing can be done via single command or gradually in steps where single step represents activity such
as
extract faces from fake videos.
The letter method allows preprocessing large datasets2 on without the need of keeping program on for 24+ hours.
- Preprocessing can be done via single command or gradually in steps where single step represents activity such
as
- Train detection model and evaluate it in assigned settings.
- Preprocess dataset containing real and fake videos. Chosen part of negatives is modified by selected non-malicious
image modifications based on settings assigned by user.
Assuming that INPUT
points to directory containing two sub-directories:
- reals -> containing authentic videos
- fakes -> containing DeepFakes The following commands can be used to train and evaluate Meso-4 model in default settings3:
# Preprocess data . More advanced users can optionally split this command
# into smaller steps , such as face extraction from negatives .
# This can be utilized while working with large datasets such as Celeb - DF .
dfd preprocess ${INPUT} ${OUTPUT} dataset ${STORAGE}
dfd train --output-path ${MODEL} ${OUTPUT}/train ${OUTPUT}/validation
dfd test ${MODEL} ${OUTPUT} / test
dfd predict MODEL ${DATA_SAMPLE}
To list possible commands use dfd --help
. Most configurable params use reasonable defaults. The modifications used to
alter negatives are configured via YAML files. Here is a sample:
---
# Example modifications settings.
# In total half of negatives are altered.
modifications:
- name: RedEyesEffectModification
share: 0.125
options:
brightness_threshold: 50
- name: CLAHEModification
share: 0.125
options:
clip_limit: 2.0
grid_width: 8
grid_height: 8
- name: HistogramEqualizationModification
share: 0.125
- name: GaussianBlurModification
share: 0.125
options:
kernel_width: 9
kernel_height: 9
The names of supported modifications can be found in this file.
The application design is loosely inspired
by Hexagonal Architecture pattern
.
Since DFD is relatively simple, Hexagonal Architecture pattern is not fully embraced. Instead, two components
corresponding to ports are defined: ModificationRegistry
and ModelRegistry
. The concrete implementations of ML
models and image modifications play the roles of adapters plugged to their respective ports.
- TL;DR:
pip install git+https://github.com/cicheck/dfd.git
- The program is tested under Ubuntu 20.04.3, however the use of tox in testing process should ensure that the package is largely independent of tested system and the installation process is similar for all major recent releases of Windows or Unix like system.
- Requirements:
- Python version 3.9.X
- Recommendations:
- It is strongly recommended to use Python's virtual environments to avoid package version clashes.
- The program can be run without CUDA configured however if the GPU is enabled it might significantly speed up computations.
- The application uses TensorFlow 2.5.0, which for GPU based computations requires: