filonenkoa / FAS-LatentDistributionAdjusting

An unofficial PyTorch implementation of Latent Distribution Adjusting for Face Anti-Spoofing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Latent Distribution Adjusting

This is an extension of the unofficial implementation of Latent Distribution Adjusting for Face Anti-Spoofing using PyTorch. The code base is rewritten from PyTorch Lightning to vanilla PyTorch to ensure the better control of everything.

Improvements to the original repository

  • Transfer from PyTorch Lightning to vanilla PyTorch
  • EfficientFormerV2 support
  • FastViT support
  • Use config files
  • Data augmentations
  • TurboJPEG support for faster image decoding
  • Multiple datasets training
  • Compute FAS-related metrics (ACER, etc.)
  • Telegram reports
  • Compute metrics for each val dataset separately
  • Split validation into miltiple GPUs
  • Balanced sampler suitable for DDP
  • Reparametrization efficiency evaluation for supported models
  • Conversion to ONNX

How to use

Installation

$ python3 -m venv env
$ source env/bin/activate
$ pip install -r requirements.txt

Pretrained weights

When using EfficientFormerV2 model, put pretrained weights to weights/efficientformerv2

Telegram reports

This repository supports sending messages after each epoch to a telegram bot.
To make it work, create .env file with Telegram bot token and chat ids:

$ cp .env.template .env
$ nano .env

Data preparation

datasets
    |---images
    |     |--img1
    |     |--img2
    |     |...
    |---train.csv
    |---val.csv
    |---test.csv

with [*.csv] having format (label only has 2 classes: 0-Spoofing, 1-Bonafide):

image_name      |  label
img_name1.jpg   |    0
img_name2.png   |    1
...

image_name is the relative path to the image from the locations of the *.csv file.
One can find utility to convert exisiting images dataset into format supported by current repository in utils/dataset_preparation/prepare_dataset.py

Training

torchrun --standalone --nnodes=1 --nproc_per_node=4 train.py --config config.yaml

nproc_per_node is the number of GPUs you want to use.

About

An unofficial PyTorch implementation of Latent Distribution Adjusting for Face Anti-Spoofing.

License:GNU General Public License v3.0


Languages

Language:Python 99.9%Language:Shell 0.1%