Skip to content

GuoQuanhao/RetinaFace-Paddle

Repository files navigation

RetinaFace-Paddle

论文提出了一种强大的单阶段面部检测器RetinaFace,通过联合外监督(extra-supervised)和自监督(self-supervised)多任务学习的优势,在各种规模的人脸上执行像素级人脸定位,并实现了在WIDER FACE数据集上的最佳表现(SOTA


数据文件部署

数据文件可以在AIStudio下载wider_val.txt文件可在此处下载[baidu/mrnh]

/home/aistudio
|-- Data
|   |-- widerface
|      |-- train
|          |-- images
|          |-- label.txt
|      |-- test
|          |-- images
|          |-- label.txt
|      |-- val
|          |-- images
|          |-- label.txt
|          |-- wider_val.txt
|-- RetinaFace
|   |-- widerface_evaluate(验证时需要自行配置)
|   |-- layers
|   |-- curve
|   |-- utils
|   |-- data
|   |-- models
|   |-- detect.py
|   |-- convert_to_onnx.py
|   |-- test.py
|   |-- train.py
|   |-- test_widerface.py

训练

在使用中需要下载的所有资源文件,训练日志,ground_truth,训练模型以及预训练模型都可在[baidu/mrnh]

train from scratch

python train.py --network resnet50

train from checkpoint

python train.py --network resnet50 --resume_epoch 20 --resume_net ./weights/Resnet50_epoch_20.pdparams

需要注意到:

1.在训练之前,训练配置保存在data/config.py以及train.pyargs参数

2.使用多卡训练multi_gpu_train.py时,其gpu选取采用spawn机制,你需要手动设置而不是从data/config.py获取

3.经过验证,本项目还支持轻量化模型mobilenetV1X0.25训练,同样你需要下载预训练模型

python train.py --network mobile0.25

评估

此处下载评估代码,将其命名为widerface_evaluate如数据文件配置所示

生成预测文本文件

python test_widerface.py --trained_model ./torch2paddlemodel/Resnet50_Final.pdparams --network resnet50

进入widerface_evaluate,将下载的ground_truth放入widerface_evaluate文件夹下,编译并评估

cd /home/aistudio/Retinaface/widerface_evaluate
python setup.py build_ext --inplace
python evaluation.py

注意到如果使用GitHub仓库在预测时出现报错需要修改evaluation.py89boxes = np.array(list(map(lambda x: [float(a) for a in x.rstrip('\r\n').split(' ')], lines))).astype('float')boxes = np.array(list(map(lambda x: [float(a) for a in x.rstrip('\r\n').split(' ')[:-1]], lines))).astype('float')

推荐直接使用AIStudio仓库

评估精度如下

在没有复杂后处理的情况下,PaddlePaddle训练结果均高于其余框架

根据论文的mAP精度测试协议, we also make use of the development server (Hard validation subset) of the WIDER Face Challenge 2018 [33], which employs a more strict evaluation metric of mean AP (mAP) for IoU=0.5:0.05:0.95, rewarding more accurate face detectors.我在repo中更新了evaluate.py 新增了mAP测试协议,只需要注释或做如下替换:

if __name__ == '__main__':

    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--pred', default="./widerface_txt/")
    parser.add_argument('-g', '--gt', default='./ground_truth/')

    args = parser.parse_args()
    evaluation_mAP(args.pred, args.gt)

运行

python evaluation.py

结果如下

iou_thresh=0.50
Processing hard: 100%|████████████████████████████████████████████████████████| 61/61 [00:11<00:00,  5.24it/s]
==================== Results ====================
Hard   Val AP: 0.9001669787983496
=================================================
iou_thresh=0.55
Processing hard: 100%|████████████████████████████████████████████████████████| 61/61 [00:11<00:00,  5.29it/s]
==================== Results ====================
Hard   Val AP: 0.8765281335631281
=================================================
iou_thresh=0.60
Processing hard: 100%|████████████████████████████████████████████████████████| 61/61 [00:11<00:00,  5.30it/s]
==================== Results ====================
Hard   Val AP: 0.8361440379223611
=================================================
iou_thresh=0.65
Processing hard: 100%|████████████████████████████████████████████████████████| 61/61 [00:11<00:00,  5.29it/s]
==================== Results ====================
Hard   Val AP: 0.779051487622847
=================================================
iou_thresh=0.70
Processing hard: 100%|████████████████████████████████████████████████████████| 61/61 [00:11<00:00,  5.28it/s]
==================== Results ====================
Hard   Val AP: 0.6888435438730449
=================================================
iou_thresh=0.75
Processing hard: 100%|████████████████████████████████████████████████████████| 61/61 [00:11<00:00,  5.26it/s]
==================== Results ====================
Hard   Val AP: 0.5621200454431498
=================================================
iou_thresh=0.80
Processing hard: 100%|████████████████████████████████████████████████████████| 61/61 [00:11<00:00,  5.26it/s]
==================== Results ====================
Hard   Val AP: 0.39284757764295203
=================================================
iou_thresh=0.85
Processing hard: 100%|████████████████████████████████████████████████████████| 61/61 [00:11<00:00,  5.29it/s]
==================== Results ====================
Hard   Val AP: 0.19579832709560405
=================================================
iou_thresh=0.90
Processing hard: 100%|████████████████████████████████████████████████████████| 61/61 [00:11<00:00,  5.27it/s]
==================== Results ====================
Hard   Val AP: 0.04667405826534609
=================================================
iou_thresh=0.95
Processing hard: 100%|████████████████████████████████████████████████████████| 61/61 [00:11<00:00,  5.25it/s]
==================== Results ====================
Hard   Val AP: 0.0016165497954932979
=================================================
==================== Results ====================
mAP: 0.5279790740022274
=================================================

论文精度为52.318

TODO

convert_to_onnx.py编写完成但暂未验证其实用性

推理

python detect.py

你可以从78行指定图片路径,默认将读取./curve/test.jpg,推理效果如下

关于作者

姓名 郭权浩
学校 电子科技大学研2020级
研究方向 计算机视觉
CSDN主页 Deep Hao的CSDN主页
GitHub主页 Deep Hao的GitHub主页
如有错误,请及时留言纠正,非常蟹蟹!
后续会有更多论文复现系列推出,欢迎大家有问题留言交流学习,共同进步成长!

About

A reproduction of RetinaFace by PaddlePaddle

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published