The insightface face recognition algorithm is awesome, though there is no details about neither how to perform the evaluation on the algorithm nor how to prepare data for evaluation/training. Of course, one can find some details from issues, but it will take a lot of time to do that. Here, all the related details are collected for the sake of saving your time.
File you need for evaluation:
- your_dataset.bin
NOTE: If you just want to perform the evaluation with the LFW dataset, just head to the Dataset-zoo from insightface to download on of the provided dataset, which contains lfw.bin
for evaluation.
In case you want to create your own .bin
file from your own dataset, following section is an example creating lfw.bin
from LFW.
- Download the LFW dataset and extract it. All the images in LFW dataset are well organized as one folder for one identity, so you have to do so for your own dataset. It is also recommanded to place the root folder of LFW datset under
$insightface/datasets
, you should have the following structure:
$ tree -d -L 1 datasets/lfw
datasets/lfw/
├── Aaron_Eckhart
├── Aaron_Guiel
├── Aaron_Patterson
├── Aaron_Peirsol
├── Aaron_Pena
├── ....
├── Zulfiqar_Ahmed
├── Zumrati_Juma
├── Zurab_Tsereteli
└── Zydrunas_Ilgauskas
5749 directories
- Create aligned face images. Run
$insightface/src/align/align_lfw.py
, which detects, aligns and crops face images into 112x112. For your own dataset, runalign_dataset_mtcnn.py
instead.
# NOTE: you will need tensorflow r1 to run the script, or you can try migrate the code to tensorflow 2 following this guide https://www.tensorflow.org/guide/migrate. In order to have similar performace, I choose tensorflow 1.5 as its release date is close to the last commit time of `align_lfw.py`. Also note that to install older tensorflow, you need older version of python, as newer tensorflow does not officially release on older python.
# NOTE 2: `scipy.misc` has deprecated `imread`, use `imread` from `imageio` instead.
python align_lfw.py --input-dir ../../datasets/lfw/ --output-dir ../../datasets/lfw-aligned/
- (For creating your own dataset) Define ratios for subsets: train set - 80%, validation set - 10%, test set - 10% for example.
- Create
.lst
file. Run$insightface/src/data/dir2lst.py
:
# NOTE: `dir2lst.py` creates `1 path/to/lfw/person_name/image_filename 0` for each image. `1` for aligned, `0` for identity label. It use \t instead of space to separate 3 columns.
python dir2lst.py ../../datasets/lfw-aligned > ../../datasets/lfw-aligned/lfw.lst
- Create
property
file under$insightface/src/data/lfw-aligned
:
# `5749` is the number of identities in LFW dataset, `112,112` is the size of the image
$ vim property
5749,112,112
- Create
.rec
and.idx
files using.lst
file. Run$insightface/src/data/face2rec2.py
:
# NOTE: if you use python3, change line `s = mx.recordio.pack(header, '')` to `s = mx.recordio.pack(header, b'')`.
python face2rec2.py ../../datasets/lfw-aligned/
- Finally create
.bin
file. Run$insightface/src/data/lfw2pack.py
:
python lfw2pack.py --data-dir=../../datasets/lfw-aligned --output=../../datasets/lfw-aligned/lfw.bin
There are two scripts for evaluation, one of which is $insightface/recognition/eval/verification.py
, the other of which is $insightface/src/eval/verification.py
. Both are okay for evaluation and giving the same result:
python verification.py --data-dir=../../datasets/lfw-aligned/ --model=../../models/model-r100-ii/model,0 --target=lfw
You can download pre-trained models from https://github.com/deepinsight/insightface/wiki/Model-Zoo. It is recommanded to place the extracted files under $insightface/models
. You should have similar directory structure like the following:
$ tree -L 1 models/model-r100-ii/
models/model-r100-ii/
├── log
├── model-0000.params
└── model-symbol.json
0 directories, 3 files
Also note that the value of --model
has to be path/to/models,0
, where models
is the prefix of your model files, which is model
in the above case, 0
is to load epoch-num==0
.
Insightface has been updated a lot since this guide. You can checkout back to https://github.com/deepinsight/insightface/tree/f92bf1e48470fdd567e003f196f8ff70461f7a20 (or older) to get some files mentioned in this guide.