Ubuntu16.04下配置caffe(仅CPU)

来源:互联网 发布:好看的网络剧 编辑:程序博客网 时间:2024/05/17 03:37

第二次配置caffe环境,依旧把之前犯过的错误重新走了一遍,不会配置的地方还是忘了,所以打算通过博客记录下来,方便以后学习使用。

1.安装依赖包

$ sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler$ sudo apt-get install --no-install-recommends libboost-all-dev$ sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev$ sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

注:如果提示”安装无法定位软件包”,可以尝试sudo apt-get update命令

2.安装caffe

$ cd ~$ git clone git://github.com/BVLC/caffe.git

3.编译caffe

$ cd caffe$ cp Makefile.config.example Makefile.config (复制一份Makefile.config文件)

在Makefile.config文件中把CPU_ONLY := 1的注释给去掉,就是去掉前面的#号

接下来在caffe根目录下执行下面命令

$ make all

在这个命令后,我遇到了一个报错信息,

./include/caffe/util/hdf5.hpp:6:18: fatal error: hdf5.h: No such file or directory

这是hdf5路径问题造成的,可以通过下面命令来获得hdf5的路径,

$ sudo find / -name hdf5.h 

我找到的hdf5.h的路径为:/usr/include/hdf5/serial/hdf5.h,于是在makefile.config文件中,把文件改成下面所示:

再执行一遍上述命令,继续报错,这次是/usr/bin/ld: cannot find -lhdf5
于是同上面一个处理 去找libhdf5.so
配置文件改为:

LIBRARY_DIRS := $(PYTHON_LIB) /usr/lib/x86_64-linux-gnu/hdf5/serial \            /usr/local/lib /usr/lib
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/include/hdf5/serial \            /usr/local/include
/usr/bin/ld: cannot find -lcblas/usr/bin/ld: cannot find -latlas

解决

sudo apt-get install libatlas-base-dev

接着执行下面命令:

make test

最后,

$ make runtest

4.编译python接口

安装pip

$ sudo apt-get install python-pip

执行安装依赖
根据caffe/python目录下的requirements.txt中列出的清单安装即可。
fortran编译器(gfortran)使为了安装scipy,否则会报错。

cd ~/caffesudo apt-get install gfortrancd ./pythonfor req in $(cat requirements.txt); do pip install $req; done

回到caffe根目录

sudo pip install -r python/requirements.txt

编译pycaffe接口

make pycaffe -j8

此时报错

python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: 没有那个文件或目录

于是,输入如下命令即可

sudo apt-get install python-numpy

在配置过程中会遇到各种问题,各种报错,最有效的办法就是百度啦。感谢以下博客
参考博客:
http://blog.csdn.net/striker_v/article/details/51615197
http://blog.csdn.net/u011762313/article/details/47262549
http://www.cnblogs.com/xuanxufeng/p/6016945.html

1 0