Ubuntu 14 Caffe安裝(無GPU)

weixin_33727510發表於2016-12-03

前提

已經安裝好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

相關文章