caffe在windows平台上的编译

来源:互联网 发布:耐玩的网络游戏知乎 编辑:程序博客网 时间:2024/04/20 04:02

接触caffe已经一年有余,一直在Ubuntu下使用。但Ubuntu对N卡驱动支持性不太好。安装Ubuntu系统时最好不要联网,系统安装好之后也y一定不能更新。否则容易出现无限登陆,导致无法进入系统。最近电脑自动更新,导致无法启动。Google各种解决方案都没用,无奈只能尝试windows下安装,好在现在windows下的安装教程比刚接触caffe那会儿多很多,编译起来也容易了许多。在此,推荐一个caffe学习博客@denny402

1. 配置环境

  1. vs2013+cuda8.0(不使用cudnn)+matlab2014a
  2. caffe下载微软最新的官方版本。微软的caffe版本采用NugetPackages进行库管理,会自动下载caffe编译时用到的库。

2. caffe编译

  1. 修改配置文件
    复制.\windows\CommonSettings.props.example到 .\windows\CommonSettings.props。将文件第7行true改为false,关闭cudnn支持
<UseCuDNN>false</UseCuDNN>

修改第8行为自己cuda的版本号,如:

<CudaVersion>8.0</CudaVersion>

修改第16行位true,打开MATLAB支持

<MatlabSupport>true</MatlabSupport>

修改21行显卡计算能力,可以在NVIDIA的官网上查询显卡计算能力。我的显卡是GT 630,计算能力为2.1,因此改为

<CudaArchitecture>compute_20,sm_21;compute_20,sm_21</CudaArchitecture>

将52-56改为

 <PropertyGroup Condition="'$(MatlabSupport)'=='true'">        <MatlabDir>D:\Program Files\MATLAB\R2014a(你的MATLAB安装路径)</MatlabDir>        <LibraryPath>$(MatlabDir)\extern\lib\win64\microsoft;$(LibraryPath)</LibraryPath>        <IncludePath>$(MatlabDir)\extern\include;$(MatlabDir)/toolbox/distcomp/gpu/extern/include(添加gpu头文件路径);$(IncludePath)</IncludePath></PropertyGroup>

如果需要编译Python借口,修改第13行为true

<PythonSupport>true</PythonSupport>

并下载miniconda,并将其添加到path环境变量中。安装相应的python库

conda install --yes numpy scipy matplotlib scikit-image pippip install protobuf

如果网速不好可能会导致安装失败,多执行几次。
然后修改配置文件47-51

<PropertyGroup Condition="'$(PythonSupport)'=='true'">        <PythonDir>D:\Miniconda2\(你的路径)</PythonDir>        <LibraryPath>$(PythonDir)\libs;$(LibraryPath)</LibraryPath>        <IncludePath>$(PythonDir)\include;$(IncludePath)</IncludePath>    </PropertyGroup>

2. 编译caffe

用vs2013打开./windows/Caffe.sln。设置为x64,release编译解决方案(可根据需要设置版本)。首先会下载依赖的库,下载完毕后会自动编译。

3. 设置环境变量

将$(caffe_dir)/Build/x64/Release加入到环境变量path中,注销或者重启系统使其生效。

4. 测试matlab接口

$(caffe_dir)/Build/x64/Release/matcaffe添加到matlab路径中,或者将$(caffe_dir)/Build/x64/Release/matcaffe/+caffe/private/caffe_.mexw64拷贝到$(caffe_dir)/matlab/+caffe/private中。打开matlab切换到$(caffe_dir)/matlab/demo目录,运行

I = imread('../../examples/images/fish-bike.jpg');classification_demo(I,1)

若运行成功,则编译成功。

5. 可能会遇到的问题

“mex.h”: No such file or directory 

配置文件中没有添加$(MatlabDir)/toolbox/distcomp/gpu/extern/include路径

matlab直接崩溃,调试之后发现

hObj.init_key == init_key判断不相等,并报invalid Net handler

这个错误很特别,好像是因为version函数和MATLAB自带的有冲突,主目录切换到$(caffe_root)/matlab/+caffe/private之后重新切换回来就没错了。

0 0
原创粉丝点击