1. 程式人生 > >Ubuntu14.04 上配置Caffe

Ubuntu14.04 上配置Caffe

安裝opencv

詳見:Ubuntu14.04安裝OpenCV3.0
注:opencv必須安裝,且版本為>=2.4或3.0

安裝依賴庫(二)

$ sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

下載Caffe

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

修改

如果安裝的是opencv3.0需要做以下修改: a、修改caffe目錄下的Makefile檔案,在
[code]LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb boost_system hdf5_hl hdf5 m \
opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
處加入後面的opencv_imgcodecs,因為opencv3.0.0把imread相關函式放到imgcodecs.lib中了(原來是imgproc.lib)

b、修改caffe/examples/cpp_classification/classification.cpp檔案,加入:
#include <opencv2/imgproc/types_c.h>
#include <opencv2/objdetect/objdetect_c.h>
否則會出現”CV_BGR2GRAY”的錯誤

編譯Caffe

$ cd ~/caffe
$ cp Makefile.config.example Makefile.config
修改
修改Makefile.config檔案:去掉CPU_ONLY:= 1的註釋 
即為,caffe在執行時,採用CPU計算。如果不註釋掉,即為預設的GPU,GPU計算速度約為CPU的四倍。GPU計算必須安裝CUDA,而且對顯示卡有一定的要求。
$ make all
$ make test
$ make runtest

配置pycaffe:

a、安裝依賴庫:
$ 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

b、編譯:
$ cd ~/caffe
$ make pycaffe

c、新增~/caffe/python到$PYTHONPATH:
$ sudo gedit /etc/profile
# 末尾新增: export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH
#export PYTHONPATH=自己caffe資料夾下的python路徑,一定要是自己的路徑!!!
# 用完整路徑,不要用~
$ source /etc/profile 
#使之生效

d、測試是否可以引用:
[code]$ 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
>>>