您的位置:首页 > Web前端

Windows 10 + VS2013 编译 Caffe

2016-08-18 12:06 549 查看

Prerequisites

NVidia Geforece 840M (any CUDA supported cards)

Windows 10 Home

Matlab (optional, R2012b)

Anaconda python (optional, python 2.7)

Git

Pre-installs

cuda_7.5.18_win10.exe

cudnn-7.0-win-x64-v4.0-prod.zip

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

Compile
libcaffe
first

Compile
caffe
next

Build Solution or compile the rest.

Troubleshooting

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>


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)


PyObject


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


References

http://blog.csdn.net/tina_ttl/article/details/51722983

https://github.com/BVLC/caffe/issues/489
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: