/libfacedetection.train

The training program for libfacedetection for face detection and 5-landmark detection.

Primary LanguagePythonMIT LicenseMIT

Training for libfacedetection in PyTorch

License

It is the training program for libfacedetection. The source code is based on FaceBoxes.PyTorch and ssd.pytorch.

Visualization of our network architecture: [netron].

Contents

Installation

  1. Install PyTorch >= v1.7.0 following official instruction.

  2. Clone this repository. We will call the cloned directory as $TRAIN_ROOT.

    git clone https://github.com/ShiqiYu/libfacedetection.train
  3. Install dependencies.

    pip install -r requirements.txt

Note: Codes are based on Python 3+.

Preparation

  1. Download the WIDER Face dataset and its evaluation tools.
  2. Extract zip files under $TRAIN_ROOT/data/widerface as follows:
    $ tree data/widerface
    data/widerface
    ├── eval_tools
    ├── train_label
    ├── wider_face_split
    ├── WIDER_test
    ├── WIDER_train
    └── WIDER_val

NOTE: We relabled the WIDER Face train set using RetinaFace. New labels are in $TRAIN_ROOT/data/train_label.

Training

cd $TRAIN_ROOT/tasks/task1/
python train.py

Detection

cd $TRAIN_ROOT/tasks/task1/
python detect.py -m weights/yunet_final.pth --image_file=filename.jpg

Evaluation on WIDER Face

  1. Build NMS module.

    cd $TRAIN_ROOT/src/widerface_eval
    python setup.py build_ext --inplace
  2. Perform evaluation. To reproduce the following performance, run on the default settings. Run python test.py --help for more options.

    cd $TRAIN_ROOT/tasks/task1/
    python test.py -m weights/yunet_final.pth

NOTE: We now use the Python version of eval_tools from here.

Performance on WIDER Face (Val): scales=[1.], confidence_threshold=0.3:

AP_easy=0.834, AP_medium=0.824, AP_hard=0.708

Export CPP source code

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

Export to onnx model for libfacedetection/example/opencv_dnn.

cd $TRAIN_ROOT/tasks/task1/
python exportonnx.py -m weights/yunet_final.pth

Design your own model

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 .

Citation

The loss used in training is EIoU, a novel extended IoU. More details can be found in:

@article{eiou,
 title={A Systematic IoU-Related Method: Beyond Simplified Regression for Better Localization},
 author={Hanyang Peng and Shiqi Yu},
 journal={IEEE Transactions on Image Processing},
 year={2021}
 }

The paper can be downloaded at https://ieeexplore.ieee.org/document/9429909.