English | 中文简体
Ultra-lightweight face detection model
This model is a lightweight facedetection model designed for edge computing devices.
- In terms of model size, the default FP32 precision (.pth) file size is 1.04~1.1MB, and the inference frame int8 quantization size is about 300KB.
- In terms of the calculation amount of the model, the input resolution of 320x240 is about 90~109 MFlops.
- There are two versions of the model, version-slim (network backbone simplification,slightly faster) and version-RFB (with the modified RFB module, higher precision).
- Widerface training pre-training model with different input resolutions of 320x240 and 640x480 is provided to better work in different application scenarios.
- Support for onnx export for ease of migration and inference.
Provide NCNN C++ inference code.
Provide MNN C++ inference code, MNN Python inference code, FP32/INT8 quantized models.
Provide Caffe model and onnx2caffe conversion code.
Tested the environment that works
- Ubuntu16.04、Ubuntu18.04、Windows 10（for inference）
- CUDA10.0 + CUDNN7.6
Accuracy, speed, model size comparison
The training set is the VOC format data set generated by using the cleaned widerface labels provided by Retinaface in conjunction with the widerface data set (PS: the following test results were obtained by myself, and the results may be partially inconsistent).
- Test accuracy in the WIDER FACE val set (single-scale input resolution: 320*240 or scaling by the maximum side length of 320)
- Test accuracy in the WIDER FACE val set (single-scale input resolution: VGA 640*480 or scaling by the maximum side length of 640 )
- This part mainly tests the effect of the test set under the medium and small resolutions.
- RetinaFace-mnet (Retinaface-Mobilenet-0.25), from a great job insightface, when testing this network, the original image is scaled by 320 or 640 as the maximum side length, so the face will not be deformed, and the rest of the network will have a fixed size resize. At the same time, the result of the RetinaFace-mnet optimal 1600 single-scale val set was 0.887 (Easy) / 0.87 (Medium) / 0.791 (Hard).
Terminal device inference speed
- Raspberry Pi 4B MNN inference test time (unit: ms) (ARM/A72x4/1.5GHz/input resolution: 320x240 /int8 quantization)
|Official Retinaface-Mobilenet-0.25 (Mxnet)
Model size comparison
- Comparison of several open source lightweight face detection models:
||model file size（MB）
|Official Retinaface-Mobilenet-0.25 (Mxnet)
Generate VOC format training data set and training process
- Download the wideface official website dataset or download the training set I provided and extract it into the ./data folder:
(1) The clean widerface data pack after filtering out the 10px*10px small face: Baidu cloud disk (extraction code: x5gt) 、Google Drive
(2) Complete widerface data compression package without filtering small faces: Baidu cloud disk (extraction code: xeis)、Google Drive
(PS: If you download the filtered packets in (1) above, you don't need to perform this step) Because the wideface has many small and unclear faces, which is not conducive to the convergence of efficient models, it needs to be filtered for training.By default,faces smaller than 10 pixels by 10 pixels will be filtered.
After the program is run and finished, the wider_face_add_lm_10_10 folder will be generated in the ./data directory. The folder data and data package (1) are the same after decompression. The complete directory structure is as follows:
At this point, the VOC training set is ready. There are two scripts: train-version-slim.sh and train-version-RFB.sh in the root directory of the project. The former is used to train the slim version model, and the latter is used. Training RFB version model, the default parameters have been set, if the parameters need to be changed, please refer to the description of each training parameter in ./train.py.
Run train-version-slim.sh train-version-RFB.sh
sh train-version-slim.sh or sh train-version-RFB.sh
Detecting image effects (input resolution: 640x480)
- If the actual production scene is medium-distance, large face, and small number of faces, it is recommended to use input size input_size: 320 (320x240) resolution for training, and use 320x240 ,160x120 or 128x96 image size input for inference, such as using the provided pre-training model version-slim-320.pth or version-RFB-320.pth .
- If the actual production scene is medium or long distance, medium or small face and large face number, it is recommended to adopt:
(1) Optimal: input size input_size: 640 (640x480) resolution training, and use the same or larger input size for inference, such as using the provided pre-training model version-slim-640.pth or version-RFB-640.pth for inference, lower False positives.
(2) Sub-optimal: input size input_size: 320 (320x240) resolution training, and use 480x360 or 640x480 size input for predictive reasoning, more sensitive to small faces, false positives will increase.
- The best results for each scene require adjustment of the input resolution to strike a balance between speed and accuracy.
- Excessive input resolution will enhance the recall rate of small faces, but it will also increase the false positive rate of large and close-range faces, and the speed of inference will increase exponentially.
- Too small input resolution will significantly speed up the inference, but it will greatly reduce the recall rate of small faces.
- The input resolution of the production scene should be as consistent as possible with the input resolution of the model training, and the up and down floating should not be too large.