设为首页 收藏本站
查看: 702|回复: 0

[经验分享] 官方Caffe-windows 配置与示例运行

[复制链接]

尚未签到

发表于 2017-12-8 08:46:57 | 显示全部楼层 |阅读模式
http://blog.csdn.net/guoyk1990/article/details/52909864


标签: caffewindows配置训练自己的数据
2016-10-24 13:34 11651人阅读 评论(2) 收藏 举报

DSC0000.jpg 分类:
深度学习(1) DSC0001.jpg 图像处理(13) caffe(1)
版权声明:本文为博主原创文章,未经博主允许不得转载。

  本文主要介绍官方给出的caffe-windows的配置及如何训练mnist数据集,介绍的比较基础,大神请绕道 DSC0002.gif
  1、环境:windows 10\CUDA7.5\cuDNN\VS2013
  2、GPU计算环境准备(没有GPU的同学可以跳过此步)
  (1)首先下载并安装CUDA7.5,下载界面如图1:
DSC0003.jpg

  图 1:CUDA7.5的下载界面
  (2)下载cuDNN,注意要下载cuDNN v4版本,下载界面如图2:
DSC0004.jpg

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

DSC0005.jpg

图 3:CUDA 7.5 安装的根目录

3、caffe-windows准备

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

DSC0006.jpg

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

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文件转换为训练数据,并在文件中添加代码:





[python] view plain copy

  • 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
  • pause
其中--backend=lmdb 表示转换为lmdb格式,若要转换为leveldb将其改写为--backend=leveldb 即可。

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





[python] view plain copy

  • 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
  • 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,文件中代码:



[python] view plain copy

  • Build\x64\Release\caffe.exe  train --solver=examples/mnist/lenet_solver.prototxt
  • pause
  保存并双击运行,如果运行成功,说明caffe配置成功了。
注意使用leveldb或lmdb格式的数据时,需要将lenet_train_test.prototxt 文件里面的data_param-> source和data_param-> backend相对应,如图5红框所标注处。
DSC0007.jpg

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

4)训练自己的数据

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

1.在caffe上跑自己的数据

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


References

BVLC/caffe

从零到一:caffe-windows(CPU)配置与利用mnist数据集训练第一个caffemodel

Windows+VS2013爆详细Caffe编译安装教程

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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-422034-1-1.html 上篇帖子: C++ windows 多线程 互斥锁 下篇帖子: delphi 启动停止windows服务 转
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表