# scrfd **Repository Path**: nextvpu2016/scrfd ## Basic Information - **Project Name**: scrfd - **Description**: 源自insightface的scrfd - **Primary Language**: Python - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-03-16 - **Last Updated**: 2023-03-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Installation Please refer to [mmdetection](https://github.com/open-mmlab/mmdetection/blob/master/docs/en/get_started.md#installation) for installation. 1. Install [mmcv](https://github.com/open-mmlab/mmcv). (mmcv-full==1.2.6 and 1.3.3 was tested) 2. Install build requirements and then install mmdet. ``` pip install -r requirements/build.txt pip install -v -e . # or "python setup.py develop" ``` ## Data preparation ### WIDERFace: 1. Download WIDERFace datasets and put it under `data/retinaface`. 2. Download annotation files from [gdrive](https://drive.google.com/file/d/1UW3KoApOhusyqSHX96yEDRYiNkd3Iv3Z/view?usp=sharing) and put them under `data/retinaface/` ``` data/retinaface/ train/ images/ labelv2.txt val/ images/ labelv2.txt gt/ *.mat ``` #### Annotation Format *please refer to labelv2.txt for detail* For each image: ``` # image_width image_height bbox_x1 bbox_y1 bbox_x2 bbox_y2 (*N) ... ... # image_width image_height bbox_x1 bbox_y1 bbox_x2 bbox_y2 (*N) ... ... ``` Keypoints can be ignored if there is bbox annotation only. ## Training Example training command, with 4 GPUs: ``` CUDA_VISIBLE_DEVICES="0,1,2,3" PORT=29701 bash ./tools/dist_train.sh ./configs/scrfd/scrfd_1g.py 4 ``` if use int8mdoel, dont use GN layer. need change '\configs\scrfd_RGB.py' datapath: ``` train=dict( type='RetinaFaceDataset', ann_file='xxxxxx/data/retinaface/train_label/labelv2.txt', img_prefix='xxxxxx/data/retinaface/train/images/', ... val=dict( type='RetinaFaceDataset', ann_file='xxxxxx/data/retinaface/val/widerface.txt', img_prefix='xxxxxx/data/retinaface/val/images/', ... test=dict( type='RetinaFaceDataset', ann_file='xxxxxx/data/retinaface/val/widerface.txt', img_prefix='xxxxxx/data/retinaface/val/images/', ... ``` want use ResNetV1e: ``` bash ./tools/train_RGB_bn.sh ``` want use MobileNetV1: need change '\configs\scrfd_RGB3H.py' datapath: ``` bash ./tools/train_RGB3H.sh ``` ## WIDERFace Evaluation We use a pure python evaluation script without Matlab. ``` GPU=0 GROUP=scrfd TASK=scrfd_2.5g CUDA_VISIBLE_DEVICES="$GPU" python -u tools/test_widerface.py ./configs/"$GROUP"/"$TASK".py ./work_dirs/"$TASK"/model.pth --mode 0 --out wouts ``` ## Pretrained-Models | Name | Easy | Medium | Hard | FLOPs | Params(M) | Infer(ms) | Link | | :------------: | ----- | ------ | ----- | ----- | --------- | --------- | ------------------------------------------------------------ | | SCRFD_500M | 90.57 | 88.12 | 68.51 | 500M | 0.57 | 3.6 | [download](https://1drv.ms/u/s!AswpsDO2toNKqyYWxScdiTITY4TQ?e=DjXof9) | | SCRFD_1G | 92.38 | 90.57 | 74.80 | 1G | 0.64 | 4.1 | [download](https://1drv.ms/u/s!AswpsDO2toNKqyPVLI44ahNBsOMR?e=esPrBL) | | SCRFD_2.5G | 93.78 | 92.16 | 77.87 | 2.5G | 0.67 | 4.2 | [download](https://1drv.ms/u/s!AswpsDO2toNKqyTIXnzB1ujPq4th?e=5t1VNv) | | SCRFD_10G | 95.16 | 93.87 | 83.05 | 10G | 3.86 | 4.9 | [download](https://1drv.ms/u/s!AswpsDO2toNKqyUKwTiwXv2kaa8o?e=umfepO) | | SCRFD_34G | 96.06 | 94.92 | 85.29 | 34G | 9.80 | 11.7 | [download](https://1drv.ms/u/s!AswpsDO2toNKqyKZwFebVlmlOvzz?e=V2rqUy) | | SCRFD_500M_KPS | 90.97 | 88.44 | 69.49 | 500M | 0.57 | 3.6 | [download](https://1drv.ms/u/s!AswpsDO2toNKri_NDM0GIkPpkE2f?e=JkebJo) | | SCRFD_2.5G_KPS | 93.80 | 92.02 | 77.13 | 2.5G | 0.82 | 4.3 | [download](https://1drv.ms/u/s!AswpsDO2toNKqyGlhxnCg3smyQqX?e=A6Hufm) | | SCRFD_10G_KPS | 95.40 | 94.01 | 82.80 | 10G | 4.23 | 5.0 | [download](https://1drv.ms/u/s!AswpsDO2toNKqycsF19UbaCWaLWx?e=F6i5Vm) | mAP, FLOPs and inference latency are all evaluated on VGA resolution. ``_KPS`` means the model includes 5 keypoints prediction. ## Convert to ONNX Please refer to `tools/scrfd2onnx.py` Generated onnx model can accept dynamic input as default. You can also set specific input shape by pass ``--shape 640 640``, then output onnx model can be optimized by onnx-simplifier. ## Inference Please refer to `tools/scrfd.py` which uses onnxruntime to do inference.