您的位置:首页 > Web前端

虚拟机ubuntu16.04 安装caffe

2017-04-26 13:35 267 查看
1.基本依赖
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compilersudo apt-get install
--no-install-recommends libboost-all-dev
2.安装blas(基础线性代数子程序库,里面拥有大量已经编写好的关于线性代数运算的程序)
sudo apt-get install libatlas-base-dev
3.安装python
sudo apt-get install
 python-dev

4.在虚拟加上用的virtual box显卡驱动。没法用 GPU。CUDA是GPU模式使用的

5.ubuntu 16.04 不存在。14.04存在
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
6.下载 caffe源代码
git clone https://github.com/BVLC/caffe.git 
b1b4

7.进入caff/python 安装python依赖包
for req in $(cat requirements.txt); do pip install $req; done

其实直接
pip install -r requirements.txt 也是 可以的

8.编译(make)
cp Makefile.config.example Makefile.config

#修改配置。如果需要GPU模式。则需要cuDNN 
是否需要
因为CPU MODE, 所以在CPU_ONLY := 1前面的#要去掉.
加上hdf5路径 否则报路径不存在
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial  
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial  

编译caffe 的 python 操作库
make pycaffe

编译 MATLAB
#make matcaffe

要确保 python 和 matlab的路径都在Makefile.config 里面。这里不装MATLAB。只装python

make all
make testmake runtest

小插曲:
在虚拟机里安装碰到这样的问题:
ln: failed to create symbolic link 'build': Read-only file system
Makefile:562: recipe for target '.build_release/.linked' failed
make: *** [.build_release/.linked] Error 1
源代码在虚拟机 和 宿主机的共享文件夹里面 。不能建立符号链接。把源码移到其他位置就好了

下面的错误是需要在 INCLUDE_DIRS 加上
/usr/include/hdf5/serial

LIBRARY_DIRS 加上 /usr/lib/x86_64-linux-gnu/hdf5/serial

src/caffe/net.cpp:8:18: fatal error: hdf5.h: No such file or directory
compilation terminated.
Makefile:581: recipe for target '.build_release/src/caffe/net.o' failed
make: *** [.build_release/src/caffe/net.o] Error 1

如果报这样的错误:
python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directory
compilation terminated.
Makefile:507: recipe for target 'python/caffe/_caffe.so' failed
make: *** [python/caffe/_caffe.so] Error 1

则是numpy没有安装到位:
apt-get install python-numpy
或者是 Makefile.config 中numpy的路径配置错误 。pip安装的numpy路径和使用 apt-get 安装的numpy路径是不一样的。pip一般是 :/usr/local/lib/python2.7/dist-packages
而linux安装的一般在:/usr/local/lib/python2.7/dist-packages

注:有显卡,gpu的安装参考
http://www.linuxdiyf.com/linux/24659.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  caffe