安装windows 版caffe 的一点经验

来源:互联网 发布:网络架空地板价格 编辑:程序博客网 时间:2024/05/16 10:05

安装windows 版caffe 的一点经验

(MATLAB操作caffe框架)

安装之前先谈谈我的电脑硬件配置:Qudra K600 的GPU(计算能力是3.0)。你在安装之前也要搞清楚自己的GPU显卡是什么,看看到底支持不支持CUDA;如果支持,要查查计算能力是多少,后面配置参数要用到。(注:电脑没有GPU也可以运行caffe框架)

         以下从操作系统的选择开始告诉你如果编译和通过MATLAB运行caffe框架:

1.   选择操作系统

选择对应操作系统;因为我的GPU不是最好的,所以没有选择win10。

2.   下载安装软件

l  操作系统的下载地址
 http://bt.byr.cn/


 https://yunpan.cn/cqDxCB5ALqZMn  访问密码 cc57

 

l  caffe的下载地址

 

Windows 下的caffe的下载地址https://github.com/Microsoft/caffe (请保存此网站在收藏夹,以后要多次用到,这个是微软官方出的最好编译的)

 

以下软件的下载是根据 下载caffe的压缩包中的README.md选择,请详细阅读。

 

 

l visualstudio 的下载地址

     http://bt.byr.cn/  (README.md中的vs是2013版,所以你要下载2013版。)

https://yunpan.cn/ckzyKngfMGVFC  访问密码 9f45

 

l CUDA的下载地址

     https://developer.nvidia.com/cuda-downloads(根据自己的操作系统版本来选择,如果不会选择,那你不用学习Caffe了!

 

    注:CUDA的安装一定在visual studio的安装完成之后(要听话!);

    注:如果电脑没有GPU,省去此步。

                      

l cuDNN的下载地址

https://developer.nvidia.com/cudnn

l Miniconda2-latest-Windows-x86_64的下载地址

http://conda.pydata.org/miniconda.html

l PTVS2.2 VS 2013的下载地址

https://github.com/Microsoft/PTVS/releases/v2.2.2  

上面的软件在我网盘里(根据自己的实际需要选择下载)

链接:http://pan.baidu.com/s/1qYja3Pq密码:w255

3.   安装软件

软件的安装按照以下次序进行:

 

 

4.   参数配置

以下操作在caffe解压的文件加下进行:

Step1:将caffe-master\windows文件夹下的CommonSettings.props.example文件在同一位置复制保存一份,并且去掉后缀.example。(CommonSettings.props文件是vs2013的参数配置文件,参数配置工作全部在此处进行。)

 

Step2: 双击运行caffe-master\windows文件夹下的Caffe.sln工程文件,启动caffe的编译工作。打开后的项目文件如下图所示:

 

Step3:打开props文件下的CommonSettings.props文件,开始配置参数,具体可参考README.md文件。

 

1文件中的<CudaArchitecture>compute_30,sm_30;compute_35,sm_35; </CudaArchitecture>的配置是根据GPU的计算能力设置的。我的K600计算能力是3.0的所以开始设置了compute_30,sm_30;如果是4.0的计算能力,则设置为compute_40,sm_40;具体设置要在网上根据自己的GPU型号进行查找。如果配置不正确,在用MATLAB编程的时候,MATLAB会崩溃。

 

2附件中将放上我的配置文件内容,其中我的CuDnn文件解压以后也放在了MATLAB的安装目录下了,所以<CuDnnPath>$(MatlabDir)</CuDnnPath>。

 

Step4: 设置matcaffe为启动项目。

 

Step5: 修改matcaffe项目内的caffe.cpp文件内容,如下图所示。

       将第20行的代码

#define MEX_ARGSint nlhs, mxArray **plhs,int nrhs,const mxArray **prhs

替换为

#define MEX_ARGSint nlhs, mxArray *plhs[],int nrhs,const mxArray *prhs[]

 

 

 

 

Step6:右键“生成”项目,在输出中查看是否编译成功。如果编译成功,则在caffe-master\Build\x64\Debug文件夹下得到MATLAB调用的接口。

 

注:此时已经得到了MATLAB和C++项目运行Caffe所需要的.dll 、.lib、.mex文件了。

 

5.   运行MATLAB实例

在caffe-master\matlab文件下存放着可以运行的MATLAB调用caffe的例子,但是需要将caffe-master\Build\x64\Debug\matcaffe\+caffe文件夹下的内容,复制替换到caffe-master\matlab\+caffe文件下的内容。

         同时还需要将生成的所有.dll文件(caffe-master\Build\x64\Debug下存放)放在caffe-master\matlab\+caffe\private文件夹下。

    最后可以matlab运行caffe-master\matlab\demo\classification_demo.m文件测试。

 

 

 

注:运行前需要从http://dl.caffe.berkeleyvision.org/网站上下载模型。

 

 

 

 

 

 

 

 

 

附件

CommonSettings.props内容:

<?xmlversion="1.0"encoding="utf-8"?>

<ProjectToolsVersion="4.0"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <ImportGroupLabel="PropertySheets" />

    <PropertyGroupLabel="UserMacros">

        <BuildDir>$(SolutionDir)..\Build</BuildDir>

        <!--NOTE:CpuOnlyBuild and UseCuDNN flags can't be set at the same time.-->

        <CpuOnlyBuild>false</CpuOnlyBuild>

        <UseCuDNN>true</UseCuDNN>

        <CudaVersion>7.5</CudaVersion>

        <!--NOTE: If Python support is enabled, PythonDir (below) needs to be

         set to the root of your Pythoninstallation. If your Python installation

         does not contain debug libraries,debug build will not work.-->

        <PythonSupport>false</PythonSupport>

        <!--NOTE: If Matlab support is enabled, MatlabDir (below) needs to be

         set to the root of your Matlabinstallation.-->

        <MatlabSupport>true</MatlabSupport>

        <CudaDependencies>C:\ProgramFiles\MATLAB\R2015b</CudaDependencies>

 

        <!-- SetCUDA architecture suitable for your GPU.

         Setting proper architecture isimportant to mimize your run and compile time.-->

       <CudaArchitecture>compute_30,sm_30;compute_35,sm_35;</CudaArchitecture>

 

        <!--CuDNN 3 and 4 are supported-->

        <CuDnnPath>$(MatlabDir)</CuDnnPath>

        <ScriptsDir>$(SolutionDir)\scripts</ScriptsDir>

    </PropertyGroup>

    <PropertyGroupCondition="'$(CpuOnlyBuild)'=='false'">

        <CudaDependencies>cublas.lib;cuda.lib;curand.lib;cudart.lib</CudaDependencies>

    </PropertyGroup>

 

    <PropertyGroupCondition="'$(UseCuDNN)'=='true'">

        <CudaDependencies>cudnn.lib;$(CudaDependencies)</CudaDependencies>

    </PropertyGroup>

    <PropertyGroupCondition="'$(UseCuDNN)'=='true' And $(CuDnnPath)!=''">

        <LibraryPath>$(CuDnnPath)\cuda\lib\x64;$(LibraryPath)</LibraryPath>

        <IncludePath>$(CuDnnPath)\cuda\include;$(IncludePath)</IncludePath>

    </PropertyGroup>

 

    <PropertyGroup>

        <OutDir>$(BuildDir)\$(Platform)\$(Configuration)\</OutDir>

        <IntDir>$(BuildDir)\Int\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>

    </PropertyGroup>

    <PropertyGroup>

        <LibraryPath>$(OutDir);$(CUDA_PATH)\lib\$(Platform);$(LibraryPath)</LibraryPath>

        <IncludePath>$(SolutionDir)..\include;$(SolutionDir)..\include\caffe\proto;$(CUDA_PATH)\include;$(IncludePath)</IncludePath>

    </PropertyGroup>

    <PropertyGroupCondition="'$(PythonSupport)'=='true'">

        <PythonDir>C:\Miniconda2\</PythonDir>

        <LibraryPath>$(PythonDir)\libs;$(LibraryPath)</LibraryPath>

        <IncludePath>$(PythonDir)\include;$(IncludePath)</IncludePath>

    </PropertyGroup>

    <PropertyGroupCondition="'$(MatlabSupport)'=='true'">

        <MatlabDir>C:\ProgramFiles\MATLAB\R2015b</MatlabDir>

        <LibraryPath>$(MatlabDir)\extern\lib\win64\microsoft;$(LibraryPath)</LibraryPath>

        <IncludePath>$(MatlabDir)\extern\include;$(IncludePath)</IncludePath>

    </PropertyGroup>

    <ItemDefinitionGroupCondition="'$(CpuOnlyBuild)'=='true'">

        <ClCompile>

            <PreprocessorDefinitions>CPU_ONLY;%(PreprocessorDefinitions)</PreprocessorDefinitions>

        </ClCompile>

    </ItemDefinitionGroup>

    <ItemDefinitionGroupCondition="'$(UseCuDNN)'=='true'">

        <ClCompile>

            <PreprocessorDefinitions>USE_CUDNN;%(PreprocessorDefinitions)</PreprocessorDefinitions>

        </ClCompile>

        <CudaCompile>

            <Defines>USE_CUDNN</Defines>

        </CudaCompile>

    </ItemDefinitionGroup>

    <ItemDefinitionGroupCondition="'$(PythonSupport)'=='true'">

        <ClCompile>

            <PreprocessorDefinitions>WITH_PYTHON_LAYER;BOOST_PYTHON_STATIC_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>

        </ClCompile>

    </ItemDefinitionGroup>

    <ItemDefinitionGroupCondition="'$(MatlabSupport)'=='true'">

        <ClCompile>

            <PreprocessorDefinitions>MATLAB_MEX_FILE;%(PreprocessorDefinitions)</PreprocessorDefinitions>

        </ClCompile>

    </ItemDefinitionGroup>

    <ItemDefinitionGroup>

        <ClCompile>

            <MinimalRebuild>false</MinimalRebuild>

            <MultiProcessorCompilation>true</MultiProcessorCompilation>

            <PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;USE_OPENCV;USE_LEVELDB;USE_LMDB;%(PreprocessorDefinitions)</PreprocessorDefinitions>

            <TreatWarningAsError>true</TreatWarningAsError>

        </ClCompile>

    </ItemDefinitionGroup>

    <ItemDefinitionGroupCondition="'$(Configuration)|$(Platform)'=='Release|x64'">

        <ClCompile>

            <Optimization>Full</Optimization>

            <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>

            <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>

            <FunctionLevelLinking>true</FunctionLevelLinking>

        </ClCompile>

        <Link>

            <EnableCOMDATFolding>true</EnableCOMDATFolding>

            <GenerateDebugInformation>true</GenerateDebugInformation>

            <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>

            <OptimizeReferences>true</OptimizeReferences>

        </Link>

    </ItemDefinitionGroup>

    <ItemDefinitionGroupCondition="'$(Configuration)|$(Platform)'=='Debug|x64'">

        <ClCompile>

            <Optimization>Disabled</Optimization>

            <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>

            <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>

        </ClCompile>

        <Link>

            <GenerateDebugInformation>true</GenerateDebugInformation>

        </Link>

    </ItemDefinitionGroup>

</Project>

 

0 0
原创粉丝点击