【caffe-Windows7】caffe+VS2013+Windows7无GPU配置教程

    xiaoxiao2021-03-25  19

    本文是博主参考网上多个配置教程,最终成功配置所涉及到的详细步骤,希望你用这个教程也能顺利的完成配置。

    配置过程参考资料:

    http://blog.csdn.net/guoyk1990/article/details/52909864

    http://blog.csdn.net/zb1165048017/article/details/51355143

    https://www.zhihu.com/question/56111727

    第一步 caffe-windows准备

    (1)下载官方caffe-windows并解压,将 .\windows\CommonSettings.props.example备份,并改名为CommonSettings.props。如图4所示:

    图 4:修改后的CommonSettings.props文件

    (2)关于CommonSettings.props文件的一点说明

    [html]  view plain  copy   </pre><pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>   <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">       <ImportGroup Label="PropertySheets" />       <PropertyGroup Label="UserMacros">           <BuildDir>$(SolutionDir)..\Build</BuildDir>           <!--NOTE: CpuOnlyBuild and UseCuDNN flags can't be set at the same time.-->           <CpuOnlyBuild>false</CpuOnlyBuild><!--注释里说的很清楚,这两个值不能同时设为true。若没有GPU就把CpuOnlyBuild设为true-->           <UseCuDNN>true</UseCuDNN>           <CudaVersion>7.5</CudaVersion>           <!-- NOTE: If Python support is enabled, PythonDir (below) needs to be            set to the root of your Python installation. If your Python installation            does not contain debug libraries, debug build will not work. -->           <PythonSupport>false</PythonSupport><!--设置是否支持python接口,若想支持,需要改后面的PythonDir的值-->       <!-- NOTE: If Matlab support is enabled, MatlabDir (below) needs to be            set to the root of your Matlab installation. -->           <MatlabSupport>false</MatlabSupport><!--设置是否支持matlab接口,若想支持,需要改后面的MatlabDir的值-->           <CudaDependencies></CudaDependencies>              <!-- Set CUDA architecture suitable for your GPU.            Setting proper architecture is important to mimize your run and compile time. -->           <CudaArchitecture>compute_35,sm_35;compute_52,sm_52</CudaArchitecture>              <!-- CuDNN 3 and 4 are supported -->           <CuDnnPath></CuDnnPath>           <ScriptsDir>$(SolutionDir)\scripts</ScriptsDir>       </PropertyGroup>       <PropertyGroup Condition="'$(CpuOnlyBuild)'=='false'">           <CudaDependencies>cublas.lib;cuda.lib;curand.lib;cudart.lib</CudaDependencies>       </PropertyGroup>          <PropertyGroup Condition="'$(UseCuDNN)'=='true'">           <CudaDependencies>cudnn.lib;$(CudaDependencies)</CudaDependencies>       </PropertyGroup>       <PropertyGroup Condition="'$(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>       <PropertyGroup Condition="'$(PythonSupport)'=='true'"><!--与前面python接口设置对应-->           <PythonDir>C:\Miniconda2\</PythonDir>           <LibraryPath>$(PythonDir)\libs;$(LibraryPath)</LibraryPath>           <IncludePath>$(PythonDir)\include;$(IncludePath)</IncludePath>       </PropertyGroup>       <PropertyGroup Condition="'$(MatlabSupport)'=='true'"><!--与前面的matlab接口设置对应-->           <MatlabDir>C:\Program Files\MATLAB\R2014b</MatlabDir>           <LibraryPath>$(MatlabDir)\extern\lib\win64\microsoft;$(LibraryPath)</LibraryPath>           <IncludePath>$(MatlabDir)\extern\include;$(IncludePath)</IncludePath>       </PropertyGroup>       <ItemDefinitionGroup Condition="'$(CpuOnlyBuild)'=='true'">           <ClCompile>               <PreprocessorDefinitions>CPU_ONLY;%(PreprocessorDefinitions)</PreprocessorDefinitions>           </ClCompile>       </ItemDefinitionGroup>       <ItemDefinitionGroup Condition="'$(UseCuDNN)'=='true'">           <ClCompile>               <PreprocessorDefinitions>USE_CUDNN;%(PreprocessorDefinitions)</PreprocessorDefinitions>           </ClCompile>           <CudaCompile>               <Defines>USE_CUDNN</Defines>           </CudaCompile>       </ItemDefinitionGroup>       <ItemDefinitionGroup Condition="'$(PythonSupport)'=='true'">           <ClCompile>               <PreprocessorDefinitions>WITH_PYTHON_LAYER;BOOST_PYTHON_STATIC_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>           </ClCompile>       </ItemDefinitionGroup>       <ItemDefinitionGroup Condition="'$(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>       <ItemDefinitionGroup Condition="'$(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>       <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">           <ClCompile>               <Optimization>Disabled</Optimization>               <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>               <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>           </ClCompile>           <Link>               <GenerateDebugInformation>true</GenerateDebugInformation>           </Link>       </ItemDefinitionGroup>   </Project>  

    第二步 编译caffe-windows

    编译用vs2013打开.\windows\Caffe.sln 并将解决方案的配置改为release,点菜单栏上的“生成->生成解决方案”,会将整个项目全部生成,这个时间会比较长(大概40分钟)。这个等待超长的过程其实是在下载NugetPackages,你可以在caffe-windows文件夹所在路径中找到NugetPackages文件夹,下载的过程是在NugetPackages文件夹下下载了16个文件,16个文件全部下载完成,就自动进入生成的过程

    当下载完毕,VS仍在继续执行生成任务,最终可能失败,原因下面会提示说无法打开libcaffe.lib之类的error。解决方法是直接对libcaffe重新生成,或者直接生成一次。

    当这个文件生成成功以后,重复一下上一步,对所有文件再重新生成一下,这时候应该不会出现libcaffe.lib无法打开的错误了。

    重新生成libcaffe时,也可能会有报错:error C1083: 无法打开源文件: “..\..\src\caffe\data_reader.cpp”: No such file or directory

    这是因为官方删掉data_reader.cpp这个文件,将libcaffe.vcxproj和libcaffe.vcxproj.filters中的 data_reader.cpp 与 data_reader.hpp删掉后就不报错了。

    生成成功之后的文件都在.\Build\x64\Release中。

    第三步 设置一下运行项

    解决方案'caffe'->属性

    或者下面直接单启动项目是caffe也行,不过最好改一下,原因相信玩过VS的都清楚,如果是单启动项目,那么在你重新编译工程的时候,只会运行次单启动项目,其它项目不会运行,这就是为什么很多人编译以后发现Release或者Debug文件夹下只有caffe.exe而没有conver_imageset.exe等可执行文件的原因。

    第四步 运行caffe.cpp

    直接双击打开caffe.cpp,然后ctrl+f5直接编译,出现如下命令窗口说明编译成功

    【PS】这个其实告诉你了如何调用caffe.exe去训练你的模型

    转载请注明原文地址: https://ju.6miu.com/read-50186.html

    最新回复(0)