日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

winsows10下用ninja编译配置caffe

發(fā)布時(shí)間:2024/9/21 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 winsows10下用ninja编译配置caffe 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

出于好奇自己想在windows上配置一下caffe環(huán)境,于是在網(wǎng)上找了一些教程。發(fā)現(xiàn)都和caffe官網(wǎng)上的說法有些不同,于是抱著作死的心態(tài)去按照官網(wǎng)上的做法走了一遍。自己也是新手,還有許多不明白的地方,隨手mark一下。

參考:https://github.com/BVLC/caffe/tree/windows

Requirements


  • Visual Studio 2013 or 2015
  • CMake?3.4 or higher (Visual Studio and?Ninja?generators are supported)

Optional Dependencies

  • Python for the pycaffe interface. Anaconda Python 2.7 or 3.5 x64 (or Miniconda)
  • Matlab for the matcaffe interface.
  • CUDA 7.5 or 8.0 (use CUDA 8 if using Visual Studio 2015)
  • cuDNN v5

We assume that?cmake.exe?and?python.exe?are on your?PATH.

這是官網(wǎng)上的說明。

1.首先就是安裝vs2015,這個(gè)就不必細(xì)說。

2.安裝anaconda和一些必要的包:

https://www.continuum.io/downloads/? ?這是下載地址,下載之后雙擊安裝程序逐步安裝,記得勾選添加anaconda至環(huán)境變量這個(gè)選項(xiàng),因?yàn)閍naconda自帶python,我下載的是python2.7版本的。安裝了anaconda之后無需再安裝python了。它的方便之處就是自己帶了很多python的庫還有spyder這個(gè)類似matlab的python集成開發(fā)環(huán)境。

然后就可打開cmd運(yùn)行:

conda install --yes numpy scipy matplotlib scikit-image pip six conda install --yes --channel willyd protobuf==3.1.0 這主要是為了在python下使用caffe安裝的依賴包。


3.安裝cuda8.0以及cuDnn v5.1:

如果想使用GPU加速,則需要安裝CUDA及cuDNN,這里如果你是nvidia的顯卡且cuda的計(jì)算能力評(píng)分在3.0及以上可以考慮安裝cuda:

https://developer.nvidia.com/cuda-downloads

評(píng)分詳見:https://developer.nvidia.com/cuda-gpus

下載cuda驅(qū)動(dòng)之后雙擊安裝,選擇自定義,安裝cuda套件,我并沒有選擇更新顯卡驅(qū)動(dòng)和安裝experience。詳情參考了博文:

http://blog.csdn.net/tina_ttl/article/details/51388242

這里注意安裝的過程中有個(gè)添加path環(huán)境變量的選項(xiàng)要選擇,安裝完成后就不用配置自己的path環(huán)境變量了。

安裝完cuda后緊接著安裝cuDNN v5.1.

安裝cuDnn就是下載文件并拷貝文件到CUDA的相關(guān)目錄里面。

下載cuDNN:https://developer.nvidia.com/rdp/form/cudnn-download-survey? ? ? 這個(gè)要注冊(cè)之后才能下載,下載后解壓,會(huì)出現(xiàn)一個(gè)名為cuda的文件夾,下面有三個(gè)子文件夾:bin,include,lib ? ?分別把這三個(gè)子文件夾里面的內(nèi)容拷貝至CUDA安裝目錄下對(duì)應(yīng)的bin,include,lib ? 文件夾下面,例如我的是C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0

4.安裝CMAKE3.4以及ninja

安裝cmake3.4,直接去官網(wǎng)https://cmake.org/download/上下載對(duì)應(yīng)的.msi文件安裝即可。注意將cmake添加到path環(huán)境變量。

安裝ninja,到https://github.com/ninja-build/ninja/releases上面去下載ninja-win.zip以及source code(zip),分別解壓得到ninja.exe,和一個(gè)ninja-1.7.2的文件夾,將ninja.exe復(fù)制到ninja-1.7.2文件夾中,雙擊ninja.exe文件,會(huì)生成一個(gè)build文件夾(沒看懂),這時(shí)可以將ninja-1.7.2這個(gè)文件夾路徑(也就是你的ninja路徑)添加到你的path環(huán)境變量中,例如我的是:D:\Programs\Projects-caffe\ninja-1.7.2

這樣ninja就可以用了。

至于官網(wǎng)上的安裝方法:

> conda config --add channels conda-forge > conda install ninja --yes 我沒有試過,不過應(yīng)該是可以的。

5.編譯

至此,所有準(zhǔn)備工作完成,進(jìn)行編譯。我是編譯python環(huán)境下的caffe,有需要的話可以編譯matlab的caffe,可以自行修改caffe\scripts\build_win.cmd文件進(jìn)行編譯,當(dāng)然修改此文件可以使用vs2015編譯,官網(wǎng)的意思時(shí)使用ninja更快更強(qiáng)。

The fastest method to get started with caffe on Windows is by executing the following commands in a?cmd?prompt (we use?C:\Projects?as a root folder for the remainder of the instructions):

