Skip to content

Latest commit

 

History

History
 
 

face

Face Recognition

The face recognition task is a case of achieving large-scale classification on PLSC, and the goal is to implement and reproduce the SOTA algorithm. It has the ability to train tens of millions of identities with high throughput in a single server.

Function has supported:

  • ArcFace
  • CosFace
  • PartialFC
  • SparseMomentum
  • FP16 training
  • DataParallel(backbone layer) + ModelParallel(FC layer) distributed training

Backbone includes:

  • IResNet
  • FaceViT
  • MobileFaceNet

Requirements

To enjoy some new features, PaddlePaddle 2.4 is required. For more installation tutorials refer to installation.md

Data Preparation

Download Dataset

Download the dataset from insightface datasets.

Note:

  • MS1MV2: MS1M-ArcFace
  • MS1MV3: MS1M-RetinaFace
  • WebFace42M: cleared WebFace260M

[Optional] Extract MXNet Dataset to Images

# for example, here extract MS1MV3 dataset
python -m plsc.data.dataset.tools.mx_recordio_2_images --root_dir /path/to/ms1m-retinaface-t1/ --output_dir ./dataset/MS1M_v3/

Extract LFW Style bin Dataset to Images

# for example, here extract agedb_30 bin to images
python -m plsc.data.dataset.tools.lfw_style_bin_dataset_converter --bin_path ./dataset/MS1M_v3/agedb_30.bin --out_dir ./dataset/MS1M_v3/agedb_30 --flip_test

Dataset Directory

We put all the data in the ./dataset/ directory, and we also recommend using soft links, for example:

mkdir -p ./dataset/
ln -s /path/to/MS1M_v3 ./dataset/MS1M_v3

How to Train

# Note: If running on multiple nodes, 
# set the following environment variables 
# and then need to run the script on each node.
export PADDLE_NNODES=1
export PADDLE_MASTER="127.0.0.1:12538"
export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7

python -m paddle.distributed.launch \
    --nnodes=$PADDLE_NNODES \
    --master=$PADDLE_MASTER \
    --devices=$CUDA_VISIBLE_DEVICES \
    plsc-train \
    -c ./configs/IResNet50_MS1MV3_ArcFace_pfc10_1n8c_dp_mp_fp16o1.yaml

How to Export

# In general, we only need to export the 
# backbone, so we only need to run the 
# export command on a single device.
export PADDLE_NNODES=1
export PADDLE_MASTER="127.0.0.1:12538"
export CUDA_VISIBLE_DEVICES=0
python -m paddle.distributed.launch \
    --nnodes=$PADDLE_NNODES \
    --master=$PADDLE_MASTER \
    --devices=$CUDA_VISIBLE_DEVICES \
    plsc-export \
    -c ./configs/IResNet50_MS1MV3_ArcFace_pfc10_1n8c_dp_mp_fp16o1.yaml \
    -o Global.pretrained_model=./output/IResNet50/latest \
    -o FP16.level=O0 \ # export FP32 model when training with FP16
    -o Model.data_format=NCHW # IResNet required if training with NHWC 

Evaluation IJB-C

python onnx_ijbc.py \
  --model-root ./output/IResNet50.onnx \
  --image-path ./ijb/IJBC/ \
  --target IJBC

Model Zoo

Datasets Backbone Config Devices PFC IJB-C(1E-4) IJB-C(1E-5) checkpoint log
MS1MV3 IRes50 config N1C8*A100 1.0 96.43 94.43 download download
WebFace42M MobileFaceNet_base config N1C8*A100 0.2 95.22 92.48 download download
WebFace42M IRes100 config N1C8*A100 0.2 97.78 96.46 download download
WebFace42M FaceViT_tiny_patch9_112 config N1C8*A100 1.0 97.24 95.79 download download
WebFace42M FaceViT_tiny_patch9_112 config N1C8*A100 0.2 97.28 95.79 download download
WebFace42M FaceViT_base_patch9_112 config N1C8*A100 0.3 97.97 97.04 download download

Citations

@misc{plsc,
    title={PLSC: An Easy-to-use and High-Performance Large Scale Classification Tool},
    author={PLSC Contributors},
    howpublished = {\url{https://github.com/PaddlePaddle/PLSC}},
    year={2022}
}
@inproceedings{deng2019arcface,
  title={Arcface: Additive angular margin loss for deep face recognition},
  author={Deng, Jiankang and Guo, Jia and Xue, Niannan and Zafeiriou, Stefanos},
  booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},
  pages={4690--4699},
  year={2019}
}
@inproceedings{An_2022_CVPR,
    author={An, Xiang and Deng, Jiankang and Guo, Jia and Feng, Ziyong and Zhu, XuHan and Yang, Jing and Liu, Tongliang},
    title={Killing Two Birds With One Stone: Efficient and Robust Training of Face Recognition CNNs by Partial FC},
    booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
    month={June},
    year={2022},
    pages={4042-4051}
}