dlib-19.8+vs2015+cuda9.1+cmake在windows10配置經驗


    本文基於dlib-19.8+ vs2015 + cuda9.1 + cudnn7.0.5 + cmake在windows10配置,使用GPU大大加快了DNN網絡的訓練速度,顯卡是GTX1060。本文也參考了網上很多博客,在這里就不一一列出了。在配置dlib的過程中用過vs2013,vs2015,vs2017,最終還是回到了vs2015,主要還是為了運行DNN相關的代碼,因為官網有如下說明:


http://dlib.net/faq.html#WhycantIusetheDNNmodulewithVisualStudio


Why can't I use the DNN module with Visual Studio?


You can, but you need to use VisualStudio 2015 Update 3 or newer since prior versions had bad C++11 support.To make this as confusing as possible, Microsoft has released multipledifferent versions of "Visual Studio 2015 Update 3". As of October2016, the version available from the Microsoft web page has good enough C++11support to compile the DNN tools in dlib. So make sure you have a version noolder than October 2016.


However, as of this writing, the newest version of Visual Studio isVisual Studio 2017, which has WORSE C++11support that Visual Studio 2015. In particular, if you try to use the DNNtooling in Visual Studio 2017 the compiler will just hang. So use Visual Studio2015.


It should also be noted that not even Visual Studio 2015 has perfectC++11 support. Specifically, the larger and more complex imagenet and metriclearning training examples don't compile in Visual Studio 2015.



 具體步驟如下:



1.   下載dlib-19.8源碼,截止目前最新版本已經是dlib-19.9。



2.   下載cmake。我下載的是cmake-3.10.2-win64-x64.zip,解壓后運行bin/cmake-gui.exe即可。




3.   下載安裝cuda9.1




4.   下載與cuda對應版本的cudnn。解壓后為cuda文件夾。將cuda/bin和cuda/lib/x64以及cuda/include添加到環境變量Path中。




5.   將下載的dlib壓縮包解壓,我這里是‪G:\dlib-19.8。




6.   運行cmake-gui.exe。添加source code目錄G:/dlib-19.8/dlib,生成目錄G:/dlib-19.8/build。






點擊左下角configure。框中顯示如下:


The C compiler identification is MSVC 19.0.24210.0

The CXX compiler identification is MSVC 19.0.24210.0

Check for working C compiler: C:/Program Files (x86)/Microsoft VisualStudio 14.0/VC/bin/x86_amd64/cl.exe

Check for working C compiler: C:/Program Files (x86)/Microsoft VisualStudio 14.0/VC/bin/x86_amd64/cl.exe -- works

Detecting C compiler ABI info

Detecting C compiler ABI info - done

Check for working CXX compiler: C:/Program Files (x86)/MicrosoftVisual Studio 14.0/VC/bin/x86_amd64/cl.exe

Check for working CXX compiler: C:/Program Files (x86)/MicrosoftVisual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works

Detecting CXX compiler ABI info

Detecting CXX compiler ABI info - done

Detecting CXX compile features

Detecting CXX compile features - done

Looking for sys/types.h

Looking for sys/types.h - found

Looking for stdint.h

Looking for stdint.h - found

Looking for stddef.h

Looking for stddef.h - found

Check size of void*

Check size of void* - done

Enabling SSE2 instructions

Searching for BLAS and LAPACK

Searching for BLAS and LAPACK

Looking for pthread.h

Looking for pthread.h - not found

Found Threads: TRUE

A library with BLAS API not found. Please specify library location.

LAPACK requires BLAS

Found CUDA:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.1 (found suitable version"9.1", minimum required is "7.5")

Looking for cuDNN install...

Found cuDNN:G:/Deeplearning/cuda/lib/x64/cudnn.lib

Building a CUDA test project to see if your compiler is compatiblewith CUDA...

Checking if you have the right version of cuDNN installed.

Enabling CUDA support for dlib. DLIB WILL USE CUDA


表明CUDA可用。



    下圖中的第一項CMAKE_INSTALL_PREFIX,是lib和include文件生成路徑,在這里將C盤路徑改為了E盤,原因是編譯時可能需要管理員權限而失敗。下圖中的最后一項DLIB_USE_CUDA,確保打上鈎。如果不使用GPU,就將鈎子去掉。





7.   點擊左下角Generate,然后點擊Open project打開解決方案。將配置和平台改為Release和×64,右鍵項目INSTALL生成。






生成完畢后,在第六步設置的目錄得到include和lib文件夾。






8.   新建一個C++控制台空項目,添加一個例程cpp,這里加入的是dnn_metric_learning_on_images.cpp,訓練人臉識別網絡。同樣將配置和平台改為Release和×64。





9.   右鍵項目-屬性,包含目錄和庫目錄設置為第七步生成的include和lib文件夾。






10. 設置附加依賴項,加入


dlib.lib

C:\Program Files\NVIDIA GPU ComputingToolkit\CUDA\v9.1\lib\x64\cudart_static.lib

C:\Program Files\NVIDIA GPU ComputingToolkit\CUDA\v9.1\lib\x64\cublas.lib

C:\Program Files\NVIDIA GPU ComputingToolkit\CUDA\v9.1\lib\x64\cublas_device.lib

C:\Program Files\NVIDIA GPU ComputingToolkit\CUDA\v9.1\lib\x64\curand.lib

C:\Program Files\NVIDIA GPU ComputingToolkit\CUDA\v9.1\lib\x64\cusolver.lib

G:\Deeplearning\cuda\lib\x64\cudnn.lib


依自己的cuda和cudnn目錄修改


 



11. 在調試中加入命令參數,為訓練圖片的文件夾。然后開始執行。







訓練速度非常快,用CPU訓練幾十個小時的過程在GPU只需幾分鍾!!  !


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com