3

I have searched it over the internet and all I can find is that people having trouble with installation of Dlib with Cuda. I have exact opposite problem. I can successfully install Dlib with Cuda and GPU support on Ubuntu (Google Colab). But I don't want that. I want to force Dlib to use CPU since when I change the runtime to TPU, there will be no GPU. But Dlib finds CUDA while installation and add support of CUDA while installation even though runtime is set to "NOT GPU".

pip install Dlib

this will by default install Dlib with cuda, since I am unaware of any flags to disable Cuda. But even if I try to build Dlib from source like:

!git clone https://github.com/davisking/dlib.git
%cd dlib
!mkdir build
%cd build
!cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1 
!cmake --build .
# !sudo make install
# !sudo ldconfig
%cd ..
# !python setup.py build --no DLIB_USE_CUDA
!python setup.py install --no DLIB_USE_CUDA

I can successfully do

import Dlib

But when I used "face_recogntion" which calls Dlib at backend

!pip install face_recognition
import dlib
import face_recognition

it throws an error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-52-c42385b122ec> in <module>()
      2 get_ipython().system('pip install face_recognition')
      3 import dlib
----> 4 import face_recognition

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

RuntimeError: Error while calling cudaGetDevice(&the_device_id) in file /tmp/pip-install-9p_kkgzg/dlib/dlib/cuda/gpu_data.cpp:178. code: 38, reason: no CUDA-capable device is detected

Now I am unable to understand what I am missing. What Flag should I set in order to Force DLIB to use CPU and not even look for GPU even when there is one.

talonmies
  • 70,661
  • 34
  • 192
  • 269
Rizwan
  • 1,210
  • 2
  • 9
  • 21

3 Answers3

4

If you want to install from pip packages directly use following below command

sudo pip install -v --install-option="--no" --install-option="DLIB_USE_CUDA" dlib

kolukuri
  • 317
  • 2
  • 8
2

In Google Colab Go to Toolbar > RunTime > Change runtime type> Set Hardware Accelerator> GPU

Nikhil
  • 115
  • 1
  • 8
  • Is there a way to select two hardware accelerators? . I needed to use TPU, so either we can select TPU or GPU? And my problem was not to use GPU, instead it was to NOT use it. Anyways, the problem is solved, You can check it issues of Dlib with the title of this post i guess. – Rizwan Feb 17 '20 at 21:18
0

If you are using google collaboratory and installed !pip install face_recognition in the collab. Then you should change your runtime acceleration to GPU to import face_recognition

  • 4
    As I can see the question was about how to use CPU instead of GPU. I'm not sure that your answer is valid. – feeeper Jun 25 '20 at 06:16