K-FACE Analysis Project on Pytorch

Overview

Installation

Setup with Conda

# create a new environment
conda create --name insightKface python=3.7 # or over
conda activate insightKface

#install the appropriate cuda version of pytorch(https://pytorch.org/)
#example:
conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge

# install requirements
pip install -r requirements.txt

Data prepration

K-FACE Database

K-FACE AI-hub.

Detail configuration about K-FACE is provided in the paper below.

K-FACE: A Large-Scale KIST Face Database in Consideration with Unconstrained Environments

K-FACE sample images

title

Structure of the K-FACE database

title

Configuration of K-FACE

Configuration_of_KFACE

Detection & Alignment on K-FACE

"""
    ###################################################################

    K-Face : Korean Facial Image AI Dataset
    url    : http://www.aihub.or.kr/aidata/73

    Directory structure : High-ID-Accessories-Lux-Emotion
    ID example          : '19062421' ... '19101513' len 400
    Accessories example : 'S001', 'S002' .. 'S006'  len 6
    Lux example         : 'L1', 'L2' .. 'L30'       len 30
    Emotion example     : 'E01', 'E02', 'E03'       len 3
    
    ###################################################################
"""

# example
cd detection

python align_kfaces.py --ori_data_path '/data/FACE/KFACE/High' --detected_data_path 'kface_retina_align_112x112'

Training and test datasets on K-FACE

Train ID Accessories Lux Expression Pose #Image Variance
T1 A1 1000 E1 C4-10 2,590 Very Low
T2 A1-2 400-1000 E1 C4-10 46,620 Low
T3 A1-A4 200-1000 E1-2 C4-13 654,160 Middle
T4 A1-A6 40-1000 E1-3 C1-20 3,862,800 High
Test ID Accessories Lux Expression Pose #Pairs Variance
Q1 A1 1000 E1 C4-10 1,000 Very Low
Q2 A1-2 400-1000 E1 C4-10 100,000 Low
Q3 A1-4 200-1000 E1-2 C4-13 100,000 Middle
Q4 A1-6 40-1000 E1-3 C1-20 100,000 High

MS1M-RetinaFace (MS1M-R)

MS1M-RetinaFace download link:

  1. The Lightweight Face Recognition Challenge & Workshop.

  2. https://github.com/deepinsight/insightface/wiki/Dataset-Zoo

#Preprocess 'train.rec' and 'train.idx' to 'jpg'

# example
cd detection

python rec2image.py --include '/data/FACE/ms1m-retinaface-t1/' --output 'MS1M-RetinaFace'

Inference

After downloading the pretrained model, run test.py.

Pretrained Model

For all experiments, ResNet-34 was chosen as the baseline backbone.

The model was trained on KFACE

Head&Loss Q1 Q2 Q3 Q4
ArcFace (s=16, m=0.25) 98.30 94.77 87.87 85.41
SN-pair (s=64) 99.20 95.01 91.84 89.74
MixFace (e=1e-22, m=0.25) 100 96.37 92.36 89.80

Note:

  • For ArcFace, We tested (s,m)={(16,0.5), (32,0.25), (64,0.25), (32,0.5), (64,0.5)}, but the model was not trained properly So, we apply (s,m)=(16,0.25).
cd recognition

# example
python test.py --weights 'kface.mixface.1e-22m0.25.best.pt' --dataset 'kface' --data_cfg 'data/KFACE/kface.T4.yaml'

The model was trained on MS1M-R

Head&Loss Q2 Q3 Q4 LFW CFP-FP AgeDB-30
ArcFace (s=64, m=0.5) 98.71 86.60 82.03 99.80 98.41 98.80
SN-pair (s=64) 92.85 76.36 70.08 99.55 96.20 95.46
MixFace (e=1e-22, m=0.5) 97.36 82.89 76.95 99.68 97.74 97.25
cd recognition

# example
python test.py --weights 'face.mixface.1e-22m0.5.best.pt' --dataset 'face' --data_cfg 'data/face.all.yaml'

The model was trained on MS1M-R+T4

Head&Loss Q2 Q3 Q4 LFW CFP-FP AgeDB-30
ArcFace (s=8, m=0.25) 76.58 73.13 71.38 99.46 96.75 93.83
SN-pair (s=64) 98.37 94.98 93.33 99.45 94.90 93.45
MixFace (e=1e-22, m=0.5) 99.27 96.85 94.79 99.53 96.32 95.56

Note:

  • For ArcFace, we tested (s,m)={(8, 0.5), (16, 0.25), (16,0.5), (32,0.25), (64,0.25), (32,0.5), (64,0.5)}, but the model was not trained properly So, we apply (s,m)=(8,0.25).
cd recognition

# example
python test.py --weights 'merge.mixface.1e-22m0.5.best.pt' --dataset 'merge' --data_cfg 'data/merge.yaml'

Training

Multi-GPU DataParallel Mode

Example script for training on KFACE

cd recognition

# example 
python train.py --dataset 'kface' --head 'mixface' --data_cfg 'data/KFACE/kface.T4.yaml' --hyp 'data/face.hyp.yaml' --head_cfg 'models/head.kface.cfg.yaml' --name 'example' --device 0,1

Multi-GPU DistributedDataParallel Mode

Example script for training on KFACE

cd recognition

# example
python -m torch.distributed.launch --nproc_per_node 2 train.py --dataset 'kface' --head 'mixface' --data_cfg 'data/KFACE/kface.T4.yaml' --hyp 'data/face.hyp.yaml' --head_cfg 'models/head.kface.cfg.yaml' --name 'example' --device 0,1

