It is the training program for libfacedetection. The source code is based on FaceBoxes.PyTorch and ssd.pytorch.
Visualization of our network architecture: [netron].
- Installation
- Preparation
- Training
- Detection
- Evaluation on WIDER Face
- Export CPP source code
- Export to ONNX model
- Design your own model
- Citation
-
Install PyTorch >= v1.7.0 following official instruction.
-
Clone this repository. We will call the cloned directory as
$TRAIN_ROOT
.git clone https://github.com/ShiqiYu/libfacedetection.train
-
Install dependencies.
pip install -r requirements.txt
Note: Codes are based on Python 3+.
- Download the WIDER Face dataset and its evaluation tools.
- Extract zip files under
$TRAIN_ROOT/data/widerface
as follows:$ tree data/widerface data/widerface ├── eval_tools ├── wider_face_split ├── WIDER_test ├── WIDER_train ├── WIDER_val └── trainset.json
NOTE:
We relabled the WIDER Face train set using RetinaFace. New labels are in
$TRAIN_ROOT/data/widerface/trainset.json
, which is the COCO_format annotations file used in DALI dataloader.
cd $TRAIN_ROOT/tasks/task1/
python train.py
cd $TRAIN_ROOT/tasks/task1/
python detect.py -m weights/yunet_final.pth --image_file=filename.jpg
Run on default settings to repoduce the evaluation results.
cd $TRAIN_ROOT/tasks/task1/
python test.py -m weights/yunet_final.pth
Run python test.py --help
for more options.
NOTE: We use the modified Python version of eval_tools
from here.
Performance on WIDER Face (Val): scales=[1.], confidence_threshold=0.3:
AP_easy=0.856, AP_medium=0.842, AP_hard=0.727
The following bash code can export a CPP file for project libfacedetection
cd $TRAIN_ROOT/tasks/task1/
python exportcpp.py -m weights/yunet_final.pth -o output.cpp
Export to onnx model for libfacedetection/example/opencv_dnn.
cd $TRAIN_ROOT/tasks/task1/
python exportonnx.py -m weights/yunet_final.pth
You can copy $TRAIN_ROOT/tasks/task1/
to $TRAIN_ROOT/tasks/task2/
or other similar directory, and then modify the model defined in file: tasks/task2/yufacedetectnet.py .
The loss used in training is EIoU, a novel extended IoU. More details can be found in:
@article{eiou,
author={Peng, Hanyang and Yu, Shiqi},
journal={IEEE Transactions on Image Processing},
title={A Systematic IoU-Related Method: Beyond Simplified Regression for Better Localization},
year={2021},
volume={30},
pages={5032-5044},
doi={10.1109/TIP.2021.3077144}
}
The paper can be open accessed at https://ieeexplore.ieee.org/document/9429909.
We also published a paper on face detection to evaluate different methods.
@article{facedetect-yu,
author={Yuantao Feng and Shiqi Yu and Hanyang Peng and Yan-ran Li and Jianguo Zhang}
title={Detect Faces Efficiently: A Survey and Evaluations},
journal={IEEE Transactions on Biometrics, Behavior, and Identity Science},
year={2021}
}
The paper can be open accessed at https://ieeexplore.ieee.org/document/9580485