Skip to content

Latest commit

 

History

History
96 lines (72 loc) · 3.45 KB

README.md

File metadata and controls

96 lines (72 loc) · 3.45 KB

MobileFaceNet_TF

Tensorflow implementation for MobileFaceNet.
This version is different from the original repo sirius-ai/MobileFaceNet_TF:

  • Model checkpoint and re-train continuously is more easier. This is suitable for model training progress on Google Colaboratory.
  • Bug fixes
  • Convert to Tensorflow Lite format
  • Provide examples on ipython notebooks

Pre-trained model

Pretrain is available at arch/pretrained_model/MobileFaceNet_TFLite/.


Dependencies

  • tensorflow 1.x >= r1.5
  • opencv-python 3.x
  • python 3.x
  • scipy
  • sklearn
  • numpy
  • mxnet
  • pickle

Prepare dataset

  1. Choose one of the following links to download dataset which is provide by insightface. (Special Recommend MS1M-refine-v2)
  1. Move dataset to ${MobileFaceNet_TF_ROOT}/datasets.
  2. Run ${MobileFaceNet_TF_ROOT}/utils/data_process.py.

Take a look at data_prepair.ipynb for more details.


Training

  1. Refined super parameters by yourself special project.
  2. Run script ${MobileFaceNet_TF_ROOT}/train_nets.py
  3. Have a snapshot result at ${MobileFaceNet_TF_ROOT}/output.

Take a look at train.ipynb for more details.


Convert to Tensorflow Lite format

  1. Choose your best model checkpoint.
  2. Freeze graph and get the .pb model file using freeze_graph.py
python3 freeze_graph.py \
--pretrained_model ./arch/pretrained_model/MobileFaceNet_TFLite/checkpoints/895000_MobileFaceNet.ckpt   \
--output_file ./arch/pretrained_model/MobileFaceNet_TFLite/MobileFaceNet.pb
  1. Convert to TFLite format
    For example:
tflite_convert \
--output_file ./arch/pretrained_model/MobileFaceNet_TFLite/MobileFaceNet.tflite  \
--graph_def_file ./arch/pretrained_model/MobileFaceNet_TFLite/MobileFaceNet.pb  \
--input_arrays "input" \
--input_shapes "1,112,112,3"  \
--output_arrays embeddings \
--output_format TFLITE

You may need to choose the suitable inference batch size. The previous example use batchsize = 1.

Take a look at test.ipynb for more details.


Performance

size LFW(%) Val@1e-3(%) inference@GPU: Qualcomm Adreno TM 509(ms)
4.9MB 99.4+ 98.3+ 30-

References

  1. facenet
  2. InsightFace mxnet
  3. InsightFace_TF
  4. MobileFaceNets: Efficient CNNs for Accurate Real-Time Face Verification on Mobile Devices
  5. CosFace: Large Margin Cosine Loss for Deep Face Recognition
  6. InsightFace : Additive Angular Margin Loss for Deep Face Recognition