前提
已经安装好Anaconda、opencv2.4.8以及dlib
正文
- 安装依赖库(一):
$ 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
- 安装BLAS:
$ sudo apt-get install libatlas-base-dev
可以安装OpenBLAS 或 MKL,以提升CPU性能,但是要修改caffe中Makefile文件…
- 安装依赖库(二):
$ sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
- 下载Caffe
$ cd ~
$ git clone git://github.com/BVLC/caffe.git
- 编译Caffe
$ cd ~/caffe
$ cp Makefile.config.example Makefile.config
- 修改Makefile.config文件:去掉CPU_ONLY:= 1的注释
$ make all
$ make test
$ make runtest
存在问题解决
安装glog/gflags/lmdb
- 安装glog
wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz
tar zxvf glog-0.3.3.tar.gz
cd glog-0.3.3
./configure
make
sudo 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
sudo make install
- 安装lmdb
git clone https://github.com/LMDB/lmdb
cd lmdb/libraries/liblmdb
make
sudo make install
- 安装glog
glog安装由于无google访问权限,需离线下载安装就好
make sudo make install
- 安装lmdb
runtest报错:../../build/examples/lenet/convert_mnist_data.bin: error while loading shared libraries: libglog.so.0: cannot open shared object file: No such file or directory
解决,在runtest之前修改路径如下:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
配置pycaffe
- 安装依赖库:
$ sudo apt-get install python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags Cython ipython
$ sudo apt-get install protobuf-c-compiler protobuf-compiler
- 编译
$ cd ~/caffe
$ make pycaffe
- 添加~/caffe/Python到$PYTHONPATH:
$ sudo gedit /etc/profile
- 末尾添加:
export PYTHONPATH=/实际path/caffe/python:$PYTHONPATH
$ source /etc/profile
- 测试是否可以引用:
$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe