本文大多转载自 http://blog.csdn.net/guoyk1990/article/details/52909864,加入部分自己实战心得。

1、环境:windows 7\VS2013

2、caffe-windows准备

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

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

附带说明,现在最新版的github已经更新,没有上述文件,根据大佬说法用cmake编译后能产生sln文件,笔者不才,并不会,这里提供百度云盘的老版本:

caffe提供Windows工具包(caffe-windows):https://github.com/BVLC/caffe/tree/windows   百度云下载地址:链接:http://pan.baidu.com/s/1bp1BFH1 密码:phf3

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

  1. </pre><pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>
  2. <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  3. <ImportGroup Label="PropertySheets" />
  4. <PropertyGroup Label="UserMacros">
  5. <BuildDir>$(SolutionDir)..\Build</BuildDir>
  6. <!--NOTE: CpuOnlyBuild and UseCuDNN flags can't be set at the same time.-->
  7. <CpuOnlyBuild>false</CpuOnlyBuild><!--注释里说的很清楚,这两个值不能同时设为true。若没有GPU就把CpuOnlyBuild设为true-->
  8. <UseCuDNN>true</UseCuDNN>
  9. <CudaVersion>7.5</CudaVersion>
  10. <!-- NOTE: If Python support is enabled, PythonDir (below) needs to be
  11. set to the root of your Python installation. If your Python installation
  12. does not contain debug libraries, debug build will not work. -->
  13. <PythonSupport>false</PythonSupport><!--设置是否支持python接口,若想支持,需要改后面的PythonDir的值-->
  14. <!-- NOTE: If Matlab support is enabled, MatlabDir (below) needs to be
  15. set to the root of your Matlab installation. -->
  16. <MatlabSupport>false</MatlabSupport><!--设置是否支持matlab接口,若想支持,需要改后面的MatlabDir的值-->
  17. <CudaDependencies></CudaDependencies>
  18. <!-- Set CUDA architecture suitable for your GPU.
  19. Setting proper architecture is important to mimize your run and compile time. -->
  20. <CudaArchitecture>compute_35,sm_35;compute_52,sm_52</CudaArchitecture>
  21. <!-- CuDNN 3 and 4 are supported -->
  22. <CuDnnPath></CuDnnPath>
  23. <ScriptsDir>$(SolutionDir)\scripts</ScriptsDir>
  24. </PropertyGroup>
  25. <PropertyGroup Condition="'$(CpuOnlyBuild)'=='false'">
  26. <CudaDependencies>cublas.lib;cuda.lib;curand.lib;cudart.lib</CudaDependencies>
  27. </PropertyGroup>
  28. <PropertyGroup Condition="'$(UseCuDNN)'=='true'">
  29. <CudaDependencies>cudnn.lib;$(CudaDependencies)</CudaDependencies>
  30. </PropertyGroup>
  31. <PropertyGroup Condition="'$(UseCuDNN)'=='true' And $(CuDnnPath)!=''">
  32. <LibraryPath>$(CuDnnPath)\cuda\lib\x64;$(LibraryPath)</LibraryPath>
  33. <IncludePath>$(CuDnnPath)\cuda\include;$(IncludePath)</IncludePath>
  34. </PropertyGroup>
  35. <PropertyGroup>
  36. <OutDir>$(BuildDir)\$(Platform)\$(Configuration)\</OutDir>
  37. <IntDir>$(BuildDir)\Int\$(ProjectName)\$(Platform)\$(Configuration)\</IntDir>
  38. </PropertyGroup>
  39. <PropertyGroup>
  40. <LibraryPath>$(OutDir);$(CUDA_PATH)\lib\$(Platform);$(LibraryPath)</LibraryPath>
  41. <IncludePath>$(SolutionDir)..\include;$(SolutionDir)..\include\caffe\proto;$(CUDA_PATH)\include;$(IncludePath)</IncludePath>
  42. </PropertyGroup>
  43. <PropertyGroup Condition="'$(PythonSupport)'=='true'"><!--与前面python接口设置对应-->
  44. <PythonDir>C:\Miniconda2\</PythonDir>
  45. <LibraryPath>$(PythonDir)\libs;$(LibraryPath)</LibraryPath>
  46. <IncludePath>$(PythonDir)\include;$(IncludePath)</IncludePath>
  47. </PropertyGroup>
  48. <PropertyGroup Condition="'$(MatlabSupport)'=='true'"><!--与前面的matlab接口设置对应-->
  49. <MatlabDir>C:\Program Files\MATLAB\R2014b</MatlabDir>
  50. <LibraryPath>$(MatlabDir)\extern\lib\win64\microsoft;$(LibraryPath)</LibraryPath>
  51. <IncludePath>$(MatlabDir)\extern\include;$(IncludePath)</IncludePath>
  52. </PropertyGroup>
  53. <ItemDefinitionGroup Condition="'$(CpuOnlyBuild)'=='true'">
  54. <ClCompile>
  55. <PreprocessorDefinitions>CPU_ONLY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  56. </ClCompile>
  57. </ItemDefinitionGroup>
  58. <ItemDefinitionGroup Condition="'$(UseCuDNN)'=='true'">
  59. <ClCompile>
  60. <PreprocessorDefinitions>USE_CUDNN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  61. </ClCompile>
  62. <CudaCompile>
  63. <Defines>USE_CUDNN</Defines>
  64. </CudaCompile>
  65. </ItemDefinitionGroup>
  66. <ItemDefinitionGroup Condition="'$(PythonSupport)'=='true'">
  67. <ClCompile>
  68. <PreprocessorDefinitions>WITH_PYTHON_LAYER;BOOST_PYTHON_STATIC_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  69. </ClCompile>
  70. </ItemDefinitionGroup>
  71. <ItemDefinitionGroup Condition="'$(MatlabSupport)'=='true'">
  72. <ClCompile>
  73. <PreprocessorDefinitions>MATLAB_MEX_FILE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  74. </ClCompile>
  75. </ItemDefinitionGroup>
  76. <ItemDefinitionGroup>
  77. <ClCompile>
  78. <MinimalRebuild>false</MinimalRebuild>
  79. <MultiProcessorCompilation>true</MultiProcessorCompilation>
  80. <PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;USE_OPENCV;USE_LEVELDB;USE_LMDB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  81. <TreatWarningAsError>true</TreatWarningAsError>
  82. </ClCompile>
  83. </ItemDefinitionGroup>
  84. <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
  85. <ClCompile>
  86. <Optimization>Full</Optimization>
  87. <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  88. <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
  89. <FunctionLevelLinking>true</FunctionLevelLinking>
  90. </ClCompile>
  91. <Link>
  92. <EnableCOMDATFolding>true</EnableCOMDATFolding>
  93. <GenerateDebugInformation>true</GenerateDebugInformation>
  94. <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
  95. <OptimizeReferences>true</OptimizeReferences>
  96. </Link>
  97. </ItemDefinitionGroup>
  98. <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
  99. <ClCompile>
  100. <Optimization>Disabled</Optimization>
  101. <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  102. <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
  103. </ClCompile>
  104. <Link>
  105. <GenerateDebugInformation>true</GenerateDebugInformation>
  106. </Link>
  107. </ItemDefinitionGroup>
  108. </Project>

3、编译caffe-windows

编译用vs2013打开.\windows\Caffe.sln 并将解决方案的配置改为release,点菜单栏上的“生成->生成解决方案”,会将整个项目全部生成,这个时间会比较长(由于官方caffe-windows 的版本使用了NuGet管理第三方开发包,所以需要在vs2013上安装NuGet,官方网站下载速度比较慢,可以在我的资源里下载)。生成成功之后的文件都在.\Build\x64\Release中。

PS:生成时可能遇到的错误:errorC2220: 警告被视为错误 - 没有生成“object”文件 (..\..\src\caffe\util\math_functions.cpp)。这个错误可参考Sunshine_in_Moon 的解决方案

4、测试

1)下载MNIST数据集,MNIST数据集包含四个文件,如表1所示:

表1:MNIST数据集及其文件解释

文件

内容

train-images-idx3-ubyte.gz

训练集图片 - 55000 张 训练图片, 5000 张 验证图片

train-labels-idx1-ubyte.gz

训练集图片对应的数字标签

t10k-images-idx3-ubyte.gz

测试集图片 - 10000 张 图片

t10k-labels-idx1-ubyte.gz

测试集图片对应的数字标签

下载完后解压得到对应的四个文件,这四个文件不能直接用于caffe的训练和测试。需要利用第4步生成的convert_mnist_data.exe把四个文件转换为caffe所支持的leveldb或lmdb文件。

2)转换 训练\测试数据

a)  中的四个文件放到 . \examples\mnist\mnist_data文件夹下。

b)  在caffe-windows安装的根目录下,新建一个convert-mnist-data-train.bat文件转换为训练数据,并在文件中添加代码:

  1. Build\x64\Release\convert_mnist_data.exe --backend=lmdbexamples\mnist\mnist_data\train-images.idx3-ubyteexamples\mnist\mnist_data\train-labels.idx1-ubyte examples\mnist\mnist_data\mnist_train_lmdb
  2. pause

其中--backend=lmdb 表示转换为lmdb格式,若要转换为leveldb将其改写为--backend=leveldb 即可。

再新建一个convert-mnist-data-test.bat转换测试数据,代码为:

  1. Build\x64\Release\convert_mnist_data.exe --backend=lmdb examples\mnist\mnist_data\t10k-images.idx3-ubyte examples\mnist\mnist_data\t10k-labels.idx1-ubyte examples\mnist\mnist_data\mnist_test_lmdb
  2. Pause

Ps:(1)convert_mnist_data.exe的命令格式为:

convert_mnist_data [FLAGS] input_image_file input_label_file output_db_file

[FLAGS]:转换的文件格式可取leveldb或lmdb,示例:--backend=leveldb

Input_image_file:输入的图片文件,示例:train-images.idx3-ubyte

input_label_file:输入的图片标签文件,示例:train-labels.idx1-ubyte

output:保存输出文件的文件夹,示例:mnist_train_lmdb

(2)如果感觉很麻烦,也可以直接下载我转换好的MNIST文件(leveldb和lmdb)。

3)运行测试

(1)将第2)步中转换好的训练\测试数据集(mnist_train_lmdb\ mnist_train_lmdb或mnist_train_leveldb\mnist_train_leveldb)文件夹放在.\examples\mnist中。

(2)在caffe-windows根目录下新建一个run.bat,文件中代码:

  1. Build\x64\Release\caffe.exe  train --solver=examples/mnist/lenet_solver.prototxt
  2. pause

保存并双击运行,如果运行成功,说明caffe配置成功了。

注意1使用leveldb或lmdb格式的数据时,需要将lenet_train_test.prototxt 文件里面的data_param-> source和data_param-> backend相对应,如图5红框所标注处。

 

图 5:lenet_train_test.prototxt文件中需要注意与训练\测试数据对应的部分

注意2将lenet_solver.prototxt 文件里面的最后一行改为solver_mode:CPU。

4)训练自己的数据

这部分可以参考下面的几个博客:

1.在caffe上跑自己的数据

2.windows下caffe训练自己的数据

reference:

官方Caffe-windows 配置与示例运行

【caffe-Windows】caffe+VS2013+Windows无GPU快速配置教程

Windows下caffe安装详解(cpu+gpu+matcaffe+pycaffe)

