All Projects → peteryuX → Arcface Tf2

peteryuX / Arcface Tf2

Licence: mit
ArcFace unofficial Implemented in Tensorflow 2.0+ (ResNet50, MobileNetV2). "ArcFace: Additive Angular Margin Loss for Deep Face Recognition" Published in CVPR 2019. With Colab.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Arcface Tf2

Combinedmargin Caffe
caffe implementation of insightface's combined margin method
Stars: ✭ 87 (-29.84%)
Mutual labels:  face-recognition
Face2data
Face2Data: Extract meaningful information from a person face in less than a second. Powered by Keras and Flask.
Stars: ✭ 107 (-13.71%)
Mutual labels:  face-recognition
Maad Face
A face database with a large number of high-quality attribute annotations
Stars: ✭ 112 (-9.68%)
Mutual labels:  face-recognition
Pyseeta
python api for SeetaFaceEngine(https://github.com/seetaface/SeetaFaceEngine.git)
Stars: ✭ 93 (-25%)
Mutual labels:  face-recognition
Face Classification
Face model to classify gender and race. Trained on LFWA+ Dataset.
Stars: ✭ 104 (-16.13%)
Mutual labels:  face-recognition
Face recognition
The world's simplest facial recognition api for Python and the command line
Stars: ✭ 42,549 (+34213.71%)
Mutual labels:  face-recognition
Insightface
State-of-the-art 2D and 3D Face Analysis Project
Stars: ✭ 10,886 (+8679.03%)
Mutual labels:  face-recognition
Deepstack
The World's Leading Cross Platform AI Engine for Edge Devices
Stars: ✭ 120 (-3.23%)
Mutual labels:  face-recognition
Awesome Face Detection
Compare with various detectors - s3fd, dlib, ocv, ocv-dnn, mtcnn-pytorch, face_recognition
Stars: ✭ 106 (-14.52%)
Mutual labels:  face-recognition
Deepface
Face analysis mainly based on Caffe. At this time, face analysis tasks like detection, alignment and recognition have been done.
Stars: ✭ 1,465 (+1081.45%)
Mutual labels:  face-recognition
Face recognition crop
Multi-view face recognition, face cropping and saving the cropped faces as new images on videos to create a multi-view face recognition database.
Stars: ✭ 98 (-20.97%)
Mutual labels:  face-recognition
Repo 2016
R, Python and Mathematica Codes in Machine Learning, Deep Learning, Artificial Intelligence, NLP and Geolocation
Stars: ✭ 103 (-16.94%)
Mutual labels:  face-recognition
Sphereface
Implementation for <SphereFace: Deep Hypersphere Embedding for Face Recognition> in CVPR'17.
Stars: ✭ 1,483 (+1095.97%)
Mutual labels:  face-recognition
Hellovision
Vision framework example for my article. https://medium.com/compileswift/swift-world-whats-new-in-ios-11-vision-456ba4156bad
Stars: ✭ 93 (-25%)
Mutual labels:  face-recognition
Deepface
Keras implementation of the renowned publication "DeepFace: Closing the Gap to Human-Level Performance in Face Verification" by Taigman et al. Pre-trained weights on VGGFace2 dataset.
Stars: ✭ 113 (-8.87%)
Mutual labels:  face-recognition
Python Tensorflow Face V2.0
基于tensorflow的人脸识别
Stars: ✭ 84 (-32.26%)
Mutual labels:  face-recognition
Resnet Face Pytorch
Training a ResNet on UMDFaces for face recognition
Stars: ✭ 107 (-13.71%)
Mutual labels:  face-recognition
Seqface
SeqFace : Making full use of sequence information for face recognition
Stars: ✭ 125 (+0.81%)
Mutual labels:  face-recognition
Dlib Face Recognition Android
Android app to demo dlib face recognition
Stars: ✭ 115 (-7.26%)
Mutual labels:  face-recognition
Whoiscomingto.party
Simple Face Recognition Attendance System
Stars: ✭ 111 (-10.48%)
Mutual labels:  face-recognition

arcface-tf2

Language grade: Python Star Fork License

Open In Colab

🔥 ArcFace (Additive Angular Margin Loss for Deep Face Recognition, published in CVPR 2019) implemented in Tensorflow 2.0+. This is an unofficial implementation. 🔥

Additive Angular Margin Loss(ArcFace) has a clear geometric interpretation due to the exact correspondence to the geodesic distance on the hypersphere, and consistently outperforms the state-of-the-art and can be easily implemented with negligible computational overhead.

Original Paper:   Arxiv   CVPR2019

Offical Implementation:   MXNet


Contents

📑

Installation

🍕

Create a new python virtual environment by Anaconda or just use pip in your python environment and then clone this repository as following.

Clone this repo

git clone https://github.com/peteryuX/arcface-tf2.git
cd arcface-tf2

Conda

conda env create -f environment.yml
conda activate arcface-tf2

Pip

pip install -r requirements.txt

Data Preparing

🍺

All datasets used in this repository can be found from face.evoLVe.PyTorch's Data-Zoo.

Note:

  • Both training and testing dataset are "Align_112x112" version.

Training Dataset

Download MS-Celeb-1M datasets, then extract and convert them to tfrecord as traning data as following.

# Binary Image: convert really slow, but loading faster when traning.
python data/convert_train_binary_tfrecord.py --dataset_path="/path/to/ms1m_align_112/imgs" --output_path="./data/ms1m_bin.tfrecord"

# Online Image Loading: convert really fast, but loading slower when training.
python data/convert_train_tfrecord.py --dataset_path="/path/to/ms1m_align_112/imgs" --output_path="./data/ms1m.tfrecord"

Note:

  • You can run python ./dataset_checker.py to check if the dataloader work.

Testing Dataset

Download LFW, Aged30 and CFP-FP datasets, then extract them to /your/path/to/test_dataset. These testing data are already binary files, so it's not necessary to do any preprocessing. The directory structure should be like bellow.

/your/path/to/test_dataset/
    -> lfw_align_112/lfw
        -> data/
        -> meta/
        -> ...
    -> agedb_align_112/agedb_30
        -> ...
    -> cfp_align_112/cfp_fp
        -> ...

Training and Testing

🍭

You can modify your own dataset path or other settings of model in ./configs/*.yaml for training and testing, which like below.

# general (shared both in training and testing)
batch_size: 128
input_size: 112
embd_shape: 512
sub_name: 'arc_res50'
backbone_type: 'ResNet50' # or 'MobileNetV2'
head_type: ArcHead # or 'NormHead': FC to targets.
is_ccrop: False # central-cropping or not

# train
train_dataset: './data/ms1m_bin.tfrecord' # or './data/ms1m.tfrecord'
binary_img: True # False if dataset is online decoding
num_classes: 85742
num_samples: 5822653
epochs: 5
base_lr: 0.01
w_decay: !!float 5e-4
save_steps: 1000

# test
test_dataset: '/your/path/to/test_dataset'

Note:

  • The sub_name is the name of outputs directory used in checkpoints and logs folder. (make sure of setting it unique to other models)
  • The head_type is used to choose ArcFace head or normal fully connected layer head for classification in training. (see more detail in ./modules/models.py)
  • The is_ccrop means doing central-cropping on both trainging and testing data or not.
  • The binary_img is used to choose the type of training data, which should be according to the data type you created in the Data-Preparing.

Training

Here have two modes for training your model, which should be perform the same results at the end.

# traning with tf.GradientTape(), great for debugging.
python train.py --mode="eager_tf" --cfg_path="./configs/arc_res50.yaml"

# training with model.fit().
python train.py --mode="fit" --cfg_path="./configs/arc_res50.yaml"

Testing

You can download my trained models for testing from Benchmark and Models without training it yourself. And, evaluate the models you got with the corresponding cfg file on the testing dataset. The testing code in ./modules/evaluations.py were modified from face.evoLVe.

python test.py --cfg_path="./configs/arc_res50.yaml"

Encode Input Image

You can also encode image into latent vector by model. For example, encode the image from ./data/BruceLee.jpg and save to ./output_embeds.npy as following.

python test.py --cfg_path="./configs/arc_res50.yaml" --img_path="./data/BruceLee.jpg"

Benchmark and Models

☕️

Verification results (%) of different backbone, head tpye, data augmentation and loss function.

Backbone Head Loss CCrop LFW AgeDB-30 CFP-FP Download Link
ResNet50 ArcFace Softmax False 99.35 95.03 90.36 GoogleDrive
MobileNetV2 ArcFace Softmax False 98.67 90.87 88.51 GoogleDrive
ResNet50 ArcFace Softmax True 99.28 94.82 93.14 GoogleDrive
MobileNetV2 ArcFace Softmax True 98.50 91.43 89.44 GoogleDrive

Note:

  • The 'CCrop' tag above means doing central-cropping on both trainging and testing data, which could eliminate the redundant boundary of intput face data (especially for AgeDB-30).
  • All training settings of the models can be found in the corresponding ./configs/*.yaml files.
  • Based on the property of the training dataset, all the pre-trained models can only be used for non-commercial applications.

References

🍔

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].