face_recognition_models icon indicating copy to clipboard operation
face_recognition_models copied to clipboard

When running on a CPU-only Google Colab kernel, no CUDA-capable device is detected

Open xjdeng opened this issue 6 years ago • 4 comments

  • face_recognition version: 0.3
  • Python version: 3.6
  • Operating System: Google Colab (cpu-only)

Description

My face encoder doesn't work when running on a CPU-only instance of Google Colab because dlib seems to expect a GPU.

What I Did

import face_recognition_models
import dlib

predictor_5_point_model = face_recognition_models.pose_predictor_five_point_model_location()
pose_predictor_5_point = dlib.shape_predictor(predictor_5_point_model)

predictor_68_point_model = face_recognition_models.pose_predictor_model_location()
pose_predictor_68_point = dlib.shape_predictor(predictor_68_point_model)

face_recognition_model = face_recognition_models.face_recognition_model_location()

face_encoder = dlib.face_recognition_model_v1(face_recognition_model)

And got the following error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-4-2d57e5cbaae3> in <module>()
----> 1 face_encoder = dlib.face_recognition_model_v1(face_recognition_model)

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

Note that this works fine on a GPU instance on Google Colab but not on a cpu-only one. And sometimes, I can't get a GPU instance on Colab which makes it impossible to run some code the uses the face_encoder (which should still work at a reasonable speed on the CPU.)

Here's a link to my Google Colab notebook to reproduce this: https://colab.research.google.com/drive/1wdCrks6Mdx-O9A77umQKUb8wCk8i43Uu

xjdeng avatar Apr 01 '20 19:04 xjdeng

you can enable GPU in colab and it's free. Runtime => Change runtime type and select GPU as Hardware accelerator.

erisitohang avatar Jun 23 '20 12:06 erisitohang

That doesn't solve the problem. Sometimes, Colab denies me a GPU and this library stops working as a result.

xjdeng avatar Jun 23 '20 12:06 xjdeng

the problem here is that the version of dlib that comes preinstalled with colab is configured to work with GPU. the work around here is either to pip uninstall the default dlib and pip install a new one ,or use virtual environments to isolate that dependency

jbichene95 avatar Oct 19 '20 14:10 jbichene95

@jbichene95 i tried to uninstall and reinstall dlib and still getting the error. @xjdeng could you solve this issue?

Finki007 avatar Aug 31 '21 18:08 Finki007