参考:http://www.cnblogs.com/go-better/p/7161006.html 注意事项: Makefile.config文件中,INCLUDE_DIRS和LIBRARY_DIRS根据实际情况填写。(推荐)如果使用了anaconda的python作为默认的python环境,则这两项应该改为:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /home/smiles/anaconda2/include /home/smiles/anaconda2/include LIBRARY_DIRS := $(PYTHON_LIB) /home/smiles/anaconda2/lib /usr/lib /usr/lib/x86_64-linux-gnu /home/smiles/anaconda2/lib其中,INCLUDE_DIRS需要添加python的include路径和hdf5.h,hdf5_hl.h所在的路径;LIBRARY_DIRS除了默认需要添加的路径外,还需添加python的lib所在路径,以及libhdf5.so所在路径。
此外,变异caffe的python接口,还需安装相关的python包,进入/caffe/python/requirements.txt所在的路径,打开终端,执行以下命令:
for req in $(cat requirements.txt); do pip install $req; done之前看过OpenBlas的介绍,这个主要是国人开发与维护的矩阵运算库,目前来说应该是最快的。 参考:https://www.cnblogs.com/llxrl/p/5292119.html
手动从source安装 1. 下载OpenBLAS并编译
1 git clone https://github.com/xianyi/OpenBLAS.git 2 cd OpenBLAS 3 make -j8 4 sudo make PREFIX=/usr/local/OpenBLAS install2.修改Caffe配置文件以下几行
# open for OpenBlas BLAS := open # Custom (MKL/ATLAS/OpenBLAS) include and lib directories. # Leave commented to accept the defaults for your choice of BLAS # (which should work)! BLAS_INCLUDE := /usr/local/OpenBLAS/include BLAS_LIB := /usr/local/OpenBLAS/lib3.添加环境变量
在 ~/.bashrc 末尾加上 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/OpenBLAS/lib/ 然后source ~/.bashrc注:直接安装在/usr/local 下应该就不需要添加环境变量
4.编译Caffe
make all -j16 make test -j16 make runtest –j16 # 不成功 make runtest # 成功5.可在环境变量中设置OpenBLAS所使用的CPU线程数
export OPENBLAS_NUM_THREADS=4可能会出现错误:编译 pycaffe时报错:fatal error: numpy/arrayobject.h没有那个文件或目录 原因:在Makefile文件里面,设置的python为系统自带的python的路径,而这个路径里面是没有numpy的。 解决:
sudo apt-get install python-numpy make pycaffe -j8之前装的caffe-ssd一直用的是atlas矩阵处理库,这次试了openblas的安装,特此记录一下整个变异安装过程
可以写一个脚本来自动执行安装步骤:
echo Installing Caffe make all –j16 make test –j16 make runtest make pycaffe -j8