使用 GPU 支持安装 dlib 时出错

Posted

技术标签:

【中文标题】使用 GPU 支持安装 dlib 时出错【英文标题】:ERROR while Installing dlib with GPU support 【发布时间】:2020-09-02 01:32:47 【问题描述】:

我已经安装了 Cmake、visual studio 2019 和 anaconda。我正在尝试在 gpu 支持中使用 Dlib。但是每次我尝试安装它时,运行 python setup.py 都会出现以下错误。 我很想使用带有 GPU (CUDA) 支持的 Dlib。


   C:\Users\yugahang\anaconda3\Lib\site-packages\dlib-master>python setup.py install --set 
    USE_AVX_INSTRUCTIONS --set DLIB_USE_CUDA
    running install
    running bdist_egg
    running egg_info
    writing dlib.egg-info\PKG-INFO
    writing dependency_links to dlib.egg-info\dependency_links.txt
    writing top-level names to dlib.egg-info\top_level.txt
    package init file 'dlib\__init__.py' not found (or not a regular file)
    reading manifest file 'dlib.egg-info\SOURCES.txt'

    reading manifest template 'MANIFEST.in'
    no previously-included directories found matching 'tools\python\build*'
    writing manifest file 'dlib.egg-info\SOURCES.txt'
    installing library code to build\bdist.win-amd64\egg
    running install_lib
    running build_py
    running build_ext
    Building extension for Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]
    Invoking CMake setup: 'cmake C:\Users\yugahang\anaconda3\Lib\site-packages\dlib-master\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\yugahang\anaconda3\Lib\site-packages\dlib-master\build\lib.win-amd64-3.7 -DPYTHON_EXECUTABLE=C:\Users\yugahang\Anaconda3\python.exe -DUSE_AVX_INSTRUCTIONS -DDLIB_USE_CUDA -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\yugahang\anaconda3\Lib\site-packages\dlib-master\build\lib.win-amd64-3.7 -A x64'
    CMake Error: Parse error in command line argument: -DUSE_AVX_INSTRUCTIONS
    Should be: VAR:type=value

    CMake Error: Problem processing arguments. Aborting.


    Traceback (most recent call last):
      File "setup.py", line 261, in 
        'Topic :: Software Development',
      File "C:\Users\yugahang\Anaconda3\lib\site-packages\setuptools\__init__.py", line 144, in setup
        return distutils.core.setup(**attrs)
      File "C:\Users\yugahang\Anaconda3\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "C:\Users\yugahang\Anaconda3\lib\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "C:\Users\yugahang\Anaconda3\lib\distutils\dist.py", line 985, in run_commands`   `
        cmd_obj.run()
      File "C:\Users\yugahang\Anaconda3\lib\site-packages\setuptools\command\install.py", line 67, in run
        self.do_egg_install()
      File "C:\Users\yugahang\Anaconda3\lib\site-packages\setuptools\command\install.py", line 109, in do_egg_install
        self.run_command('bdist_egg')
      File "C:\Users\yugahang\Anaconda3\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\Users\yugahang\Anaconda3\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\yugahang\Anaconda3\lib\site-packages\setuptools\command\bdist_egg.py", line 172, in run
        cmd = self.call_command('install_lib', warn_dir=0)
      File "C:\Users\yugahang\Anaconda3\lib\site-packages\setuptools\command\bdist_egg.py", line 158, in call_command
        self.run_command(cmdname)
      File "C:\Users\yugahang\Anaconda3\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\Users\yugahang\Anaconda3\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\yugahang\Anaconda3\lib\site-packages\setuptools\command\install_lib.py", line 11, in run
        self.build()
      File "C:\Users\yugahang\Anaconda3\lib\distutils\command\install_lib.py", line 107, in build
        self.run_command('build_ext')`
      File "C:\Users\yugahang\Anaconda3\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\Users\yugahang\Anaconda3\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "setup.py", line 135, in run`enter code here`
        self.build_extension(ext)
      File "setup.py", line 172, in build_extension
        subprocess.check_call(cmake_setup, cwd=build_folder)
      File "C:\Users\yugahang\Anaconda3\lib\subprocess.py", line 363, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\yugahang\\anaconda3\\Lib\\site-packages\\dlib-master\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\yugahang\\anaconda3\\Lib\\site-packages\\dlib-master\\build\\lib.win-amd64-3.7', '-DPYTHON_EXECUTABLE=C:\\Users\\yugahang\\Anaconda3\\python.exe', '-DUSE_AVX_INSTRUCTIONS', '-DDLIB_USE_CUDA', '-`enter code here`DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\yugahang\\anaconda3\\Lib\\site-packages\\dlib-master\\build\\lib.win-amd64-3.7', '-A', 'x64']' returned non-zero exit status 1.

有什么办法可以解决这个问题。首先我想知道是什么导致了这个问题。

【问题讨论】:

这些选项默认启用。 dlib.net/compile.html。我最近在 master 上运行了python setup.py install,cuda 已自动启用。 【参考方案1】:

setup.py 的参数 --set 应该是形式

--set <variable>=<value>

这将转换为 cmake 参数为 -D&lt;variable&gt;=&lt;value&gt; 完全适合 cmake synopsis。

例如而不是

--set USE_AVX_INSTRUCTIONS

使用

--set USE_AVX_INSTRUCTIONS=ON

setup.py 的参数 --no 没有赋值 (=&lt;value&gt;) 部分,因为

--no <variable>

自动翻译成cmake参数-D&lt;variable&gt;=no

【讨论】:

以上是关于使用 GPU 支持安装 dlib 时出错的主要内容,如果未能解决你的问题,请参考以下文章

Dlib(支持 GPU)不能正常工作,不确定?

如何检查 dlib 是不是正在使用 GPU?

当我尝试使用 pip 安装 Dlib 时出错。苹果系统

dlib 不使用 CUDA

使用 Windows 10 在 Python 3.5 上安装 dlib 时出错

使用 pip 安装 Dlib 时出错