1) 安装依赖库
sudo yum install protobuf-devel leveldb-devel snappy-devel hdf5-devel
sudo yum install gflags-devel glog-devel lmdb-devel
也可以通过下面方式安装:
# 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 # gflags wget https://github.com/schuhschuh/gflags/archive/master.zip unzip master.zip cd gflags-master mkdir build && cd build export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1 make && make install # lmdb git clone https://github.com/LMDB/lmdb cd lmdb/libraries/liblmdb make && make install
sudo yum install atlas
sudo yum install atlas-devel
有些包没有,已经放在了我的资源里面:
http://download.csdn.net/detail/sundongsdu/9827222
由于系统自带的python是2.6.6(通过python -V查看),但是caffe要求2.7及以上,所以需要升级python到2.7:
安装包在 http://download.csdn.net/detail/sundongsdu/9827574
# 解压缩tgz
tar zxvf Python-2.7.9.tgz
cd Python-2.7.9
# 指定-fPIC选项,否则Caffe编译过程会报错
./configure CFLAGS=-fPIC
# 开始编译 4线程
make -j4
# 用root权限安装
sudo make install
建立软连接,使系统默认的 python指向 python2.7
mv/usr/bin/python/usr/bin/python2.6.6
ln-s/usr/local/bin/python2.7/usr/bin/python
ln -s /usr/local/bin/python2.7 /usr/bin/python2.7
ln -s /usr/local/include/python2.7 /usr/include/python2.7
ln -s /usr/local/lib/python2.7 /usr/lib/python2.7
通过python -V查看已经升级到2.7.9
解决系统 Python 软链接指向 Python2.7 版本后,yum不兼容 问题,需要指定 yum 的Python版本:
#vi/usr/bin/yum
将文件头的#!/usr/bin/python改为:#!/usr/bin/python2.6.6
boost 和opencv版本太低需要重新手动安装:
要求Boost >= 1.55,OpenCV >= 2.4 including 3.0
如果已经安装了系统自带版本:
[lss@localhost liblmdb]$ rpm -q boost
boost-1.41.0-27.el6.x86_64
[lss@localhost liblmdb]$ rpm -q opencv
opencv-2.0.0-12.el6.x86_64
先卸载低版本:
[lss@localhost liblmdb]$ sudo rpm -e boost-devel
[lss@localhost liblmdb]$ sudo rpm -e boost
[lss@localhost liblmdb]$ sudo rpm -e opencv-devel
[lss@localhost liblmdb]$ sudo rpm -e opencv
高版本放在了我的资源里:
http://download.csdn.net/detail/sundongsdu/9827232
http://download.csdn.net/detail/sundongsdu/9827243
安装Boost
$ ./bootstrap.sh
$ ./b2$ sudo ./b2 install
安装opencv:
$unzipopencv-2.4.10.zip
$cdopencv-2.4.10
$mkdirbuild
$cdbuild
$cmake../-DCMAKE_BUILD_TYPE=RELEASE-DBUILD_EXAMPLES=ON-DBUILD_NEW_PYTHON_SUPPORT=ON-DINSTALL_PYTHON_EXAMPLES=ON
$make
$sudomakeinstall
2)安装caffe
从git下载caffe: https://github.com/BVLC/caffe
cd caffe-master/python,requirements.txt里面列出了依赖的python库:
Cython>=0.19.2
numpy>=1.7.1
scipy>=0.13.2
scikit-image>=0.9.3
matplotlib>=1.3.1
ipython>=3.0.0
h5py>=2.2.0
leveldb>=0.191
networkx>=1.8.1
nose>=1.3.0
pandas>=0.12.0
python-dateutil>=1.4,<2
protobuf>=2.5.0
python-gflags>=2.0
pyyaml>=3.10
Pillow>=2.3.0
six>=1.1.0
如果有网络可以在线安装:
sudo /usr/local/bin/pip install -r python/requirements.txt
如果需要离线安装,可以从https://pypi.python.org/pypi/ 下载相应的包如Cython-0.25.2.tar.gz,然后解包python setup.py install
离线安装包已经放在了:
http://download.csdn.net/detail/sundongsdu/9828335
http://download.csdn.net/detail/sundongsdu/9828329
配置Makefile.config:
- For cpu & GPU accelerated Caffe,no changes are needed.
- For cuDNN acceleration using NVIDIA’s proprietary cuDNN software,uncomment the
USE_CUDNN := 1
switch inMakefile.config
. cuDNN is sometimes but not always faster than Caffe’s GPU acceleration. - For cpu-only Caffe,uncomment
cpu_ONLY := 1
inMakefile.config
.
cp Makefile.config.example Makefile.config # Adjust Makefile.config (for example,if using Anaconda Python,or if cuDNN is desired)
make all make test make runtest
4) 编译pycaffe
修改Makefile.config,根据自己的python安装情况配置以下两行:
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/site-packages/numpy-1.12.1-py2.7-linux-x86_64.egg/numpy/core/include
然后执行make pycaffe
====================== 问题及方案 ============================
1) /usr/bin/ld: cannot find -lcblas
原因:缺少cblas库
解决方案:下载cblas.tgz
解压后根据README的要求进行设置:
ln -s Makefile.LINUX Makefile.in
在Makefile.in里设置BLLIB和CBLIB
BLLIB可以通过whereis查看:
whereis libblas.a
libblas: /usr/lib64/libblas.a /usr/lib64/libblas.so
因此设置为:
BLLIB = libblas.a
CBLIB = ../lib/cblas_$(PLAT).a
因此设置为:
BLLIB = /usr/lib64/libblas.a
CBLIB = /usr/lib64/libcblas.a
设置编译参数,加上-fPIC:CFLAGS = -O3 -DADD_ -fPIC
然后执行make all
然后查看:
[lss@localhost CBLAS]$ whereis libcblas.a
libcblas: /usr/lib64/libcblas.a
如果报/usr/bin/ld: cannot find -latlas,但是上面已经通过yum安装了atlas,查看以后发现在atlas子文件夹里面:
[root@localhost lib64]# find / -name libatlas.a
/usr/lib64/atlas/libatlas.a
所以可以拷贝或者软连接从/usr/lib64/atlas/libatlas.a到/usr/lib64/libatlas.a
2) [lss@localhost caffe-master]$ make runtest 时报一些库找不到,如:
.build_release/tools/caffe
.build_release/tools/caffe: error while loading shared libraries: libglog.so.0: cannot open shared object file: No such file or directory
.build_release/tools/caffe: error while loading shared libraries: libboost_filesystem.so.1.60.0: cannot open shared object file: No such file or directory
解决方案:
查看库是否已经存在,如
[lss@localhost bin]$ whereis libboost_filesystem.so.1.60.0
libboost_filesystem.so.1.60: /usr/local/lib/libboost_filesystem.so.1.60.0
因此修改库搜索路径即可:
sudo vi /etc/profile
在最后添加 export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH, 然后source使其生效。
3) ('ERROR: cython exec Failed. Is cython not in the path? ','[Errno 2] No such file or directory')
如果没有安装Cython,那么就先安装,如果安装了仍然报这个错,那应该是路径问题。
[lss@localhost bin]$ whereis cython
cython: /usr/local/bin/cython
[lss@localhost bin]$ sudo ln -s /usr/local/bin/cython /usr/bin/cython
参考:http://caffe.berkeleyvision.org/installation.html#compilation
原文链接:https://www.f2er.com/centos/377784.html