Note:

  • For MS1M-R, change args --dataset face, --data_cfg data/face.all.yaml, and --head_cfg model/head.face.cfg.yaml.
  • For MS1M-R+T4, change args --dataset merge, --data_cfg data/merge.yaml, and --head_cfg model/head.merge.cfg.yaml.
  • The args --nodrop should be used if you train with the metric loss(e.g., SN-pair, N-pair, etc.) on MS1M-R or MS1M-R+T4.
  • The args --double should be used if you train with the metric loss(e.g., SN-pair, N-pair, etc.) or MixFace on MS1M-R or MS1M-R+T4.
  • DistributedDataParallel is only available to classification loss(e.g., arcface, cosface, etc.)

Reference code

Thanks for these source codes porviding me with knowledges to complete this repository.

  1. https://github.com/biubug6/Pytorch_Retinaface.
  2. https://github.com/deepinsight/insightface.
  3. https://github.com/ultralytics/yolov5
You might also like...
Face-Recognition-Attendence-System - This face recognition Attendence system using Python

Face-Recognition-Attendence-System I have developed this face recognition Attend

AI Face Mesh: This is a simple face mesh detection program based on Artificial intelligence.

AI Face Mesh: This is a simple face mesh detection program based on Artificial Intelligence which made with Python. It's able to detect 468 different

Video-face-extractor - Video face extractor with Python

Python face extractor Setup Create the srcvideos and faces directories Put your

Face and Pose detector that emits MQTT events when a face or human body is detected and not detected.
Face and Pose detector that emits MQTT events when a face or human body is detected and not detected.

Face Detect MQTT Face or Pose detector that emits MQTT events when a face or human body is detected and not detected. I built this as an alternative t

Deepface is a lightweight face recognition and facial attribute analysis (age, gender, emotion and race) framework for python
Deepface is a lightweight face recognition and facial attribute analysis (age, gender, emotion and race) framework for python

deepface Deepface is a lightweight face recognition and facial attribute analysis (age, gender, emotion and race) framework for python. It is a hybrid

Face Mask Detection is a project to determine whether someone is wearing mask or not, using deep neural network.
Face Mask Detection is a project to determine whether someone is wearing mask or not, using deep neural network.

face-mask-detection Face Mask Detection is a project to determine whether someone is wearing mask or not, using deep neural network. It contains 3 scr

This project contains an implemented version of Face Detection using OpenCV and Mediapipe. This is a code snippet and can be used in projects.
This project contains an implemented version of Face Detection using OpenCV and Mediapipe. This is a code snippet and can be used in projects.

Live-Face-Detection Project Description: In this project, we will be using the live video feed from the camera to detect Faces. It will also detect so

my graduation project is about live human face augmentation by projection mapping by using CNN
my graduation project is about live human face augmentation by projection mapping by using CNN

Live-human-face-expression-augmentation-by-projection my graduation project is about live human face augmentation by projection mapping by using CNN o

Face Recognition Attendance Project
Face Recognition Attendance Project

Face-Recognition-Attendance-Project In This Project You will learn how to mark attendance using face recognition, Hello Guys This is Gautam Kumar, Thi

Owner
Jung Jun Uk
Jung Jun Uk
Code for HLA-Face: Joint High-Low Adaptation for Low Light Face Detection (CVPR21)

HLA-Face: Joint High-Low Adaptation for Low Light Face Detection The official PyTorch implementation for HLA-Face: Joint High-Low Adaptation for Low L

Wenjing Wang 77 Dec 8, 2022
DVG-Face: Dual Variational Generation for Heterogeneous Face Recognition, TPAMI 2021

DVG-Face: Dual Variational Generation for HFR This repo is a PyTorch implementation of DVG-Face: Dual Variational Generation for Heterogeneous Face Re

null 52 Dec 30, 2022
[TIP 2021] SADRNet: Self-Aligned Dual Face Regression Networks for Robust 3D Dense Face Alignment and Reconstruction

SADRNet Paper link: SADRNet: Self-Aligned Dual Face Regression Networks for Robust 3D Dense Face Alignment and Reconstruction Requirements python

Multimedia Computing Group, Nanjing University 99 Dec 30, 2022
Realtime Face Anti Spoofing with Face Detector based on Deep Learning using Tensorflow/Keras and OpenCV

Realtime Face Anti-Spoofing Detection ?? Realtime Face Anti Spoofing Detection with Face Detector to detect real and fake faces Please star this repo

Prem Kumar 86 Aug 3, 2022
Swapping face using Face Mesh with TensorFlow Lite

Swapping face using Face Mesh with TensorFlow Lite

iwatake 17 Apr 26, 2022
Face Synthetics dataset is a collection of diverse synthetic face images with ground truth labels.

The Face Synthetics dataset Face Synthetics dataset is a collection of diverse synthetic face images with ground truth labels. It was introduced in ou

Microsoft 608 Jan 2, 2023
Face Library is an open source package for accurate and real-time face detection and recognition

Face Library Face Library is an open source package for accurate and real-time face detection and recognition. The package is built over OpenCV and us

null 52 Nov 9, 2022
VGGFace2-HQ - A high resolution face dataset for face editing purpose

The first open source high resolution dataset for face swapping!!! A high resolution version of VGGFace2 for academic face editing purpose

Naiyuan Liu 232 Dec 29, 2022
A large-scale face dataset for face parsing, recognition, generation and editing.

CelebAMask-HQ [Paper] [Demo] CelebAMask-HQ is a large-scale face image dataset that has 30,000 high-resolution face images selected from the CelebA da

switchnorm 1.7k Dec 26, 2022
Python tools for 3D face: 3DMM, Mesh processing(transform, camera, light, render), 3D face representations.

face3d: Python tools for processing 3D face Introduction This project implements some basic functions related to 3D faces. You can use this to process

Yao Feng 2.3k Dec 30, 2022