Skip to content

Lightweight face detectors with landmarks. Training code using pytorch and inference using pytorch/ncnn/tensorflow/tflite.

License

Notifications You must be signed in to change notification settings

yyqgood/Lightweight-Face-Detector-With-Landmarks

 
 

Repository files navigation

Lightwight Face Detector with Landmarks

Contents

Introduction

This project provides a serias of lightweight face detectors with landmarks which can be deployed on mobile devices.

Functions

  • Train/test/evaluation/ncnn/tensorflow/tflite/C++ inference of Retinaface-mobile0.25
  • Train/test/evaluation/ncnn/tensorflow/tflite/C++ inference of Face-Detector-1MB slim and RFB version
  • Add 5 landmarks estimation to Face-Detector-1MB
  • Support the inference using pytorch/ncnn/tensorflow/tflite

Test_environment

  • Ubuntu18.04
  • Python3.7
  • Pytorch1.2
  • CUDA10.0 + CUDNN7.5

Evaluation

Widerface

  • Evaluation result on wider face val (input image size: 320*240
<ethods Easy Medium Hard
libfacedetection v1(caffe) 0.65 0.5 0.233
libfacedetection v2(caffe) 0.714 0.585 0.306
version-slim(origin) 0.765 0.662 0.385
version-RFB(origin) 0.784 0.688 0.418
version-slim(our) 0.795 0.683 0.34.5
version-RFB(our) 0.814 0.710 0.363
Retinaface-Mobilenet-0.25(our) 0.811 0.697 0.376
  • Evaluation result on wider face val (input image size: 640*480)
Methods Easy Medium Hard
libfacedetection v1(caffe) 0.741 0.683 0.421
libfacedetection v2(caffe) 0.773 0.718 0.485
version-slim(origin) 0.757 0.721 0.511
version-RFB(origin) 0.851 0.81 0.541
version-slim(our) 0.850 0.808 0.595
version-RFB(our) 0.865 0.828 0.622
Retinaface-Mobilenet-0.25(our) 0.873 0.836 0.638

Parameter_and_flop

Methods parameter(M) flop(M)
version-slim(our) 0.343 98.793
version-RFB(our) 0.359 118.435
Retinaface-Mobilenet-0.25(our) 0.426 193.921

Speed

  • Test speed on RK3399 using tflite format

Input image size: 320*240

Methods Speed(ms)
MTCNN 325
version-slim(our) 82
version-RFB(our) 94
Retinaface-Mobilenet-0.25(our) 103

Input image size: 640*480

Methods Speed(ms)
MTCNN 420
version-slim(our) 342
version-RFB(our) 380
Retinaface-Mobilenet-0.25(our) 438

How_to_use

Installation

Clone and install
  1. git clone this project

  2. Pytorch version 1.1.0+ and torchvision 0.3.0+ are needed.

  3. Codes are based on Python 3

Data
  1. The dataset directory as follows:
  ./data/widerface/
    train/
      images/
      label.txt
    val/
      images/
      wider_val.txt

ps: wider_val.txt only include val file names but not label information.

  1. We provide the organized dataset we used as in the above directory structure.

Link: from google cloud or baidu cloud Password: ruck

Training

  1. Before training, you can check network configuration (e.g. batch_size, min_sizes and steps etc..) in data/config.py and train.py.
 adjuct lmk_weight and loc_weight to improve the landmarks accuracy
  1. Train the model using WIDER FACE:
CUDA_VISIBLE_DEVICES=0 python train.py --network mobile0.25 or 
CUDA_VISIBLE_DEVICES=0 python train.py --network slim or
CUDA_VISIBLE_DEVICES=0 python train.py --network RFB

If you don't want to train, we also provide a trained model on ./weights

mobilenet0.25_Final.pth 
RBF_Final.pth
slim_Final.pth

Evaluation

Evaluation widerface val

  1. Generate txt file
python test_widerface.py --trained_model weight_file --network mobile0.25 or slim or RFB
  1. Evaluate txt results. Demo come from Here
cd ./widerface_evaluate
python setup.py build_ext --inplace
python evaluation.py
  1. You can also use widerface official Matlab evaluate demo in Here

Convertor

  • Convert pytorch to onnx/ncnn/caffe/tensorflow/tflite
  • Converting script on convertor folder
  1. Generate onnx file
python convert_to_onnx.py --trained_model weight_file --network mobile0.25 or slim or RFB
  1. Onnx file change to ncnn(*.param and *.param)
cp *.onnx ./Detector_cpp/Face_Detector_ncnn/tools
cd ./Detector_cpp/Face_Detector_ncnn/tools
./onnx2ncnn face.param face.bin
  1. Simplify onnx file
pip install onnx-simplifier
python-m onnxsim input_onnx_model output_onnx_model
  1. Convert to Caffe
python convertCaffe.py
  1. Convert to Tensorflow
python demoCaffe.py
python froze_graph_from_ckpt.py
  1. Convert to Tensorflow lite
python convert_to_tflite.py

C++_inference

  • C++ inference code for ncnn/tf/tflite on Detector_cpp folder
  1. Build Project(set opencv path in CmakeList.txt)
mkdir build
cd build
cmake ..
make -j4
  1. run
./FaceDetector *.jpg
./FaceDetectorFolder [folder path]

References

@inproceedings{deng2019retinaface,
title={RetinaFace: Single-stage Dense Face Localisation in the Wild},
author={Deng, Jiankang and Guo, Jia and Yuxiang, Zhou and Jinke Yu and Irene Kotsia and Zafeiriou, Stefanos},
booktitle={arxiv},
year={2019}

About

Lightweight face detectors with landmarks. Training code using pytorch and inference using pytorch/ncnn/tensorflow/tflite.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.4%
  • CMake 2.6%