Windows下caffe安装详解(仅CPU)的更多相关文章

  1. windows下mongodb安装详解

    1.打开官网https://www.mongodb.com/download-center?jmp=nav#community 注:这里小伙伴们可是开启下FQ软件psiphon 3下载(不开启FQ好像 ...

  2. 【Gtk】feorda下gtk安装详解

    feorda下gtk安装详解   1.yum在线安装gtk 1)pkg-config -version查看pkg-config的版本(本机测试是0.25)    2)安装必要组建:(在root权限下) ...

  3. windows下caffe安装配置、matlab接口

    一.CommonSettings.props caffe下载后解压.源代码文件夹caffe-master,到该文件夹下的windows文件夹下,将CommonSettings.props.exampl ...

  4. windows下route命令详解(转载)

    1.具体功能        该命令用于在本地IP路由表中显示和修改条目.使用不带参数的ROUTE可以显示帮助.            2.语法详解        route [-f] [-p] [co ...

  5. Linux和Windows下ping命令详解(转:http://linux.chinaitlab.com/command/829332.html)

    一.Linux下的ping参数 用途 发送一个回送信号请求给网络主机. 语法 ping [ -d] [ -D ] [ -n ] [ -q ] [ -r] [ -v] [ \ -R ] [ -a add ...

  6. Linux和Windows下ping命令详解

    转:http://linux.chinaitlab.com/command/829332.html 一.Linux下的ping参数 用途 发送一个回送信号请求给网络主机. 语法 ping [ -d] ...

  7. IPython,让Python显得友好十倍的外套——windows XP/Win7安装详解

        前言 学习python,官方版本其实足够了.但是如果追求更好的开发体验,耐得住不厌其烦地折腾.那么我可以负责任的告诉你:IPython是我认为的唯一显著好于原版python的工具.   整理了 ...

  8. Linux系统下Nginx安装详解

    该随笔为个人原创,后期会根据项目实践实时更新,如若转载,请注明出处,方便大家获得最新博文! 注:安装Nginx需要Linux系统已经安装   openssl-fips-2.0.2.tar.gz zli ...

  9. Linux 下 Redis 安装详解

    文章来源:www.oschina.net/question/12_18065 redis作为NoSQL数据库的一种应用,响应速度和命中率上还是比较高效的.项目中需要用集中式可横向扩展的缓存框架,做了一 ...

随机推荐

  1. ASP.NET动态网站制作(9)-- JQ(1)

    前言:从这节课开始讲jQuery的相关内容,这节课主要围绕jQuery的选择器展开. 内容: 1.jQuery是一个优秀的js框架,目前企业里大多数都是用jQuery(以下简称jq).jq是对js里一 ...

  2. PHP百分号转小数

    <?php $a = "20.544545%"; echo (float)$a/100; ?>

  3. python 基础 4.3 高阶函数下和匿名函数

    一 .匿名函数 顾名思议就是没有名字的函数,那为什么要设立匿名函数,他有什么作用呢?lambda 函数就是一种快速定义单行的最小函数,可以用在任何需要函数的地方.   常规版: def fun(x,y ...

  4. 【BZOJ1150】[CTSC2007]数据备份Backup 双向链表+堆(模拟费用流)

    [BZOJ1150][CTSC2007]数据备份Backup Description 你在一家 IT 公司为大型写字楼或办公楼(offices)的计算机数据做备份.然而数据备份的工作是枯燥乏味的,因此 ...

  5. VMware虚拟机下安装RedHat Linux 9.0

    从这一篇文章开始我和大家一起学习Linux系统.不管是什么样的系统,必须安装上才能谈使用对吧. Linux版本 安装Linux之前需要了解一下Linux系统的安装版本. Linux的版本分为内核版本和 ...

  6. iOS SQLite使用

    数据库的特征: 以一定方式存储在一起 能为多个用户分享 具有尽可能少的冗余代码 与程序彼此独立的数据集 SQLite SQLite是一个轻量级关系数据库,最初的设计目标是用于嵌入式系统,它占用资源非常 ...

  7. new() 和 make() 的区别

    https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/07.2.md

  8. Kafka核心思想

    Kafka是2010年12月份开源的项目,采用Scala语言编写,使用了多种效率优化机制,整体架构比较新颖(push/pull),更适合异构集群. 设计目标: (1) 数据在磁盘上的存取代价为O(1) ...

  9. 【题解】[JSOI2008]最大数

    [题解][P1198 JSOI2008]最大数 正难则反,意想不到. 这道题是动态让你维护一个数列,已经在数列里面的数据不做改变,每次在最后加上一个数,强制在线. 既然正着做很难,考虑如果时间倒流,不 ...

  10. java实现二叉树的构建以及3种遍历方法(转)

    转 原地址:http://ocaicai.iteye.com/blog/1047397 大二下学期学习数据结构的时候用C介绍过二叉树,但是当时热衷于java就没有怎么鸟二叉树,但是对二叉树的构建及遍历 ...