如何 运行 dlib 人脸识别与 gpu

how to run dlib face recognition with gpu

我已经安装了 visual studio 2019、Cuda 10.1 和 TensorFlow 2.1.0,但我仍然无法 运行 使用 GPU 进行人脸识别,谁能给我一个完整的步骤指南使用 GPU 而不是 CPU.

注意:我用的是windows10,我的GPU是gtx1050,我用的是anaconda spider。

首先,你应该安装 tensorflow-gpu 包而不是 tensorflow。

如果你的tf安装正确,你可以运行在deepface的gpu中进行人脸识别。您可以使用分配内存功能进行测试。

#!pip install deepface
from deepface import DeepFace
DeepFace.allocateMemory()

如果一切正常,则会显示 returns“DeepFace 将 运行 在 GPU 上”消息。

除 Dlib 之外的所有人脸识别模型都将在 tensorflow-gpu 上 运行。可以运行人脸识别带验证功能

from deepface import DeepFace
models = ["VGG-Face", "Facenet", "OpenFace", "DeepFace", "DeepID", "Dlib"]
obj = DeepFace.verify("img1.jpg", "img2.jpg", model_name = models[0])
print(obj)

我使用 anaconda 环境通过这些步骤解决了这个问题:

已安装 cuda 10.2

python (3.7.7)

conda 安装 pip

conda安装tensorflow(最新2.1.0)

conda 安装 tensorflow-gpu

pip 安装 imutils

pip install opencv-python

pip 安装 opencv-contrib-python

pip 安装 dlib

pip 安装face_recognition

正如 Adrian Rosebrock 在 https://www.pyimagesearch.com/2018/06/18/face-recognition-with-opencv-python-and-deep-learning/ 中提到的那样,最好从源代码构建 Dlib,这样该库就会知道您的系统中存在确切的 GPU。我的猜测是 - 在构建过程中,它通过 CUDA 驱动程序探测 GPU 的功能并相应地构建和安装。

git 克隆 https://github.com/davisking/dlib.git
cd dlib
mkdir 构建
光盘构建
cmake .. -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1
cmake --build .
CD ..
python setup.py 安装 --yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDA