This project provides a serias of lightweight face detectors with landmarks which can be deployed on mobile devices.
- Modify the anchor size of Retinaface-mobile0.25
- Add landmarks estimation to Face-Detector-1MB
- 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
- Ubuntu18.04
- Python3.7
- Pytorch1.2
- CUDA10.0 + CUDNN7.5
- 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 |
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 |
- 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 |
-
git clone this project
-
Pytorch version 1.1.0+ and torchvision 0.3.0+ are needed.
-
Codes are based on Python 3
- 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.
- We provide the organized dataset we used as in the above directory structure.
Link: from google cloud or baidu cloud Password: ruck
- 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
- 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
- Generate txt file
python test_widerface.py --trained_model weight_file --network mobile0.25 or slim or RFB
- Evaluate txt results. Demo come from Here
cd ./widerface_evaluate
python setup.py build_ext --inplace
python evaluation.py
- You can also use widerface official Matlab evaluate demo in Here
- Convert pytorch to onnx/ncnn/caffe/tensorflow/tflite
- Converting script on convertor folder
- Generate onnx file
python convert_to_onnx.py --trained_model weight_file --network mobile0.25 or slim or RFB
- 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
- Simplify onnx file
pip install onnx-simplifier
python-m onnxsim input_onnx_model output_onnx_model
- Convert to Caffe
python convertCaffe.py
- Convert to Tensorflow
python demoCaffe.py
python froze_graph_from_ckpt.py
- Convert to Tensorflow lite
python convert_to_tflite.py
- C++ inference code for ncnn/tf/tflite on Detector_cpp folder
- Build Project(set opencv path in CmakeList.txt)
mkdir build
cd build
cmake ..
make -j4
- run
./FaceDetector *.jpg
./FaceDetectorFolder [folder path]
- FaceBoxes
- Retinaface (mxnet)
- Retinaface (pytorch)
- Ultra-Light-Fast-Generic-Face-Detector-1MB
- Face-Detector-1MB-with-landmark
@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}