Windows下caffe安装详解(仅CPU)
本文大多转载自 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文件的一点说明。
- </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>
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数据集及其文件解释
文件 |
内容 |
训练集图片 - 55000 张 训练图片, 5000 张 验证图片 |
|
训练集图片对应的数字标签 |
|
测试集图片 - 10000 张 图片 |
|
测试集图片对应的数字标签 |
2)转换 训练\测试数据
a) 中的四个文件放到 . \examples\mnist\mnist_data文件夹下。
b) 在caffe-windows安装的根目录下,新建一个convert-mnist-data-train.bat文件转换为训练数据,并在文件中添加代码:
- 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转换测试数据,代码为:
- 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,文件中代码:
- Build\x64\Release\caffe.exe train --solver=examples/mnist/lenet_solver.prototxt
- 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)训练自己的数据
这部分可以参考下面的几个博客:
reference:
【caffe-Windows】caffe+VS2013+Windows无GPU快速配置教程
Windows下caffe安装详解(cpu+gpu+matcaffe+pycaffe)
Windows下caffe安装详解(仅CPU)的更多相关文章
- windows下mongodb安装详解
1.打开官网https://www.mongodb.com/download-center?jmp=nav#community 注:这里小伙伴们可是开启下FQ软件psiphon 3下载(不开启FQ好像 ...
- 【Gtk】feorda下gtk安装详解
feorda下gtk安装详解 1.yum在线安装gtk 1)pkg-config -version查看pkg-config的版本(本机测试是0.25) 2)安装必要组建:(在root权限下) ...
- windows下caffe安装配置、matlab接口
一.CommonSettings.props caffe下载后解压.源代码文件夹caffe-master,到该文件夹下的windows文件夹下,将CommonSettings.props.exampl ...
- windows下route命令详解(转载)
1.具体功能 该命令用于在本地IP路由表中显示和修改条目.使用不带参数的ROUTE可以显示帮助. 2.语法详解 route [-f] [-p] [co ...
- Linux和Windows下ping命令详解(转:http://linux.chinaitlab.com/command/829332.html)
一.Linux下的ping参数 用途 发送一个回送信号请求给网络主机. 语法 ping [ -d] [ -D ] [ -n ] [ -q ] [ -r] [ -v] [ \ -R ] [ -a add ...
- Linux和Windows下ping命令详解
转:http://linux.chinaitlab.com/command/829332.html 一.Linux下的ping参数 用途 发送一个回送信号请求给网络主机. 语法 ping [ -d] ...
- IPython,让Python显得友好十倍的外套——windows XP/Win7安装详解
前言 学习python,官方版本其实足够了.但是如果追求更好的开发体验,耐得住不厌其烦地折腾.那么我可以负责任的告诉你:IPython是我认为的唯一显著好于原版python的工具. 整理了 ...
- Linux系统下Nginx安装详解
该随笔为个人原创,后期会根据项目实践实时更新,如若转载,请注明出处,方便大家获得最新博文! 注:安装Nginx需要Linux系统已经安装 openssl-fips-2.0.2.tar.gz zli ...
- Linux 下 Redis 安装详解
文章来源:www.oschina.net/question/12_18065 redis作为NoSQL数据库的一种应用,响应速度和命中率上还是比较高效的.项目中需要用集中式可横向扩展的缓存框架,做了一 ...
随机推荐
- iOS对象(字典或数组)转化为JSon字符串
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; [dictionary setValue:@"he ...
- iOS 可选择的购物车
最近看了淘宝的购物车,于是做了一个可选择的购物车模板. 如果有好的建议请提出,带我日后更新.
- 高性能流媒体服务器EasyDSS前端重构(二) webpack + vue + AdminLTE 多页面提取共用文件, 优化编译时间
本文围绕着实现EasyDSS高性能流媒体服务器的前端框架来展开的,具体EasyDSS的相关信息可在:www.easydss.com 找到! 接上回 <高性能流媒体服务器EasyDSS前端重构(一 ...
- 通用分页(Jquery版)
1.简单定义下样式 <style type="text/css"> .fanye { color: blue; margin-right: 15px; text-dec ...
- intellij idea同一个窗口打开多个项目
1 将多个maven项目放在同一个目录 2 file --> open该目录 intellij 将会加载该目录下所有的项目. 3 依赖加载 maven projects--->" ...
- Wireshark学习笔记——怎样高速抓取HTTP数据包
0.前言 在火狐浏览器和谷歌浏览器中能够很方便的调试network(抓取HTTP数据包),可是在360系列浏览器(兼容模式或IE标准模式)中抓取HTTP数据包就不那么那么方便了.尽管也可使用H ...
- 关于wx.redirectTo、wx.navigateTo失效问题
问题:在app.json页面中若配置了tabBar,并且要跳转的目标页面也在tabBar中时,那么常用的几种页面跳转方式便失效了.即不能跳转到tabBar中定义的页面. 解决办法:若要跳转至tabBa ...
- 安装pymysqlpool并使用(待补充)
pip3 install PyMysqlPool 第一个错,提示没有装c++ 14.0,下载安装报下一个错 error: Setup script exited with error: Microso ...
- 山东省第四届ACM程序设计竞赛A题:Rescue The Princess(数学+计算几何)
Rescue The Princess Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 412 Solved: 168[Submit][Status][ ...
- Hive- Hive安装
Hive安装 1.1下载Hive安装包 官网:http://hive.apache.org/downloads.html 个人建议到这里下载:http://apache.forsale.plus/ 1 ...