win10+VS2015+pycaffe编译

这里的环境是WIN10+cuda v8 +cudnn v6 + opencv + pycharm+VS2015

使用的是GPU,我的GPU是titan 6G+内存16G

首先是caffe的文件以及第三方库的编译,这里提供一个已经编译好的的连接:


但是这个网址上的编译教程有漏洞,编译步骤我总结如下:


1.下载:https://github.com/happynear/caffe-windows

Requirements: Visual Studio 2015, CUDA 8.0, third party libraries: Baidu Yun or Google Drive. Please extract the archive into caffe-windows解压后的 ./windows/thirdparty/

2. add the folder ./windows/thirdparty/bins to the environment variable PATH.

3.拷贝一份.\windows\CommonSettings.props.example 到同级目录,然后把副本改名为CommonSettings.props,

By defaults Windows build requires CUDA and cuDNN libraries. Both can be disabled by adjusting build variables in .\windows\CommonSettings.props. Python support is disabled by default, but can be enabled via .\windows\CommonSettings.props as well.

<PythonDir>dir改为实际路径,include的父目录,比如:

<PythonDir>D:\Users\sbd01\Miniconda3\envs\python3.6\</PythonDir>

4. CUDA Download CUDA Toolkit 8.0 from nVidia website. If you don't have CUDA installed, you can experiment with CPU_ONLY build. In .\windows\CommonSettings.props set CpuOnlyBuild to true and set UseCuDNN & UseNCCL to false.

5. cuDNN Download cuDNN v5 from nVidia website. Unpack downloaded zip to %CUDA_PATH% (environment variable set by CUDA installer). Alternatively, you can unpack zip to any location and set CuDnnPath to point to this location in .\windows\CommonSettings.propsCuDnnPath defined in .\windows\CommonSettings.props. Also, you can disable cuDNN by setting UseCuDNN to false in the property file.

<CuDnnPath>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0</CuDnnPath>

6.Python

To build Caffe Python wrapper set PythonSupport to true in .\windows\CommonSettings.props. Download Miniconda 2.7 64-bit Windows installer [from Miniconda website] (http://conda.pydata.org/miniconda.html). Install for all users and add Python to PATH (through installer).

Run the following commands from elevated command prompt:

conda install --yes numpy scipy matplotlib scikit-image pip

pip install protobuf


7 vs2015打开 .\windows\Caffe.sln性中修改) ,编译选项改为Release

1.先编译生成libcaffe(静态库),

2.把caffe改为动态链接库.dll(项目属性中修改) ,再编译caffe,编译成功后,

编译生成目录:D:\soft\caffe\caffe-windows-ms\Build\x64\Release

3.选择pycaffe的属性,将配置属性下的VC++目录中的包含目录和库目录填上你python所在的include和libs

比如:

D:\Users\Administrator\Miniconda3\envs\python3.6\include
D:\Users\Administrator\Miniconda3\envs\python3.6\libs

链接器-输入中添加:cudnn.lib

4.把pycaffe作为单启动。注意需要在release x64位下编译。

再编译pycaffe,注意:编译pycaffe之前,把caffe改为动态链接库.dll(项目属性中修改) 

After you have built solution with Python support, in order to use it you have to either:

  • set PythonPath environment variable to point to <caffe_root>\Build\x64\Release\pycaffe, or
  • Matlab

    To build Caffe Matlab wrapper set MatlabSupport to true and MatlabDir to the root of your Matlab installation in .\windows\CommonSettings.props.

    Remark

    After you have built solution with Matlab support, in order to use it you have to add the ./matlab folder to Matlab search path.

    Build

    先生成libcaffe,再编译caffe

    Now, you should be able to build .\windows\Caffe.sln

  • copy folder <caffe_root>\Build\x64\Release\pycaffe\caffe under <python_root>\lib\site-packages.

把pycaffe作为单启动。注意需要在release x64位下编译。

如果没有这个的话,就将这个文件夹里python文件夹中的项目加入即可。如果没有python项目,就自己建一个,将python文件夹里的cpp文件加入就可以了。

3、

同时在LINKER的输入目录下的附加依赖库中加入cudnn的lib文件。

D:\Users\Administrator\Miniconda3\envs\python3\Lib

D:\Users\Administrator\Miniconda3\envs\python3\Lib\site-packages\numpy\core\include

3、开始编译即可。这里要注意一定要和caffe、caffelib在一个项目里编译,否则会报错。

4、编译成功后会在caffe\python\caffe下生成_caffe.pyd 是打不开的

5、配置python环境:需要几个额外库

Cython>=0.19.2
numpy>=1.7.1
scipy>=0.13.2
scikit-image>=0.9.3
matplotlib>=1.3.1
ipython>=3.0.0
h5py>=2.2.0
leveldb>=0.191
networkx>=1.8.1
nose>=1.3.0
pandas>=0.12.0
python-dateutil>=1.4,<2
protobuf>=2.5.0
python-gflags>=2.0
pyyaml>=3.10
Pillow>=2.3.0
six>=1.1.0

其中numpy要装MKL版本的,不然scipy装上了BLAS不能用

leveldb没有windows版本的,不过我找到了可以使用的办法。见这个博客:

https://github.com/happynear/py-leveldb-windows/

点击打开链接

如果有pip install 装不上的,可以上这个网站找 wheel文件安装就可以了

http://www.lfd.uci.edu/~gohlke/pythonlibs/

点击打开链接

6、最后把目录中python下的caffe文件夹复制到python27\Lib\site-packages就可以了。

比如:

D:\soft\caffe\caffe-windows-ms\Build\x64\Release\pycaffe\caffe

测试的时候只需要在控制台下输入import caffe 看能载入就知道成功了:)



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值