用Caffe 可以project做什么的好玩的 Project

VS2013(Win10X64)配置使用Caffe源码
VS2013(Win10X64)配置使用Caffe源码
&&&&&&&& 原文链接:http://blog.csdn.net/joshua_1988/article/details/
&&&&&&&& 2014年4月的时候自己在公司就将Caffe移植到Windows系统了,今年自己换了台电脑,想在家里也随便跑跑,本来也装了Ubuntu可以很方便的配置好,无奈在家的风格是“娱乐的时候抽空学习”,所以移植到Windows还是很有必要的。但是,公司禁止将公司内部资料带出,很多地方又都忘记了,周末磨了一天终于移植完,本篇为记录将Caffe移植至Windows7&x64系统下的一些关键步骤。下面介绍如何从源码建立VS2013工程。
1.&从/BVLC/caffe下载caffe源码,master或者dev版本都可以,本文中以dev为例
2.&新建一个空的控制台VS2013工程,起名为caffe-dev。
File&--&&New&--&&Project
选择Win32&Console&Application
选择工程路径,比如D:CODECXX
给项目命名caffe-dev
单击OK后选择Empty&project
3.&将工程的Solution&Platform改为x64
Build&--&&Configuration&Manager&--&&Active&solution&platform&--&&new&--&&x64&--&&OK
4.&设置CUDA编译
property--& Build dependencies --&&Build&Customizations...&--&&CUDA 6.5 --&&OK
5.&设置一些工程下的路径,注意Debug和Release下都要设置
在Project&--&&Properties&--&&Configuration&Properties&--&&VC++&Directories&--&&Include&Directories中添加openblas、opencv、boost和cuda,例如
C:Toolsboost_1_56
C:ToolsOpenBLAS_MinGW
C:Toolsopen
C:Toolsopencvbuildincludeopencv2;
C:Program FilesNVIDIA GPU Computing ToolkitCUDAv6.5
在Project&--&&Properties&--&&Configuration&Properties&--&&VC++&Directories&--&&Library&Directories中添加openblas、opencv、boost和cuda,例如
C:ToolsOpenBLAS_MinGW
C:Toolsopencvbuildx64vc12
C:Toolsboost_1_56lib64-msvc-12.0;
C:Program FilesNVIDIA GPU Computing ToolkitCUDAv6.5libx64;
6.&将压缩包内的include、src和tools文件夹拷贝到工程根目录下,同时把整理好的3rdparty文件夹也拷贝到工程目录下&
7.&添加caffe的路径和3rdparty中第三方依赖库的路径,同样Debug和Release都要设置
在Project&--&&Properties&--&&Configuration&Properties&--&&C/C++&--&&General&--&&Additional&Include&Directories中添加
../3rdparty/include
../3rdparty/include/hdf5
../3rdparty/include/lmdb
&&&&&&&&&&& C:ToolsCaffe-3
在Project&--&&Properties&--&&Configuration&Properties&--&&Linker&--&&General&--&&Additional&Library&Directories中添加
../3rdparty/lib
C:ToolsCaffe-3rdlibLevelDB;
C:ToolsCaffe-3
C:ToolsCaffe-3
C:ToolsCaffe-3
C:ToolsCaffe-3
在Project&--&&Properties&--&&Configuration&Properties&--&&Linker&--&&Input&--&&Additional&Dependencies中添加
opencv_core2410.lib
opencv_highgui2410.lib
opencv_imgproc2410.lib
opencv_ts300.lib
opencv_world300.lib
cudart.lib
cublas.lib
curand.lib
gflags.lib
libglog.lib
libopenblas.dll.a
libopenblas.lib
libprotobuf.lib
libprotoc.lib
leveldb.lib
libhdf5.lib
libhdf5_hl.lib
Shlwapi.lib
注意在Debug下应添加xxxd.lib形式的自己确认一下debug命名 静态库
opencv_core2410d.lib
opencv_highgui2410d.lib
opencv_imgproc2410d.lib
opencv_ts300d.lib
opencv_world300d.lib
cudart.lib
cublas.lib
curand.lib
gflagsd.lib
libglogd.lib
libopenblas.dll.a
libopenblas.lib
libprotobuf-gd.lib
libprotoc.lib
leveldbd.lib
libhdf5.lib
libhdf5_hl.lib
Shlwapi.lib
8.&利用protoc.exe和caffe.proto生成caffe.pb.h和caffe.pb.cc文件
在编译protobuf的时候会生成一个可执行文件protoc.exe,在工程的D:CODECXXcaffe-devsrccaffeproto路径下有一个文件叫caffe.proto,可以将protoc.exe拷贝到该路径下,在命令行中进入D:CODECXXcaffe-devsrccaffeproto路径,输入命令
view plaincopy
&del&&span style=&color:#FF0000;&&&span style=&background-color: rgb(255, 0, 0);&&protoc.exe caffe.proto --cpp_output=./
&/span&&/span&&/del&
可以看到在该路径下会生成caffe.pb.h和caffe.pb.cc,在D:CODECXXcaffeincludecaffe中新建一个文件夹proto,
将生成的两个文件移动到D:CODECXXcaffeincludecaffeproto中
cd C:Toolscaffe-mastersrccaffeproto protoc --cpp_out=&.& caffe.proto
9.&准备mkstemp.h和mkstemp.cpp文件。
将mkstemp.h放在include/caffe/util/路径下,mkstemp.h中的内容为
view plaincopy
#include &windows.h&
#include &io.h&
int mkstemp(char *templates);
将mkstemp.cpp放在src/caffe/util/路径下,mkstemp.cpp中的内容为
view plaincopy
/* mkstemp extracted from libc/sysdeps/posix/tempname.c.
(C) , , 2006 Free Software Foundation, Inc.
The GNU C Libr you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software F either
version 2.1 of the License, or (at your option) any later version.
#include &caffe/util/mkstemp.hpp&
#include &errno.h&
#include &fcntl.h&
#include &sys/stat.h&
static const char letters[] =
&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&;
/* Generate a temporary file name based on TMPL.
TMPL must match the
rules for mk[s]temp (i.e. end in &XXXXXX&).
The name constructed
does not exist at the time of the call to mkstemp.
overwritten with the result.
int mkstemp (char *tmpl)
char *XXXXXX;
static unsi
unsigned long long random_time_
int fd = -1;
int save_errno =
/* A lower bound on the number of temporary files to attempt to
The maximum total number of temporary file names that
can exist for a given template is 62**6.
It should never be
necessary to try all these combinations.
Instead if a reasonable
number of names is tried (we define reasonable as 62**3) fail to
give the system administrator the chance to remove the problems.
#define ATTEMPTS_MIN (62 * 62 * 62)
/* The number of times to attempt to generate a temporary file.
conform to POSIX, this must be no smaller than TMP_MAX.
#if ATTEMPTS_MIN & TMP_MAX
unsigned int attempts = TMP_MAX;
unsigned int attempts = ATTEMPTS_MIN;
len = strlen (tmpl);
if (len & 6 || strcmp (&tmpl[len - 6], &XXXXXX&))
errno = EINVAL;
return -1;
/* This is where the Xs start.
XXXXXX = &tmpl[len - 6];
/* Get some more or less random data.
SYSTEMTIME
FILETIME ftN
// get system time
GetSystemTime(&stNow);
stNow.wMilliseconds = 500;
if (!SystemTimeToFileTime(&stNow, &ftNow))
errno = -1;
return -1;
random_time_bits = (((unsigned long long)ftNow.dwHighDateTime && 32)
| (unsigned long long)ftNow.dwLowDateTime);
value += random_time_bits ^ (unsigned long long)GetCurrentThreadId ();
for (count = 0; count & value += 7777, ++count)
unsigned long long v =
/* Fill in the random bits.
XXXXXX[0] = letters[v % 62];
XXXXXX[1] = letters[v % 62];
XXXXXX[2] = letters[v % 62];
XXXXXX[3] = letters[v % 62];
XXXXXX[4] = letters[v % 62];
XXXXXX[5] = letters[v % 62];
fd = open (tmpl, O_RDWR | O_CREAT | O_EXCL, _S_IREAD | _S_IWRITE);
if (fd &= 0)
errno = save_
else if (errno != EEXIST)
return -1;
/* We got out of the loop because we ran out of combinations to try.
errno = EEXIST;
return -1;
10.&将caffe的源文件添加到工程中
将D:CODECXXcaffe-devsrccaffe路径下除了test文件中的所有源文件添加到工程中,如果想要跑一些测试代码,也可以把test中的源文件加进去
将D:CODECXXcaffe-devincludecaffeproto下的caffe.pb.cc添加到工程中
将D:CODECXXcaffe-devtools下的caffe.cpp添加到工程中&
11.&修改一些代码
在include/caffe/common.hpp中添加#include&&direct.h&
在include/caffe/util/io.hpp中添加#include&&mkstemp.hpp&,并将close函数替换为_close,
将char*&mkdtemp_result&=&mkdtemp(temp_dirname_cstr);替换为errno_t&mkdtemp_result&=&_mktemp_s(temp_dirname_cstr,&sizeof(temp_dirname_cstr));&
将bnll_layer.cu中的const&float&kBNLL_THRESHOLD&=&50.;修改为#define&kBNLL_THRESHOLD&50.
将util/db.cpp中的mkdir(source.c_str(),&0744)修改为_mkdir(source.c_str())
将util/io.cpp中的open函数替换为_open,close函数替换为_close
将util/io.cpp中ReadProtoFromBinaryFile函数中的int&fd&=&open(filename,&O_RDONLY);替换为int&fd&=&open(filename,&O_RDONLY&|&O_BINARY);
在util/math_functions.cpp中添加
view plaincopy
#define&__builtin_popcount&__popcnt&&&#define&__builtin_popcountl&__popcnt&&
在common.cpp中添加#include&&process.h&
将pid&=&getpid();替换为pid&= _getpid(); 这里本来有个笔误,谢谢dongb5lz的提醒
注释掉::google::InstallFailureSignalHandler();
将solver.cpp中的snprintf函数替换为sprintf_s
编译吧!!!!
感谢关注 Ithao123精品文库频道,是专门为互联网人打造的学习交流平台,全面满足互联网人工作与学习需求,更多互联网资讯尽在 IThao123!
Laravel是一套简洁、优雅的PHP Web开发框架(PHP Web Framework)。它可以让你从面条一样杂乱的代码中解脱出来;它可以帮你构建一个完美的网络APP,而且每行代码都可以简洁、富于表达力。
Hadoop是一个由Apache基金会所开发的分布式系统基础架构。
用户可以在不了解分布式底层细节的情况下,开发分布式程序。充分利用集群的威力进行高速运算和存储。
Hadoop实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS。HDFS有高容错性的特点,并且设计用来部署在低廉的(low-cost)硬件上;而且它提供高吞吐量(high throughput)来访问应用程序的数据,适合那些有着超大数据集(large data set)的应用程序。HDFS放宽了(relax)POSIX的要求,可以以流的形式访问(streaming access)文件系统中的数据。
Hadoop的框架最核心的设计就是:HDFS和MapReduce。HDFS为海量的数据提供了存储,则MapReduce为海量的数据提供了计算。
产品设计是互联网产品经理的核心能力,一个好的产品经理一定在产品设计方面有扎实的功底,本专题将从互联网产品设计的几个方面谈谈产品设计
随着国内互联网的发展,产品经理岗位需求大幅增加,在国内,从事产品工作的大部分岗位为产品经理,其实现实中,很多从事产品工作的岗位是不能称为产品经理,主要原因是对产品经理的职责不明确,那产品经理的职责有哪些,本专题将详细介绍产品经理的主要职责
IThao123周刊游迅网官方微信:
yxdown-com(扫我)
每日推送最热最新资讯
海量手游礼包免费领取
剩余:198/200
剩余:98/100
剩余:198/200
剩余:375/400
剩余:97/100
剩余:88/100
剩余:196/200
剩余:200/200
剩余:200/200
剩余:199/200
热门安卓游戏排行
类别:休闲游戏
类别:角色扮演
类别:休闲游戏
1282次下载
最新安卓游戏排行
类别:棋牌游戏
类别:休闲游戏
类别:角色扮演
CopyRight2004年-年
游迅网 All Rights Reserved
备案编号:沪ICP备号-9[操作系统]caffe 无GPU 环境搭建
你的位置:
[操作系统]caffe 无GPU 环境搭建
root@k-Lenovo:/home/k# sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compilerroot@k-Lenovo:/home/k# sudo apt-get install --no-install-recommends libboost-all-dev&root@k-Lenovo:~# sudo apt-get install linux-headers-$(uname -r)&BLASroot@k-Lenovo:/home/k# sudo apt-get install libatlas-base-dev&其他依赖项root@k-Lenovo:/home/k# sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev &OpenCVroot@k-Lenovo:/home/k# sudo apt-get install build-essential&root@k-Lenovo:/home/k# sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev &root@k-Lenovo:/home/k# sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev&1234git clone /Itseez/opencv.git&&cd ~/opencv&&mkdir build&&cd build&root@k-Lenovo:~/opencv/build# cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..&root@k-Lenovo:~/opencv/build# ls3rdparty
CPackSourceConfig.cmake Makefileapps
CTestTestfile.cmake
modulesbin
custom_hal.hpp
opencv2CMakeCache.txt
cvconfig.h
OpenCVConfig.cmakeCMakeFiles
OpenCVConfig-version.cmakecmake_install.cmake
OpenCVModules.cmakecmake_uninstall.cmake include
test-reportsCMakeVars.txt
unix-installCPackConfig.cmake
version_string.tmp&root@k-Lenovo:~/opencv/build# make -j4&root@k-Lenovo:~/opencv/build# sudo make install&Cafferoot@k-Lenovo:~/caffe# lscaffe.cloc
INSTALL.md
toolscmake
pythonCMakeLists.txt
README.mdCONTRIBUTING.md examples Makefile.config.example scriptsCONTRIBUTORS.md include
srcroot@k-Lenovo:~/caffe# pwd/root/cafferoot@k-Lenovo:~/caffe# cp Makefile.config.example Makefile&root@k-Lenovo:~/caffe# vim Makefile&endififeq ($(USE_OPENCV), 1)
LIBRARIES += opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs #增加opencv_imgcodecs
ifeq ($(OPENCV_VERSION), 3)
LIBRARIES += opencv_imgcodecs
endif&root@k-Lenovo:~/caffe# make all&root@k-Lenovo:~/caffe# make allCXX src/caffe/common.cppIn file included from ./include/caffe/common.hpp:19:0,
from src/caffe/common.cpp:7:./include/caffe/util/device_alternate.hpp:34:23: fatal error: cublas_v2.h: No such file or directory #include &cublas_v2.h&
^compilation terminated.make: *** [.build_release/src/caffe/common.o] Error 1&root@k-Lenovo:~/caffe# vi Makefile.config# CPU-only switch (uncomment to build without GPU support).CPU_ONLY := 1 #关键&root@k-Lenovo:~/caffe# make all&root@k-Lenovo:~/caffe# make test&root@k-Lenovo:~/caffe# make runtest&root@k-Lenovo:~/caffe# make runtest.build_release/tools/caffe.build_release/tools/caffe: error while loading shared libraries: libopencv_core.so.3.1: cannot open shared object file: No such file or directorymake: *** [runtest] Error 127&root@k-Lenovo:~/caffe# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib&root@k-Lenovo:~/caffe# make runtest...[----------] 1 test from SolverTest/1, where TypeParam = caffe::CPUDevice&double&[ RUN
] SolverTest/1.TestInitTrainTestNets[
OK ] SolverTest/1.TestInitTrainTestNets (1 ms)[----------] 1 test from SolverTest/1 (1 ms total)[----------] 2 tests from EuclideanLossLayerTest/1, where TypeParam = caffe::CPUDevice&double&[ RUN
] EuclideanLossLayerTest/1.TestGradient[
OK ] EuclideanLossLayerTest/1.TestGradient (0 ms)[ RUN
] EuclideanLossLayerTest/1.TestForward[
OK ] EuclideanLossLayerTest/1.TestForward (0 ms)[----------] 2 tests from EuclideanLossLayerTest/1 (0 ms total)[----------] Global test environment tear-down[==========] 1054 tests from 146 test cases ran. (37419 ms total)[ PASSED ] 1054 tests.&安装python和piproot@k-Lenovo:~/caffe# python --versionPython 2.7.6&pip是专门用于安装python各种依赖库的,所以我们这里安装一下pip1.5.6& /s/1cfsHv4root@k-Lenovo:~# wget https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz-- 14:40:36-- https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gzResolving pypi.python.org (pypi.python.org)... 103.245.224.223Connecting to pypi.python.org (pypi.python.org)|103.245.224.223|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 6K) [application/octet-stream]Saving to: &pip-1.5.6.tar.gz&100%[===================================================&] 938,120
14:40:40 (294 KB/s) - &pip-1.5.6.tar.gz& saved [120]&root@k-Lenovo:~# cd pip-1.5.6root@k-Lenovo:~/pip-1.5.6# lsAUTHORS.txt docs
MANIFEST.in pip.egg-info PROJECT.txt setup.cfgCHANGES.txt LICENSE.txt pip
README.rst
setup.py&root@k-Lenovo:~/pip-1.5.6# sudo python setup.py installTraceback (most recent call last): File "setup.py", line 6, in &module&
from setuptools import setup, find_packagesImportError: No module named setuptools&有些电脑可能会提示 no moudle name setuptools 的错误,这是没有安装setuptools的原因。那就需要先安装一下setuptools, 到https://pypi.python.org/packages/source/s/setuptools/setuptools-19.2.tar.gz&下载安装包setuptools-19.2.tar.gz,然后解压执行/s/1dFx31Axroot@k-Lenovo:~# wget https://pypi.python.org/packages/source/s/setuptools/setuptools-19.2.tar.gz-- 14:44:07-- https://pypi.python.org/packages/source/s/setuptools/setuptools-19.2.tar.gzResolving pypi.python.org (pypi.python.org)... 103.245.224.223Connecting to pypi.python.org (pypi.python.org)|103.245.224.223|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 7K) [application/octet-stream]Saving to: &setuptools-19.2.tar.gz&100%[===================================================&] 641,777
14:44:11 (287 KB/s) - &setuptools-19.2.tar.gz& saved [777]&root@k-Lenovo:~# lscaffe
setuptools-19.2caffe.tar opencv.tar pip-1.5.6.tar.gz setuptools-19.2.tar.gzroot@k-Lenovo:~# cd setuptools-19.2root@k-Lenovo:~/setuptools-19.2# lsbootstrap.py
ez_setup.py msvc-build-launcher.cmd release.py setuptools.egg-infoCHANGES.txt
launcher.c
testsconftest.py
pkg_resources
tox.inidocs
MANIFEST.in pytest.ini
setup.pyeasy_install.py _markerlib
README.txt
setuptools&root@k-Lenovo:~/setuptools-19.2# sudo python setup.py install&root@k-Lenovo:~# cd pip-1.5.6root@k-Lenovo:~/pip-1.5.6# sudo python setup.py install&安装pyhon接口依赖库在caffe根目录的python文件夹下,有一个requirements.txt的清单文件,上面列出了需要的依赖库,按照这个清单安装就可以了。在安装scipy库的时候,需要fortran编译器(gfortran),如果没有这个编译器就会报错,因此,我们可以先安装一下。首先回到caffe的根目录,然后执行安装代码:&root@k-Lenovo:~/pip-1.5.6# cd ~/cafferoot@k-Lenovo:~/caffe# sudo apt-get install gfortran&root@k-Lenovo:~/caffe# cd python/root@k-Lenovo:~/caffe/python# lscaffe classify.py CMakeLists.txt detect.py draw_net.py requirements.txtroot@k-Lenovo:~/caffe/python# for req in $(cat requirements.txt); do sudo pip install $ done&root@k-Lenovo:~/caffe/python# cd ..root@k-Lenovo:~/caffe# lsbuild
CONTRIBUTORS.md examples
Makefile.config
README.mdcaffe.cloc
Makefile.config.example scriptscmake
distribute
INSTALL.md matlab
srcCMakeLists.txt
toolsCONTRIBUTING.md docs
pythonroot@k-Lenovo:~/caffe# sudo pip install -r python/requirements.txt&编译python接口首先,将caffe根目录下的python文件夹加入到环境变量打开配置文件bashrc&root@k-Lenovo:~/caffe# sudo vi ~/.bashrc&export PYTHONPATH=/root/caffe/python:$PYTHONPATH #追加到最后&root@k-Lenovo:~/caffe/python# sudo ldconfig&root@k-Lenovo:~/caffe# sudo make pycaffeCXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpptouch python/caffe/proto/__init__.pyPROTOC (python) src/caffe/proto/caffe.proto&查看 python/caffe/ 目录下,除了原先的一堆py后缀文件,现在多出了一堆pyc后缀文件/root/caffe/python/cafferoot@k-Lenovo:~/caffe/python/caffe# cd ..root@k-Lenovo:~/caffe/python# lscaffe classify.py CMakeLists.txt detect.py draw_net.py requirements.txtroot@k-Lenovo:~/caffe/python# pythonPython 2.7.6 (default, Jun 22 :13) [GCC 4.8.2] on linux2Type "help", "copyright", "credits" or "license" for more information.&&& import caffecaffe/pycaffe.py:13: RuntimeWarning: to-Python converter for boost::shared_ptr&caffe::Net&float& & second conversion method ignored. from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \caffe/pycaffe.py:13: RuntimeWarning: to-Python converter for boost::shared_ptr&caffe::Blob&float& & second conversion method ignored. from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \caffe/pycaffe.py:13: RuntimeWarning: to-Python converter for boost::shared_ptr&caffe::Solver&float& & second conversion method ignored. from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \/usr/local/lib/python2.7/dist-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')&&& &root@k-Lenovo:~/caffe/python# cd caffe/root@k-Lenovo:~/caffe/python/caffe# ls_caffe.cpp
classifier.pyc detector.pyc __init__.py
test_caffe.so
coord_map.py
__init__.pyc net_spec.py
pycaffe.pyclassifier.py detector.py
net_spec.pyc pycaffe.pyc&安装jupyter学会了python还不行,还得学习一下ipython,后者更加方便快捷,更有自动补全功能。而ipython notebook是ipython的最好展现方式。最新的版本改名为jupyter notebook,我们先来安装一下。&root@k-Lenovo:~/caffe/python# sudo pip install jupyter&安装成功后,运行notebookroot@k-Lenovo:~/caffe/python# jupyter notebook&
、 、 、 、 、}

我要回帖

更多关于 project做什么的 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信