转载来自:http://blog.csdn.net/guoyk1990/article/details/52909864

本文主要介绍官方给出的caffe-windows的配置及如何训练mnist数据集,介绍的比较基础,大神请绕道

1、环境:windows 10\CUDA7.5\cuDNN\VS2013

2、GPU计算环境准备(没有GPU的同学可以跳过此步)

(1)首先下载并安装CUDA7.5,下载界面如图1:

图 1:CUDA7.5的下载界面

(2)下载cuDNN,注意要下载cuDNN v4版本,下载界面如图2:

图 2:cuDNN的下载界面

官网下载cuDNN需要先注册,而且要填一些调查表,也可以在我上传的资源中下载。下载后解压会有三个文件夹bin、include、lib。将这三个文件夹复制到cuda的安装目录中:\NVIDIA GPU ComputingToolkit\CUDA\v7.5。(cuda的安装目录中也有这三个文件夹,将这三个文件夹分别与原来存在的文件夹合并,如3图所示)。

图 3:CUDA 7.5 安装的根目录

3、caffe-windows准备

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

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

(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>

4、编译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 的解决方案

5、测试

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配置成功了。

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

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

4)训练自己的数据

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

1.在caffe上跑自己的数据

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

转载:官方Caffe-windows 配置与示例运行的更多相关文章

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

    http://blog.csdn.net/guoyk1990/article/details/52909864 标签: caffewindows配置训练自己的数据 2016-10-24 13:34 1 ...

  2. Windows 配置nginx服务器 运行php项目

    1下载 http://nginx.org/en/download.html 选择稳定版下载. 2 解压后 直接双击nginx.exe 双击后一个黑色的弹窗一闪而过 3 修改配置文件nginx.conf ...

  3. Windows配置本地Hadoop运行环境

    很多人喜欢用Windows本地开发Hadoop程序,这里是一个在Windows下配置Hadoop的教程. 首先去官网下载hadoop,这里需要下载一个工具winutils,这个工具是编译hadoop用 ...

  4. 沁恒CH32F103C8T6(二): Linux PlatformIO环境配置, 示例运行和烧录

    目录 沁恒CH32F103C8T6(一): Keil5环境配置,示例运行和烧录 沁恒CH32F103C8T6(二): Linux PlatformIO环境配置, 示例运行和烧录 StdPeriphLi ...

  5. 快速解决:windows安装程序无法将windows配置为在此计算机的硬件上运行

    用手工运行msoobe.ext启用配置的方法, 快速解决:windows安装程序无法将windows配置为在此计算机的硬件上运行   我自己安装碰到的是蓝色这个错误,下面这个也有网友说用安装驱动等方法 ...

  6. Windows 安装程序无法将 Windows 配置为在此计算机的硬件上运行

    遇到这个问题是用辅助工具(WinNTSetup3.exe)进行的安装,重启后就就遇到“Windows 安装程序无法将 Windows 配置为在此计算机的硬件上运行” 解决:在WIN PE 下挂载安装光 ...

  7. windows安装程序无法将windows配置为在此计算机的硬件上运行

    关于装windows系统时,出现一些安装中断的处理 该方法适用于 windows安装程序无法将windows配置为在此计算机的硬件上运行 计算机意外地重新启动或遇到错误. Windows 安装无法继续 ...

  8. Windows下caffe的配置和调用caffe库(一)

    一.Windows下caffe的配置: 1. 下载caffe官网提供的开发包,https://github.com/microsoft/caffe 2. 将caffe-master目录下的Window ...

  9. windows配置caffe + python和matlab接口

    参考: http://blog.csdn.net/baidu_26408419/article/details/53711640 http://www.cnblogs.com/love6tao/p/5 ...

随机推荐

  1. DS二叉树--叶子数量

    题目描述 计算一颗二叉树包含的叶子结点数量. 提示:叶子是指它的左右孩子为空. 建树方法采用“先序遍历+空树用0表示”的方法,即给定一颗二叉树的先序遍历的结果为AB0C00D00,其中空节点用字符‘0 ...

  2. Solr[Q] -No live SolrServers available to handle this request, no servers hosting shard

    No live SolrServers available to handle this request , no servers hosting shard 当某一片索引对应的结点全部宕了以后,会报 ...

  3. bzoj5011: [Jx2017]颜色

    Description 可怜有一个长度为n的正整数序列Ai,其中相同的正整数代表着相同的颜色. 现在可怜觉得这个序列太长了,于是她决定选择一些颜色把这些颜色的所有位置都删去. 删除颜色i可以定义为把所 ...

  4. 使用Google cardboard 2的一些软件

    最近入手cardboard2,FQ尝试了一些软件,特别分享,给大家提供一些方便. 链接:http://pan.baidu.com/s/1slehilZ 密码:b49h

  5. Rabbitmq 安装&启动

    安装socat [root@Aliyun software]# yum -y install epel-release [root@Aliyun software]# yum -y install s ...

  6. 数组连接a.concat(b),b作为一个整体

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  7. 文档碎片及xml讲解

    1.将数据渲染到页面的几种方式 1.字符串拼接 2.dom循环 3.模板 4.文档碎片 字符串拼接: 优势:只进行一次dom回流 缺点:原有的dom事件会消失 案例分析:原有list中有3个li,并且 ...

  8. MySQL mysqlbinlog企业案例

    内容待补充 案例文字说明: 7.3 故障时间点: 周四上午10点,开发人员误删除了一个表,如何恢复? 7.4 思路: 1.停业务,避免数据的二次伤害 2.找一个临时库,恢复周三23:00全备 3.截取 ...

  9. SqlServer查询中使用事务

    --获取一个新的ID declare @newId bigint select @newId=MAX(ID) from BdRdRecord01 begin tran or @newId is nul ...

  10. 一个简单的基于多进程实现并发的Socket程序

    在单进程的socket的程序的基础上,实现多进程并发效果的思路具体是:在server端开启“链接循环”,每建立一次链接就生成一个Process对象进行server-client的互动,而client端 ...