Files
insightface/README.md

246 lines
9.4 KiB
Markdown
Raw Normal View History

2017-11-29 16:39:30 +08:00
2018-03-22 16:12:52 +00:00
# InsightFace: 2D and 3D Face Analysis Project
2017-12-07 09:45:20 +08:00
2018-03-22 16:38:34 +00:00
By Jia Guo and [Jiankang Deng](https://jiankangdeng.github.io/)
2018-01-26 13:25:56 +08:00
2018-03-22 16:12:52 +00:00
## License
2018-03-14 11:48:37 +08:00
2018-03-22 16:12:52 +00:00
The code of InsightFace is released under the MIT License.
2018-02-16 18:52:51 +08:00
2019-01-02 14:27:18 +00:00
## ArcFace Video Demo
2019-02-09 13:35:01 +00:00
2019-01-02 14:29:14 +00:00
[![ArcFace Demo](https://github.com/deepinsight/insightface/blob/master/resources/facerecognitionfromvideo.PNG)](https://www.youtube.com/watch?v=y-D1tReryGA&t=81s)
2019-01-02 14:27:18 +00:00
Please click the image to watch the Youtube video. For Bilibili users, click [here](https://www.bilibili.com/video/av38041494?from=search&seid=11501833604850032313).
2018-03-22 16:12:52 +00:00
## Recent Update
2018-02-13 13:34:27 +08:00
2019-04-14 13:41:49 +01:00
**`2019.04.14`**: We will launch a Light-weight Face Recognition challenge/workshop on ICCV 2019.
2019-01-17 20:21:11 +08:00
2019-04-14 13:41:49 +01:00
**`2019.04.04`**: Arcface achieved state-of-the-art performance (5/109) on the NIST Face Recognition Vendor Test (FRVT) (1:1 verification)
[report](https://www.nist.gov/sites/default/files/documents/2019/04/04/frvt_report_2019_04_04.pdf) (name: Imperial-000). Our solution is based on [MS1MV2+DeepGlintAsian, ResNet100, ArcFace loss].
2018-12-13 18:59:01 +08:00
2019-04-14 13:41:49 +01:00
**`2019.02.08`**: Please check [https://github.com/deepinsight/insightface/tree/master/recognition](https://github.com/deepinsight/insightface/tree/master/recognition) for our parallel training code which can easily and efficiently support one million identities on a single machine (8* 1080ti).
2018-10-28 11:37:49 +08:00
2019-04-14 13:41:49 +01:00
**`2018.12.13`**: Inference acceleration [TVM-Benchmark](https://github.com/deepinsight/insightface/wiki/TVM-Benchmark).
2018-10-16 11:22:01 +08:00
2019-04-14 13:41:49 +01:00
**`2018.10.28`**: Light-weight attribute model [Gender-Age](https://github.com/deepinsight/insightface/tree/master/gender-age). About 1MB, 10ms on single CPU core. Gender accuracy 96% on validation set and 4.1 age MAE.
2018-06-15 00:08:28 +08:00
2019-04-14 13:41:49 +01:00
**`2018.10.16`**: We achieved state-of-the-art performance on [Trillionpairs](http://trillionpairs.deepglint.com/results) (name: nttstar) and [IQIYI_VID](http://challenge.ai.iqiyi.com/detail?raceId=5afc36639689443e8f815f9e) (name: WitcheR).
2018-02-08 14:01:16 +08:00
2018-03-22 16:12:52 +00:00
## Contents
2018-03-22 16:58:47 +00:00
[Deep Face Recognition](#deep-face-recognition)
- [Introduction](#introduction)
2018-10-23 12:51:51 +08:00
- [Training Data](#training-data)
2018-03-22 16:58:47 +00:00
- [Train](#train)
- [Pretrained Models](#pretrained-models)
2018-03-26 17:15:54 +08:00
- [Verification Results On Combined Margin](#verification-results-on-combined-margin)
2018-03-22 16:58:47 +00:00
- [Test on MegaFace](#test-on-megaface)
2018-03-22 17:24:26 +00:00
- [512-D Feature Embedding](#512-d-feature-embedding)
2018-03-22 16:58:47 +00:00
- [Third-party Re-implementation](#third-party-re-implementation)
2018-03-22 17:07:13 +00:00
2018-03-22 16:58:47 +00:00
[Face Alignment](#face-alignment)
2018-03-22 17:07:13 +00:00
2018-03-22 16:58:47 +00:00
[Face Detection](#face-detection)
2018-03-22 17:07:13 +00:00
2018-03-22 16:58:47 +00:00
[Citation](#citation)
2018-03-22 17:07:13 +00:00
2018-03-22 16:58:47 +00:00
[Contact](#contact)
2017-11-29 16:39:30 +08:00
2018-03-22 16:38:34 +00:00
## Deep Face Recognition
2017-11-29 16:39:30 +08:00
2018-01-24 09:35:09 +08:00
### Introduction
2017-11-30 19:15:34 +08:00
2018-03-22 16:58:47 +00:00
In this repository, we provide training data, network settings and loss designs for deep face recognition.
2019-01-15 14:45:10 +08:00
The training data includes the normalised MS1M, VGG2 and CASIA-Webface datasets, which were already packed in MXNet binary format.
The network backbones include ResNet, MobilefaceNet, MobileNet, InceptionResNet_v2, DenseNet, DPN.
2018-03-22 16:58:47 +00:00
The loss functions include Softmax, SphereFace, CosineFace, ArcFace and Triplet (Euclidean/Angular) Loss.
2019-01-15 14:45:10 +08:00
2017-12-07 09:45:20 +08:00
2018-03-23 10:57:39 +00:00
![margin penalty for target logit](https://github.com/deepinsight/insightface/raw/master/resources/arcface.png)
2017-12-07 09:45:20 +08:00
2018-03-22 16:58:47 +00:00
Our method, ArcFace, was initially described in an [arXiv technical report](https://arxiv.org/abs/1801.07698). By using this repository, you can simply achieve LFW 99.80%+ and Megaface 98%+ by a single model. This repository can help researcher/engineer to develop deep face recognition algorithms quickly by only two steps: download the binary dataset and run the training script.
2017-12-07 09:45:20 +08:00
2018-03-22 16:38:34 +00:00
### Training Data
2017-12-21 15:41:54 +08:00
2018-03-22 17:24:26 +00:00
All face images are aligned by [MTCNN](https://kpzhang93.github.io/MTCNN_face_detection_alignment/index.html) and cropped to 112x112:
2017-12-21 15:41:54 +08:00
2019-01-15 14:45:10 +08:00
Please check [Dataset-Zoo](https://github.com/deepinsight/insightface/wiki/Dataset-Zoo) for detail information and dataset downloading.
2017-12-21 15:41:54 +08:00
2018-10-23 12:51:51 +08:00
* Please check *src/data/face2rec2.py* on how to build a binary face dataset. Any public available *MTCNN* can be used to align the faces, and the performance should not change. We will improve the face normalisation step by full pose alignment methods recently.
2018-01-24 21:00:22 +08:00
2018-03-22 16:12:52 +00:00
### Train
2018-01-24 09:33:34 +08:00
2018-03-22 16:12:52 +00:00
1. Install `MXNet` with GPU support (Python 2.7).
2018-01-24 09:33:34 +08:00
2018-03-22 16:58:47 +00:00
```
2019-01-15 14:45:10 +08:00
pip install mxnet-cu90
2018-03-22 16:58:47 +00:00
```
2018-01-24 09:33:34 +08:00
2018-03-22 17:07:13 +00:00
2. Clone the InsightFace repository. We call the directory insightface as *`INSIGHTFACE_ROOT`*.
2018-01-24 09:33:34 +08:00
2018-03-22 16:58:47 +00:00
```
git clone --recursive https://github.com/deepinsight/insightface.git
```
2018-01-24 09:33:34 +08:00
2019-01-15 14:45:10 +08:00
3. Download the training set (`MS1M-Arcface`) and place it in *`$INSIGHTFACE_ROOT/datasets/`*. Each training dataset includes at least following 6 files:
2018-01-24 09:33:34 +08:00
2018-03-22 16:58:47 +00:00
```Shell
2019-01-15 14:45:10 +08:00
faces_emore/
2018-03-22 16:58:47 +00:00
train.idx
train.rec
property
lfw.bin
cfp_fp.bin
agedb_30.bin
```
2018-01-24 09:33:34 +08:00
2019-01-16 10:52:33 +08:00
The first three files are the training dataset while the last three files are verification sets.
2018-01-24 09:33:34 +08:00
2018-03-22 16:12:52 +00:00
4. Train deep face recognition models.
2019-01-15 14:45:10 +08:00
In this part, we assume you are in the directory *`$INSIGHTFACE_ROOT/recognition/`*.
```Shell
2018-03-22 16:58:47 +00:00
export MXNET_CPU_WORKER_NTHREADS=24
export MXNET_ENGINE_TYPE=ThreadedEnginePerDevice
```
2019-01-15 14:45:10 +08:00
Place and edit config file:
```Shell
cp sample_config.py config.py
vim config.py # edit dataset path etc..
```
2018-03-22 16:58:47 +00:00
We give some examples below. Our experiments were conducted on the Tesla P40 GPU.
2018-01-25 19:34:25 +08:00
2018-03-22 16:12:52 +00:00
(1). Train ArcFace with LResNet100E-IR.
2018-01-24 09:33:34 +08:00
2018-03-22 16:58:47 +00:00
```Shell
2019-01-15 22:17:21 +08:00
CUDA_VISIBLE_DEVICES='0,1,2,3' python -u train.py --network r100 --loss arcface --dataset emore
2018-03-22 16:58:47 +00:00
```
2019-01-16 10:52:33 +08:00
It will output verification results of *LFW*, *CFP-FP* and *AgeDB-30* every 2000 batches. You can check all options in *config.py*.
2019-01-15 14:45:10 +08:00
This model can achieve *LFW 99.80+* and *MegaFace 98.3%+*.
2018-01-24 09:33:34 +08:00
2018-03-22 16:12:52 +00:00
(2). Train CosineFace with LResNet50E-IR.
2018-01-24 09:33:34 +08:00
2018-03-22 16:58:47 +00:00
```Shell
2019-01-15 22:17:21 +08:00
CUDA_VISIBLE_DEVICES='0,1,2,3' python -u train.py --network r50 --loss cosface --dataset emore
2018-03-22 16:58:47 +00:00
```
2018-01-24 09:33:34 +08:00
2019-01-15 14:45:10 +08:00
(3). Train Softmax with LMobileNet-GAP.
2018-01-24 09:33:34 +08:00
2018-03-22 16:58:47 +00:00
```Shell
2019-01-15 22:17:21 +08:00
CUDA_VISIBLE_DEVICES='0,1,2,3' python -u train.py --network m1 --loss softmax --dataset emore
2018-03-22 16:58:47 +00:00
```
2018-01-24 09:33:34 +08:00
2018-03-22 16:12:52 +00:00
(4). Fine-turn the above Softmax model with Triplet loss.
2018-01-24 09:33:34 +08:00
2018-03-22 16:58:47 +00:00
```Shell
2019-01-15 22:17:21 +08:00
CUDA_VISIBLE_DEVICES='0,1,2,3' python -u train.py --network m1 --loss triplet --lr 0.005 --pretrained ./models/m1-softmax-emore,1
2018-03-22 16:58:47 +00:00
```
2018-01-24 09:33:34 +08:00
2018-04-23 12:12:09 +08:00
2018-03-22 16:12:52 +00:00
5. Verification results.
2018-01-24 09:33:34 +08:00
2019-01-16 10:52:33 +08:00
*LResNet100E-IR* network trained on *MS1M-Arcface* dataset with ArcFace loss:
2018-01-24 09:33:34 +08:00
2019-01-15 14:45:10 +08:00
| Method | LFW(%) | CFP-FP(%) | AgeDB-30(%) |
| ------- | ------ | --------- | ----------- |
| Ours | 99.80+ | 98.0+ | 98.20+ |
2018-01-24 09:33:34 +08:00
2018-03-22 16:38:34 +00:00
### Pretrained Models
2018-01-30 13:39:34 +08:00
2018-03-22 16:58:47 +00:00
You can use `$INSIGHTFACE/src/eval/verification.py` to test all the pre-trained models.
2018-03-22 16:12:52 +00:00
2018-10-23 12:51:51 +08:00
**Please check [Model-Zoo](https://github.com/deepinsight/insightface/wiki/Model-Zoo) for more pretrained models.**
2018-04-04 16:13:03 +08:00
2018-03-22 16:12:52 +00:00
2018-03-26 17:15:54 +08:00
### Verification Results on Combined Margin
2018-03-26 17:28:18 +08:00
A combined margin method was proposed as a function of target logits value and original `θ`:
2018-03-26 17:15:54 +08:00
```
COM(θ) = cos(m_1*θ+m_2) - m_3
```
2019-01-15 14:45:10 +08:00
For training with `m1=1.0, m2=0.3, m3=0.2`, run following command:
2018-03-26 17:15:54 +08:00
```
2019-01-15 14:45:10 +08:00
CUDA_VISIBLE_DEVICES='0,1,2,3' python -u train_softmax.py --network r100 --loss combined --dataset emore
2018-03-26 17:15:54 +08:00
```
2019-01-15 14:45:10 +08:00
Results by using ``MS1M-IBUG(MS1M-V1)``
2018-03-26 17:15:54 +08:00
| Method | m1 | m2 | m3 | LFW | CFP-FP | AgeDB-30 |
| ---------------- | ---- | ---- | ---- | ----- | ------ | -------- |
| W&F Norm Softmax | 1 | 0 | 0 | 99.28 | 88.50 | 95.13 |
| SphereFace | 1.5 | 0 | 0 | 99.76 | 94.17 | 97.30 |
| CosineFace | 1 | 0 | 0.35 | 99.80 | 94.4 | 97.91 |
| ArcFace | 1 | 0.5 | 0 | 99.83 | 94.04 | 98.08 |
| Combined Margin | 1.2 | 0.4 | 0 | 99.80 | 94.08 | 98.05 |
| Combined Margin | 1.1 | 0 | 0.35 | 99.81 | 94.50 | 98.08 |
| Combined Margin | 1 | 0.3 | 0.2 | 99.83 | 94.51 | 98.13 |
| Combined Margin | 0.9 | 0.4 | 0.15 | 99.83 | 94.20 | 98.16 |
2018-03-22 16:38:34 +00:00
### Test on MegaFace
2018-03-22 16:12:52 +00:00
2019-01-15 14:45:10 +08:00
Please check *`$INSIGHTFACE_ROOT/Evaluation/megaface/`* to evaluate the model accuracy on Megaface. All aligned images were already provided.
2018-03-22 16:12:52 +00:00
2018-03-22 17:24:26 +00:00
### 512-D Feature Embedding
2018-03-22 16:12:52 +00:00
2018-03-22 17:07:13 +00:00
In this part, we assume you are in the directory *`$INSIGHTFACE_ROOT/deploy/`*. The input face image should be generally centre cropped. We use *RNet+ONet* of *MTCNN* to further align the image before sending it to the feature embedding network.
2018-03-22 16:12:52 +00:00
2018-03-22 16:58:47 +00:00
1. Prepare a pre-trained model.
2019-01-15 14:45:10 +08:00
2. Put the model under *`$INSIGHTFACE_ROOT/models/`*. For example, *`$INSIGHTFACE_ROOT/models/model-r100-ii`*.
2018-03-22 17:07:13 +00:00
3. Run the test script *`$INSIGHTFACE_ROOT/deploy/test.py`*.
2018-03-22 16:12:52 +00:00
2018-03-22 16:58:47 +00:00
For single cropped face image(112x112), total inference time is only 17ms on our testing server(Intel E5-2660 @ 2.00GHz, Tesla M40, *LResNet34E-IR*).
2018-01-24 09:33:34 +08:00
2018-03-22 16:38:34 +00:00
### Third-party Re-implementation
2018-01-24 09:33:34 +08:00
2018-03-22 16:38:34 +00:00
- TensorFlow: [InsightFace_TF](https://github.com/auroua/InsightFace_TF)
2018-10-11 17:45:46 +08:00
- TensorFlow: [tf-insightface](https://github.com/AIInAi/tf-insightface)
- PyTorch: [InsightFace_Pytorch](https://github.com/TreB1eN/InsightFace_Pytorch)
- PyTorch: [arcface-pytorch](https://github.com/ronghuaiyang/arcface-pytorch)
- Caffe: [arcface-caffe](https://github.com/xialuxi/arcface-caffe)
2019-02-02 11:10:37 +08:00
- Caffe: [CombinedMargin-caffe](https://github.com/gehaocool/CombinedMargin-caffe)
- Tensorflow: [InsightFace-tensorflow](https://github.com/luckycallor/InsightFace-tensorflow)
2018-10-11 17:45:46 +08:00
2018-01-24 09:33:34 +08:00
2018-03-22 16:38:34 +00:00
## Face Alignment
2018-01-25 21:47:22 +08:00
2018-03-22 16:12:52 +00:00
Todo
2018-01-25 21:47:22 +08:00
2018-03-22 16:38:34 +00:00
## Face Detection
2018-01-24 09:33:34 +08:00
2018-03-22 16:12:52 +00:00
Todo
2018-01-24 09:33:34 +08:00
2018-03-22 16:12:52 +00:00
## Citation
2018-01-24 09:33:34 +08:00
2018-03-22 17:07:13 +00:00
If you find *InsightFace* useful in your research, please consider to cite the following related papers:
2018-01-24 09:33:34 +08:00
2018-01-24 11:55:27 +08:00
```
2019-04-14 13:41:49 +01:00
@inproceedings{guo2018stacked,
title={Stacked Dense U-Nets with Dual Transformers for Robust Face Alignment},
author={Guo, Jia and Deng, Jiankang and Xue, Niannan and Zafeiriou, Stefanos},
booktitle={BMVC},
year={2018}
}
2019-02-26 11:49:09 +00:00
@inproceedings{deng2018arcface,
2018-03-22 16:58:47 +00:00
title={ArcFace: Additive Angular Margin Loss for Deep Face Recognition},
2019-01-02 14:29:14 +00:00
author={Deng, Jiankang and Guo, Jia and Niannan, Xue and Zafeiriou, Stefanos},
2019-02-26 11:49:09 +00:00
booktitle={CVPR},
2019-02-26 11:33:45 +00:00
year={2019}
2018-03-22 16:12:52 +00:00
}
```
## Contact
2018-01-24 09:33:34 +08:00
2018-01-24 11:55:27 +08:00
```
2018-03-22 16:38:34 +00:00
[Jia Guo](guojia[at]gmail.com)
[Jiankang Deng](jiankangdeng[at]gmail.com)
2018-03-22 16:12:52 +00:00
```