Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Dlib python to install with CPU support only; on a GPU machine with Cuda and everything

Tags:

c++

python

gpu

dlib

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.

like image 349
Rizwan Avatar asked Nov 05 '25 11:11

Rizwan


2 Answers

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

like image 57
kolukuri Avatar answered Nov 07 '25 01:11

kolukuri


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

like image 25
Nikhil Avatar answered Nov 06 '25 23:11

Nikhil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!