简体   繁体   English

强制 Dlib python 仅安装 CPU 支持; 在带有 Cuda 和一切的 GPU 机器上

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

I have searched it over the internet and all I can find is that people having trouble with installation of Dlib with Cuda.我在互联网上搜索过它,我只能找到人们在使用 Cuda 安装 Dlib 时遇到问题。 I have exact opposite problem.我有完全相反的问题。 I can successfully install Dlib with Cuda and GPU support on Ubuntu (Google Colab).我可以在 Ubuntu (Google Colab) 上成功安装带有 Cuda 和 GPU 支持的 Dlib。 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.我想强制 Dlib 使用 CPU,因为当我将运行时更改为 TPU 时,将没有 GPU。 But Dlib finds CUDA while installation and add support of CUDA while installation even though runtime is set to "NOT GPU".但是 Dlib 在安装时找到 CUDA 并在安装时添加对 CUDA 的支持,即使运行时设置为“NOT GPU”。

pip install Dlib

this will by default install Dlib with cuda, since I am unaware of any flags to disable Cuda.这将默认安装带有 cuda 的 Dlib,因为我不知道任何禁用 Cuda 的标志。 But even if I try to build Dlib from source like:但即使我尝试从源代码构建 Dlib,例如:

!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但是当我使用在后端调用 Dlib 的“face_recogntion”时

!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.我应该设置什么标志才能强制 DLIB 使用 CPU,甚至不寻找 GPU,即使有一个。

If you want to install from pip packages directly use following below command如果要从 pip 包直接安装,请使用以下命令

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

In Google Colab Go to Toolbar > RunTime > Change runtime type> Set Hardware Accelerator> GPU在 Google Colab Go 到工具栏 > 运行时 > 更改运行时类型 > 设置硬件加速器 > GPU

If you are using google collaboratory and installed !pip install face_recognition in the collab.如果您使用的是 google collaboratory 并在 collab 中安装了!pip install face_recognition。 Then you should change your runtime acceleration to GPU to import face_recognition然后您应该将运行时加速更改为 GPU 以导入 face_recognition

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM