dlib 安装和使用

dlib 安装

使用 pip install dlibconda install dlib 安装的 dlib,默认是 CPU 版本,无法使用 GPU。

dlib GPU 版本安装:
1、去官网 http://dlib.net/ 下载 dlib 压缩包,并解压;
2、安装 cmake,使用 pip install cmakeconda install cmake 安装即可;
3、去 dlip 解压目录下,执行 python setup.py install,等待完成安装。

判断dlib是否可以使用GPU:

import dlib
dlib.DLIB_USE_CUDA   # True 表示可以使用 GPU

使用 dlib 进行人脸检测

import dlib

face_detector = dlib.get_frontal_face_detector()      # 仅利用 CPU,即使 dlib.DLIB_USE_CUDA=True

cnn_face_detector = dlib.cnn_face_detection_model_v1(filename="mmod_human_face_detector.dat")    # CNN-based 方法,可以利用 GPU 加速

官方模型 mmod_human_face_detector.dat 下载链接:

http://dlib.net/files/mmod_human_face_detector.dat.bz2

get_frontal_face_detector() 示例:

https://github.com/davisking/dlib/blob/master/python_examples/face_detector.py

cnn_face_detection_model_v1() 示例:

https://github.com/davisking/dlib/blob/master/python_examples/cnn_face_detector.py

References

使用人脸识别完成单人视频 cut -- 6enmel
dlib.DLIB_USE_CUDA=True and dlib.cuda.get_num_devices() = 6,but cannot see any process in nvidia-smi. #2302
Ubuntu环境下配置使用GPU加速的dlib库 -- Ooo。
http://dlib.net/cnn_face_detector.py.html
https://github.com/ageitgey/face_recognition/blob/55b5c136292dcd4a1f5953f3eb3181235086efab/face_recognition/api.py#L92

作者:wuliytTaotao
本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
原文地址:https://www.cnblogs.com/wuliytTaotao/p/14594178.html