参考网站:
http://caffe.berkeleyvision.org/install_yum.html(bvlc官网说明)
https://www.zybuluo.com/hanxiaoyang/note/364680
http://blog.sina.com.cn/s/blog_990865340102vewt.html (主要参考)
http://stackoverflow.com/questions/31395729/how-to-enable-multithreading-with-caffe
(多核训练)
redhat配置caffe
1.安装依赖
- $ sudo yum install protobuf-devel
- $ sudo yum install level-devel
- $ sudo yum install snappy-devel
- $ sudo yum install opencv-devel
- $ sudo yum install boost-devel
- $ sudo yum install hdf5-devel
- $ sudo yum install atlas-devel
- $ sudo yum install gflags-devel
- $ sudo yum install glog-devel
- $ sudo yum install lmdb-devel
某些源可能找不到
可以先安装以下命令
- $ sudo yum install epel-release
其中glog仍然找不到,则需要进行手动安装
- # glog
- wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/google-glog/glog-0.3.3.tar.gz
- tar zxvf glog-0.3.3.tar.gz
- cd glog-0.3.3
- ./configure
- make && make install
2.安装opecv-2.4.13
见redhat配置opencv
3.编译配置boost_1_59_0
- Tar –zxvf boost_1_59_0.tar.gz
- cd boost boost_1_59_0
- ./boostrap.sh
- ./b2
- sudo ./b2 install –prefix=/usr/local/boost_hy
配置参数
/usr/local/include
/usr/local/lib
可以将配置文件写到
- echo "/usr/local/lib" >> /etc/ld.so.conf
- ldconfig
3.下载源码
- $ git clone https://github.com/bvlc/caffe.git
- $ cd caffe/
- $ mv Makefile.config.example Makefile.config
4.修改Makefile.config
CPU_ONLY := 1
BLAS := atlas
BLAS_INCLUDE := /usr/include/atlas
BLAS_LIB := /usr/lib64/atlas
BOOST_ROOT := /usr/local/boost_hy
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/local/boost_hy/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib64 /usr/local/boost_hy/lib
5.编译
- make all
问题1:
./include/caffe/util/io.hpp: In function 'void caffe::MakeTempDir(std::string_)':
./include/caffe/util/io.hpp:27: error: 'temp_directory_path' is not a member of 'boost::filesystem'
./include/caffe/util/io.hpp:29: error: 'unique_path' is not a member of 'boost::filesystem'
应该是boost版本问题,要1.59.0以上的。但说明是1.54以上版本就行。
明明装了1.59版本的boost还是不行。
- rpm –qa boost*
发现许多包还是1.41版本的,可能是系统依赖的包。因此,重新安装boost,指定安装路径,如果不指定的话,lib会放在 /usr/local/lib, include会放在/usr/local/include。
- ./b2 install –prefix=/usr/local/boost_hy
Boost_hy下回出现include和lib。
在caffe目录下Makefile.config中添加如下配置:
BOOST_BOOT:=/usr/local/boost_hy
INCLUDE_DIRS:=/usr/local/boost_hy/include
LIB_DIRS:=/usr/local/boost_hy/lib
https://groups.google.com/forum/#!topic/caffe-users/h_hXnUbrurk
https://github.com/BVLC/caffe/issues/3686
问题2:
使用命令
- sudo make all
时,出现以下问题:
.build_release/src/caffe/proto/caffe.pb.h:17:2: error: #error This file was generated by an older version of protoc which is
.build_release/src/caffe/proto/caffe.pb.h:18:2: error: #error incompatible with your Protocol Buffer headers. Please
.build_release/src/caffe/proto/caffe.pb.h:19:2: error: #error regenerate this file with a newer version of protoc.
/usr/bin/protoc –version发现是1.4.*版本的。而至少需要1.5版本的。
如果不用sudo的话,可能用到的是本目录下的protoc,
- make all //不要用sudo执行
问题3
/usr/bin/ld: skipping incompatible /usr/lib/libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for –lc
This typically arises due to an architecture mismatch - in this case it seems that the build system attempts to link a 64bit object files with a 32bit library
问题是64为系统编译,却到32位的lib包中去寻找,解决:
更改caffe目录下Makelist.config
将所有的/usr/lib都改为/usr/lib64
- make clean
- make all
终于编译成功,截图如下:
6. 训练mnist
问题:
[wuhairong@zhsw-ws02 caffe-master]$ make runtest .build_release/tools/caffe ERROR: flag 'tab_completion_word' was defined more than once (in files 'src/gflags_completions.cc' and '/home/wuhairong/gflags-master/src/gflags_completions.cc').make: *** [runtest] 错误 1
https://groups.google.com/forum/#!msg/caffe-users/bqDam0xuT3E/78wQnx3memAJ
gflags安装了两次,要将gflags文件卸载之后再安装。利用yum命令即可。
- sudo yum remove gflags
- sudo yum install gflags
然后重新编译caffe
- make clean
- make all
- make test
- make runtest
- make matcaffe
- make pycaffe
开始训练
在caffe目录下执行
- sh data/get_mnist.sh
- sh examples/mnist/create_mnist.h
注意:如果出现错误,可能是因为数据下载不正确。
- sh examples/mnist/train_lenet.sh
静候结果。。。
多核训练
http://stackoverflow.com/questions/31395729/how-to-enable-multithreading-with-caffe