• Stars
    star
    152
  • Rank 239,545 (Top 5 %)
  • Language
    Jupyter Notebook
  • License
    MIT License
  • Created almost 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Code for Video Deepfake Detection model from "Combining EfficientNet and Vision Transformers for Video Deepfake Detection" presented at ICIAP 2021.

Combining EfficientNet and Vision Transformers for Video Deepfake Detection

PWC

Code for Video Deepfake Detection model from "Combining EfficientNet and Vision Transformers for Video Deepfake Detection" available on Arxiv and presented at ICIAP 2021 [Pre-print PDF | Springer]. Using this repository it is possible to train and test the two main architectures presented in the paper, Efficient Vision Transformers and Cross Efficient Vision Transformers, for video deepfake detection. The architectures exploits internally the EfficientNet-Pytorch and ViT-Pytorch repositories.

Setup

Clone the repository and move into it:

git clone https://github.com/davide-coccomini/Combining-EfficientNet-and-Vision-Transformers-for-Video-Deepfake-Detection.git

cd Combining-EfficientNet-and-Vision-Transformers-for-Video-Deepfake-Detection

Setup Python environment using conda:

conda env create --file environment.yml
conda activate deepfakes
export PYTHONPATH=.

Get the data

Download and extract the dataset you want to use from:

Preprocess the data

The preprocessing phase is based on Selim Seferbekov implementation.

In order to perform deepfake detection it is necessary to first identify and extract faces from all the videos in the dataset. Detect the faces inside the videos:

cd preprocessing
python3 detect_faces.py --data_path "path/to/videos"

By default the consideted dataset structure will be the one of DFDC but you can customize it with the following parameter:

  • --dataset: Dataset (DFDC / FACEFORENSICS)

The extracted boxes will be saved inside the "path/to/videos/boxes" folder. In order to get the best possible result, make sure that at least one face is identified in each video. If not, you can reduce the threshold values of the MTCNN on line 38 of face_detector.py and run the command again until at least one detection occurs. At the end of the execution of face_detector.py an error message will appear if the detector was unable to find faces inside some videos.

If you want to manually check that at least one face has been identified in each video, make sure that the number of files in the "boxes" folder is equal to the number of videos. To count the files in the folder use:

cd path/to/videos/boxes
ls | wc -l

Extract the detected faces obtaining the images:

python3 extract_crops.py --data_path "path/to/videos" --output_path "path/to/output"

By default the consideted dataset structure will be the one of DFDC but you can customize it with the following parameter:

  • --dataset: Dataset (DFDC / FACEFORENSICS)

Repeat detection and extraction for all the different parts of your dataset.

After extracting all the faces from the videos in your dataset, organise the "dataset" folder as follows:

- dataset
    - training_set
        - Deepfakes
            - video_name_0
                0_0.png
                1_0.png
                2_0.png
                ...
                N_0.png
            ...
            - video_name_K
                0_0.png
                1_0.png
                2_0.png
                ...
                M_0.png
        - DFDC
        - Face2Face
        - FaceShifter
        - FaceSwap
        - NeuralTextures
        - Original
    - validation_set
        ...
            ...
                ...
                ...
    - test_set
        ...
            ...
                ...
                ...

We suggest to exploit the --output_path parameter when executing extract_crops.py to build the folders structure properly.

Evaluate

Move into the choosen architecture folder you want to evaluate and download the pre-trained model:

(Efficient ViT)

cd efficient-vit
wget http://datino.isti.cnr.it/efficientvit_deepfake/efficient_vit.pth

(Cross Efficient ViT)

cd cross-efficient-vit
wget http://datino.isti.cnr.it/efficientvit_deepfake/cross_efficient_vit.pth

If you are unable to use the previous urls you can download the weights from Google Drive.

Then, issue the following commands for evaluating a given model giving the pre-trained model path and the configuration file available in the config directory:

python3 test.py --model_path "pretrained_models/[model]" --config "configs/architecture.yaml"

