一个简单而轻量级的软件包,用于支持GPU的最先进的人脸检测。
face-detection的Python项目详细描述
基于DSFD和RetinaFace的Pytorch人脸检测技术
此存储库包括:
- 本文“DSFD: Dual Shot Face Detector" (CVPR 2019).”的一个高性能Pythorch实现,改编自original source code。在
- 轻量级单发人脸检测来自于纸张RetinaFace: Single-stage Dense Face Localisation in the Wild改编自https://github.com/biubug6/Pytorch_Retinaface。在
NOTE此实现只能用于模型选择的推理,并且所有的训练脚本都将被删除。如果您想微调任何模型,我们建议您使用原始源代码。在
安装
您可以使用pip安装这个存储库(需要python>;=3.6)
pip install git+https://github.com/hukkelas/DSFD-Pytorch-Inference.git
也可以使用setup.py
安装
入门
跑
python3 test.py
这将在images/
文件夹中查找图像,并将结果保存在以_out.jpg
结尾的同一文件夹中
简单API
要执行检测,可以简单地使用以下行:
importcv2importface_detectionprint(face_detection.available_detectors)detector=face_detection.build_detector("DSFDDetector",confidence_threshold=.5,nms_iou_threshold=.3)# BGR to RGBim=cv2.imread("path_to_im.jpg")[:,:,::-1]detections=detector.detect(im)
这将返回一个形状为[N, 5]
的张量,其中N是面数,五个元素是[xmin, ymin, xmax, ymax, detection_confidence]
批处理推理
importnumpyasnpimportface_detectionprint(face_detection.available_detectors)detector=face_detection.build_detector("DSFDDetector",confidence_threshold=.5,nms_iou_threshold=.3)# [batch size, height, width, 3]images_dummy=np.zeros((2,512,512,3))detections=detector.batched_detect(im)
改进
与DSFD的差异
有关原始源代码,请参见here。在
- 删除培训/加载VGG模型的所有不必要的文件。在
- 使用
time
(在V100-32gbgpu上测量)粗略估计,将推理时间提高约30倍(从6s到0.2)。在
推理时间的主要改进来自:
- 将非最大抑制替换为highly optimized torchvision version
- 重构SSD model中的
init_priors
以缓存以前的大小(不需要每次向前传递生成此值)。在 - 重构^{
} 中的Detect
中的前向传递,以便在非最大值抑制之前执行置信阈值 - 使用Pythorch1.0特性的前向过程中的细微变化
与视网膜表面的差异
有关原始源代码,请参见here。在
我们做了以下改进:
- 删除推理的梯度计算(
torch.no_grad
)。在 - 将非最大抑制替换为highly optimized torchvision version
推理时间
这是在1024x687图像上粗略估计的。报告的时间是单个图像上平均超过1000次的正向传递。(无cudnn基准和fp16计算)。在
DSFDDetector | RetinaNetResNet50 | RetinaNetMobileNetV1 | |
---|---|---|---|
CPU (Intel 2.2GHz i7) * | 17,496 ms (0.06 FPS) | 2970ms (0.33 FPS) | 270ms (3.7 FPS) |
NVIDIA V100-32GB | 76.41 (13.1 FPS) | 29.05ms (34.43 FPS) | 22.09ms (45.28 FPS) |
NVIDIA GTX 1080 8GB | 197.3 (5.1 FPS) | 42.45ms (23.55 FPS) | 16.55ms (60.43 FPS) |
NVIDIA T4 16 GB |
*2014年年中,在MacOS上完成了100多次向前传球,15英寸。在
变更日志
- 2020年9月1日:增加对fp16/混合精度推断的支持
- 2020年9月2日:通过优化先验盒生成来减少推理时间
引文
如果您发现此代码有用,请记住引用原始作者:
@inproceedings{li2018dsfd,
title={DSFD: Dual Shot Face Detector},
author={Li, Jian and Wang, Yabiao and Wang, Changan and Tai, Ying and Qian, Jianjun and Yang, Jian and Wang, Chengjie and Li, Jilin and Huang, Feiyue},
booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},
year={2019}
}
@inproceedings{deng2019retinaface,
title={RetinaFace: Single-stage Dense Face Localisation in the Wild},
author={Deng, Jiankang and Guo, Jia and Yuxiang, Zhou and Jinke Yu and Irene Kotsia and Zafeiriou, Stefanos},
booktitle={arxiv},
year={2019}
- 项目
标签: