Giter Club home page Giter Club logo

fas-patchnet's Introduction

PatchNet: A Simple Face Anti-Spoofing Framework via Fine-Grained Patch Recognition

This repository implements PatchNet from paper PatchNet: A Simple Face Anti-Spoofing Framework via Fine-Grained Patch Recognition (UNOFFICIAL)

After carefully examining the original repository, I have identified a number of missing features that I believe would greatly benefit its functionality. In light of this, I have made the decision to fork the repository and implement these features. Specifically, I incorporated distributed data parallel as well as training and validation for multiple datasets.

Improvements to the original repository

  • More augmentations (torchvision ➞ albumentations)
  • TurboJPEG support for faster image decoding
  • DDP support
  • Multiple datasets training
  • Utility to convert datasets
  • Compute FAS-related metrics (ACER, etc.)
  • Incorporate loss into a model (the whole inference can be exported to a single ONNX file)
  • Telegram reports
  • Compute metrics for each val dataset separately
  • Split validation into miltiple GPUs
  • Balanced sampler suitable for DDP
  • Conversion to ONNX
  • Reparametrization efficiency evaluation for supported models

Supported backbones

  • EfficientFormerV2
  • FastViT

Installation

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

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

Usage

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 tool/train.py --config config.yaml

nproc_per_node is the number of GPUs you want to use.

Testing

This step has not been remade by me yet. Your conrtibution is welcome.
Go to tool/test.py and fix saved_name to your path to checkpoint
Run

python3 test.py

Conversion to ONNX

Use a script utils/convert_to_onnx.py. It will create 2 versions of models: for batch size = 1 and for dynamic batch size. Some inference engines require all the dimensions fixed.

Original repository contributors

  • Tien Thong Doan
  • Minh Chau Nguyen
  • Minh Hung Nguyen

This repository contributors

  • Alexander Filonenko

fas-patchnet's People

Contributors

filonenkoa avatar doantienthongbku avatar

Stargazers

Alejandro Mora avatar Li Yang avatar Lương Nguyên Khoa avatar Trường An avatar xiaohan avatar  avatar abc_xyz avatar  avatar  avatar  avatar 9000 Machine avatar Randy Pangestu avatar WangDong avatar  avatar  avatar

Forkers

van-2k

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.