By default the command will test on DFDC dataset but you can customize the following parameters for both the architectures:

  • --dataset: Which dataset to use (Deepfakes|Face2Face|FaceShifter|FaceSwap|NeuralTextures|DFDC)
  • --max_videos: Maximum number of videos to use for training (default: all)
  • --workers: Number of data loader workers (default: 10)
  • --frames_per_video: Number of equidistant frames for each video (default: 30)
  • --batch_size: Prediction Batch Size (default: 32)

To evaluate a customized model trained from scratch with a different architecture you need to edit the configs/architecture.yaml file.

Train

Only for DFDC dataset, prepare the metadata moving all of them (by default inside dfdc_train_part_X folders) into a subfolder:

mkdir data/metadata
cd path/to/videos/training_set
mv **/metadata.json ../../../data/metadata

In order to train the model using our architectures configurations use:

(Efficient ViT)

cd efficient-vit
python3 train.py --config configs/architecture.yaml

(Cross Efficient ViT)

cd cross-efficient-vit
python3 train.py --config configs/architecture.yaml

By default the commands will train on DFDC dataset but you can customize the following parameters for both the architectures:

  • --num_epochs: Number of training epochs (default: 300)
  • --workers: Number of data loader workers (default: 10)
  • --resume: Path to latest checkpoint (default: none)
  • --dataset: Which dataset to use (Deepfakes|Face2Face|FaceShifter|FaceSwap|NeuralTextures|All) (default: All)
  • --max_videos: Maximum number of videos to use for training (default: all)
  • --patience: How many epochs wait before stopping for validation loss not improving (default: 5)

Only for the Efficient ViT model it's also possible to custom the patch extractor and use different versions of EfficientNet (only B0 and B7) by adding the following parameter:

  • --efficient_net: Which EfficientNet version to use (0 or 7, default: 0)

Reference

@InProceedings{10.1007/978-3-031-06433-3_19,
author="Coccomini, Davide Alessandro
and Messina, Nicola
and Gennaro, Claudio
and Falchi, Fabrizio",
editor="Sclaroff, Stan
and Distante, Cosimo
and Leo, Marco
and Farinella, Giovanni M.
and Tombari, Federico",
title="Combining EfficientNet and Vision Transformers for Video Deepfake Detection",
booktitle="Image Analysis and Processing -- ICIAP 2022",
year="2022",
publisher="Springer International Publishing",
address="Cham",
pages="219--229",
isbn="978-3-031-06433-3"
}

More Repositories

1

MINTIME-Multi-Identity-size-iNvariant-TIMEsformer-for-Video-Deepfake-Detection

Code for Video Deepfake Detector from "MINTIME: Multi-Identity Size-Invariant Video Deepfake Detection", pre-print available on Arxiv
Jupyter Notebook
45
star
2

TimeSformer-Video-Classification

The notebook explains the various steps to obtain the results of publication: "Is Space-Time Attention All You Need for Video Understanding?"
Jupyter Notebook
37
star
3

Detecting-Images-Generated-by-Diffusers

Jupyter Notebook
24
star
4

GAN-Universe

This repository contains part of the code used to make the images visible in the article "How does an AI Imagine the Universe?" published on Towards Data Science.
Python
11
star
5

ml-checklist

This tool can be used while you are working on a research project or at the end of it to make sure that you have done everything correctly and rigorously. The system will return a score for each of the four parameters taken into account, namely Robustness, Rigorousness, Completeness and Comparability.
HTML
8
star
6

Deepfake-Detection-Challenge-DFAD2023

Implementation of solution for the Media Analytics Challenge.
Jupyter Notebook
5
star
7

LSDataBase

Large Scale Database Working Group
Java
4
star
8

Runtics

A mobile game brain teaser developed using React Native and React Redux.
JavaScript
4
star
9

Internet-of-Things-Smart-Home

Makefile
3
star
10

KMeans-MapReduce

Distributed development applied to KMeans clustering algorithm using Hadoop and Spark.
Java
3
star
11

SmartFridge

Desktop application to manage an intelligent fridge.
Java
3
star
12

Cross-Forgery-Analysis-of-Vision-Transformers-and-CNNs-for-Deepfake-Image-Detection

Code for the paper Cross Forgery Analysis of Vision Transformers and CNNs for Deepfake Image Detection
Python
3
star
13

Publication-Tracker

