Windows 10 + VS2013 编译 Caffe

本文档详细介绍了在Windows 10系统中使用Visual Studio 2013编译Caffe的步骤,包括必要的前提条件、预安装软件、克隆源代码、依赖库的安装,以及解决常见问题的方法。重点关注CUDA 7.5.18、cuDNN 4.0的安装,以及Boost、OpenCV等依赖包的自动获取。同时,提供了设置Anaconda路径和解决编译警告的建议。
摘要由CSDN通过智能技术生成

Prerequisites

  • NVidia Geforece 840M (any CUDA supported cards)
  • Windows 10 Home
  • Matlab (optional, R2012b)
  • Anaconda python (optional, python 2.7)
  • Git

Pre-installs

Note: Caffe doesn’t support cudnn v5.0 yet, install v4.0 instead, otherwise you will get complaints.

Clone

By default, git clone fetches all the branches on the remote repository, so first clone the sources, and switch to the branch windows.

git clone https://github.com/BVLC/caffe.git
git branch -a #check all the branches
git checkout windows

Dependencies

The following dependency packages will be automatically fetched from Internet by NuGet when you start build the project.

  • LevelDB-vc120.1.2.0.0
  • boost_thread-vc120.1.59.0.0
  • OpenBLAS.0.2.14.1
  • gflags.2.1.2.1
  • OpenCV.2.4.10
  • glog.0.3.3.0
  • boost.1.59.0.0
  • hdf5-v120-complete.1.8.15.2
  • boost_chrono-vc120.1.59.0.0
  • lmdb-v120-clean.0.9.14.0
  • boost_date_time-vc120.1.59.0.0
  • protobuf-v120.2.6.1
  • boost_filesystem-vc120.1.59.0.0
  • protoc_x64.2.6.1
  • boost_python2.7-vc120.1.59.0.0
  • repositories.config
  • boost_system-vc120.1.59.0.0

After downloading is complete, check these packages here, right-click the project, Manage NuGet Packages.

Configs

My CommonSettings.props is as follows, the differences from the

<?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>
        <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>true</PythonSupport>
        <!-- NOTE: If Matlab support is enabled, MatlabDir (below) needs to be
         set to the root of your Matlab installation. -->
        <MatlabSupport>true</MatlabSupport>
        <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'">
        <PythonDir>C:\Program Files\Anaconda</PythonDir>
        <LibraryPath>$(PythonDir)\libs;$(LibraryPath)</LibraryPath>
        <IncludePath>$(PythonDir)\include;$(IncludePath)</IncludePath>
    </PropertyGroup>
    <PropertyGroup Condition="'$(MatlabSupport)'=='true'">
        <MatlabDir>C:\Program Files\MATLAB\R2012b</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>

Compilation

  1. Compile libcaffe first
  2. Compile caffe next
  3. Build Solution or compile the rest.

Troubleshooting

  1. pyconfig.h: No such file or directory

    Set Anaconda path in CommonSettings.prop

    <PropertyGroup Condition="'$(PythonSupport)'=='true'">
        <PythonDir>C:\Program Files\Anaconda</PythonDir>
        <LibraryPath>$(PythonDir)\libs;$(LibraryPath)</LibraryPath>
  2. The builds tools for v140 (Platform Toolset = 'v140') cannot be found

    It might be caused by building caffe with vs2015 first, change it here,
    Configuration Properties > General > Platform Toolset > Visual Studio 2013 (v120)

  3. PyObject

    Set False to “Treat Warnings As Errors”, it is here Configuration Properties > C/C++ > General > Treat Warnings As Errors

References

  1. http://blog.csdn.net/tina_ttl/article/details/51722983
  2. https://github.com/BVLC/caffe/issues/489
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值