本文参考了:https://blog.csdn.net/muzilinxi90/article/details/53673184
https://blog.csdn.net/u013989576/article/details/56677749
https://blog.csdn.net/wuzuyu365/article/details/52430657
本文实现的是为虚拟机里的Ubuntu系统搭建caffe框架,因为电脑配置有限,只能实现CPU的架构。
一、安装库
在命令行模式下执行
sudo apt-get install libprotobuf-dev
sudo apt-get install libleveldb-devsudo apt-get install libsnappy-dev
sudo apt-get install libopencv-dev
sudo apt-get install libhdf5-serial-dev
sudo apt-get install protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libatlas-base-dev
建立python接口
sudo apt-get install python-dev
安装一些依赖库
sudo apt-get install libgflags-dev
sudo apt-get install libgoogle-glog-dev
sudo apt-get install liblmdb-dev
二、下载caffe
首先安装git
sudo apt-get install git
下载caffe
git clone https://github.com/BVLC/caffe.git
切换到caffe下的python文件,下载python依赖库
sudo apt-get install python-pip
for req in $(cat requirements.txt); do pip install $req; done
三、编译caffe
到Caffe文件夹中,拷贝一份Makefile.config.example并重命名成Makefile.config,修改该配置文件:
cp Makefile.config.example Makefile.config
使用文本编辑器更改Makefile.config,命令如下:
sudo gedit Makefile.config
把CPU_ONLY:=1前面的注释去掉
还要把#Whatever else you find you need goes here.处要改成下面这样:
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
设置成这样后,执行下面的命令
sudo make pycaffe 发现报错和numpy有关。设置Makefile.config的路径。把下面的路径
# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include
更改成下面的格式
# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/dist-packages/numpy/core/include
这时再执行一遍 sudo make pycaffe,如果发现还报错。则在caffe下的python执行下面的命令
sudo apt-get install python-numpy
随后 sudo make pycaffe
如果还不行则执行下面的命令
import numpy as np
np.get_include()
再不行,就没有办法了。
接着执行下面这些命令
sudo make pycaffe
sudo make all
sudo make test
sudo make runtest
所有测试都通过了就说明安装好了
四、测试python接口是否安装好
切换到caffe目录下的python文件夹,进入Python环境后,输入下面命令
import caffe
如果没有报错,则说明安装完成。如果报错,打开配置文件bashrc:命令如下:
sudo gedit ~/.bashrc
在文件的最后面添加:export PYTHONPATH=/home/shine/caffe/python:$PYTHONPATH
重新执行上述命令便可以了。
至此caffe框架便搭建完成。