C:\Projects> git clone https://github.com/BVLC/caffe.git C:\Projects> cd caffe C:\Projects\caffe> git checkout windows :: Edit any of the options inside build_win.cmd to suit your needs C:\Projects\caffe> scripts\build_win.cmd

如需修改配置,使用記事本編輯build_win.cmd文件,修改的地方為else后的東西,如下圖:


編譯過程十分鐘左右,編譯完成后會(huì)在caffe目錄里生成build文件夾。

然后將caffe\python\caffe文件夾復(fù)制到path\to\Anaconda2\Lib\site-packages下(例如D:\Programs\Anaconda2\Lib\site-packages)。

?官網(wǎng)說法:In order to use the python interface you need to either add the?C:\Projects\caffe\python?folder to your python path of copy the?C:\Projects\caffe\python\caffe?folder to your?site_packages?folder.

也可以新建一個(gè)環(huán)境變量PYTHONPATH

變量值為path\to\caffe\python(例如:?C:\Projects\caffe\python)

6.測(cè)試

run cmd

C:\Users\ThomasZhao>python
Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 19 2016, 13:29:36) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import caffe
>>>

如果沒有報(bào)錯(cuò),說明caffe安裝成功。

補(bǔ)充:試著編譯了一下matlab的caffe

發(fā)現(xiàn)運(yùn)行caffe.run_tests()時(shí):

Using the MATLAB interface

Follow the above procedure and use?-DBUILD_matlab=ON. Change your current directory in MATLAB to?C:\Projects\caffe\matlab?and run the following command to run the tests:

>> caffe.run_tests()

出現(xiàn)了錯(cuò)誤:

Invalid MEX-file..........................................找不到指定模塊

解決方案,設(shè)置path環(huán)境變量:D:\Programs\Projects-caffe\caffe\build\install\bin

然后重啟matlab,再次運(yùn)行:

caffe.run_tests()
Cleared 0 solvers and 0 stand-alone nets
Running caffe.test.test_net
.....
Done caffe.test.test_net
__________


Unexpected Standard exception from MEX file.
What() is:CHECK failed: file != NULL:
..


Error in caffe.get_solver (line 7)
pSolver = caffe_('get_solver', solver_file);


Error in caffe.Solver (line 21)
? ? ? ? self = caffe.get_solver(varargin{:});


Error in caffe.test.test_solver (line 22)
? ? ? self.solver = caffe.Solver(solver_file);


Error in caffe.run_tests (line 12)
results = [...


今天又找了一下原因,發(fā)現(xiàn)應(yīng)該時(shí)編譯的時(shí)候選擇了參數(shù):

DBUILD_SHARED_LIBS=ON

而官網(wǎng)教程上的說法是

CMake can be used to build a shared library instead of the default static library. To do so follow the above procedure and use?-DBUILD_SHARED_LIBS=ON. Please note however, that some tests (more specifically the solver related tests) will fail since both the test exectuable and caffe library do not share static objects contained in the protobuf library.

  • Shared library (DLL) build will have failing tests.
這個(gè)意思就是使用上述參數(shù)的話射程shared library可能會(huì)是一些測(cè)試失敗。。。所以修改build_win.cmd文件使得DBUIL_SHARED_LIBS = 0,如下劃線部分:

?else (
? ? :: Change the settings here to match your setup
? ? :: Change MSVC_VERSION to 12 to use VS 2013
? ? if NOT DEFINED MSVC_VERSION set MSVC_VERSION=14
? ? :: Change to 1 to use Ninja generator (builds much faster)
? ? if NOT DEFINED WITH_NINJA set WITH_NINJA=1
? ? :: Change to 1 to build caffe without CUDA support
? ? if NOT DEFINED CPU_ONLY set CPU_ONLY=0
? ? :: Change to Debug to build Debug. This is only relevant for the Ninja generator the Visual Studio generator will generate both Debug and Release configs
? ? if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release
? ? :: Set to 1 to use NCCL
? ? if NOT DEFINED USE_NCCL set USE_NCCL=0
? ? :: Change to 1 to build a caffe.dll
? ? if NOT DEFINED CMAKE_BUILD_SHARED_LIBS set CMAKE_BUILD_SHARED_LIBS=0

然后再編譯,將caffe目錄下\build\install\bin復(fù)制到\matlab\+caffe\下(也可以將path\to\build\install\bin添加到PATH環(huán)境變量)

再打開matlab切換當(dāng)前路徑到caffe目錄下\matlab,

命令行輸入:caffe.run_tests():

>> caffe.run_tests()
Cleared 0 solvers and 0 stand-alone nets
Running caffe.test.test_net
.....
Done caffe.test.test_net
__________


Running caffe.test.test_solver
.
Done caffe.test.test_solver
__________


Running caffe.test.test_io
.
Done caffe.test.test_io
__________


Cleared 0 solvers and 0 stand-alone nets


ans =?


? 1x7 TestResult array with properties:


? ? Name
? ? Passed
? ? Failed
? ? Incomplete
? ? Duration


Totals:
? ?7 Passed, 0 Failed, 0 Incomplete.
? ?1.0383 seconds testing time.


>>?

測(cè)試成功!

總結(jié)

以上是生活随笔為你收集整理的winsows10下用ninja编译配置caffe的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。