如何在 Google Colaboratory 中导入 face_recognition?

How do I import face_recognition in Google Colaboratory?

我在 Google Colab 工作并且已经导入了 dlib

!pip install dlib
import dlib

并安装了 face_recognition 模块。

!pip install face_recognition

但是,这一行我收到错误消息:

import face_recognition
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from matplotlib.patches import Circle
import numpy as np
import cv2

%matplotlib inline

错误如下:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-159-91aca6eea0d3> in <module>()
----> 1 import face_recognition
      2 import matplotlib.pyplot as plt
      3 from matplotlib.patches import Rectangle
      4 from matplotlib.patches import Circle
      5 import numpy as np

1 frames
/usr/local/lib/python3.6/dist-packages/face_recognition/api.py in <module>()
     24 
     25 cnn_face_detection_model = face_recognition_models.cnn_face_detector_model_location()
---> 26 cnn_face_detector = dlib.cnn_face_detection_model_v1(cnn_face_detection_model)
     27 
     28 face_recognition_model = face_recognition_models.face_recognition_model_location()

RuntimeError: Error while calling cudaGetDevice(&the_device_id) in file /tmp/pip-wheel-66glv9rf/dlib/dlib/cuda/gpu_data.cpp:201. code: 100, reason: no CUDA-capable device is detected

可以做什么?

从错误中我可以看出您(可能)没有启用 GPU 加速。

转到运行时间 -> 更改运行时间 -> Select GPU

然后运行代码!pip install face_recognition

这应该可以毫无问题地安装库(和依赖项)。此外,您不需要单独安装 dlib。让 face_recognition 与它一起构建它。