Software to allow people to explore the information about authors and their publications, using a graph database with Neo4j and data scraped from Google Scholar.
Java
3
star
14

Cross-Forgery-Video-Deepfake-Detection

Code for paper "On the Generalization of Deep Learning Models in Video Deepfake Detection"
Python
2
star
15

Coronavirus-Data-Visualization

Python
2
star
16

Everli-Calculator

2
star
17

tftp

TFTP is a very simple protocol used to transfer files. It is from this that its name comes, Trivial File Transfer Protocol or TFTP.
C
2
star
18

Fanta-GOT

Fanta-GOT is an online game based on Game of Thrones.
PHP
2
star
19

Liar-Recognition

Machine Learning allow us to recognize the behavior of a person trying to understand if he/she is lying. This simple Python program try to do this based on some characteristics identified by psychologists about the people who lie.
Python
2
star
20

Predicting-Tornadoes-days-ahead-with-Machine-Learning

This is the official repository of the paper "Predicting Tornadoes days ahead with Machine Learning" and is designed to allow other researchers to reproduce the results presented in the paper but also to exploit the dataset for their own experiments. Within this repository there are also a number of additional files used in the research phase to explore the effectiveness of various approaches.
Python
2
star
21

Valhalla

An online browsergame based on the Vikings' history.
PHP
2
star
22

RO-Questioner

A simple web assistant to prepare the Ricerca Operativa exam at university of Pisa.
PHP
1
star
23

HashCode-2021

Python program to efficiently schedule traffic lights in a simulated road network, developed for Hash Code 2021
Python
1
star
24

Adversarial-Magnification-to-Deceive-Deepfake-Detection-through-Super-Resolution

Official code for the paper "Adversarial Magnification to Deceive Deepfake Detection through Super Resolution"
Python
1
star
25

Hyperspectral-image-manipulation

C++
1
star
26

Analisi-della-percezione-delle-differenze-cromatiche-al-variare-della-risoluzione

TeX
1
star
27

FieldGenerator

Website to create arenas, perfect table role-games.
HTML
1
star
28

netcdf2text

Python
1
star
29

Internship-Report

TeX
1
star
30

compression-image

C++
1
star
31

Hashcode2018

Python
1
star
32

gnocchi-api

Python
1
star
33

CyberSecurity

C++
1
star
34

Invoicer

This is an extension to automatically fill the invoice for Appen projects workers
JavaScript
1
star
35

GTA-V-Objects

CSS
1
star
36

davide-coccomini.github.io

HTML
1
star
37

DungeonsAndDiary

Do you play at D&D and you are never able to decide a day to play? With this web application you can tell to the others when you are free and the system will find the perfect day to play!
PHP
1
star
38

GoCV-Test

Go
1
star
39

Client-Server-messaging

A messaging system that allows the exchange of messages between different users
C
1
star
40

Lab-SSIM

The structural similarity (SSIM) index is a method for predicting the perceived quality of digital television and cinematic pictures, as well as other kinds of digital images and videos.
C++
1
star
41

Algorithmic-problems

C++
1
star
42

parts-detection

C++
1
star
43

ArenaCraft-Store

Template based on BuyCraft for the shop of ArenaCraft, a famous Minecraft server.
HTML
1
star
44

Filo-d-oro

Simple template made using bootstrap for an elegant restaurant.
HTML
1
star
45

GAN-Cars-Generator

1
star
46

fantagot-data-analysis

R
1
star
47

Convolutional-Neural-Network-for-Medical-Imaging-Analysis-Abnormality-detection-in-mammography

Classifiers trained to distinguish between masses and calcifications within mammograms and classifiers able to distinguish whether masses and calcifications are malignant or benign.
Jupyter Notebook
1
star
48

Mojivote

In the past, Facebook was invaded by a river of polls where the people could vote using emoji. I've thought that if the people used to love this type of polls, I could try to create a "Social network" based on them. From this, birth Mojivote!
PHP
1
star
49

Battery-Report

Windows provided to create an html page to visualize battery information but to create this page needs to use the command line and it could be a problem for the medium user. This very simple program solve this problem in one click.
Batchfile
1
star