1.caffe源碼
使用git
命令將github上caffe最新的代碼下載下來。
(1)安裝git:
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git
查看版本信息:
git --version
(2)下載源代碼:
git clone https://github.com/BVLC/caffe.git
2. caffe配置
在源碼的第一層目錄中,有一個文件Makefile.config.example
。首先進行文件拷貝:
cp Makefile.config.example Makefile.config
然後對Makefile.config
進行修改:
# 如果使用CUDNN的話,需要改爲下面的形式
USE_CUDNN := 1
# 如果是在CPU上進行開發,需要改爲下面的形式
CPU_ONLY := 1
# 根據系統安裝好的OpenCV版本進行設置,必須是系統環境下的OpenCV路徑
OPENCV_VERSION := 3
# 根據實際的Python環境進行配置
PYTHON_INCLUDE := /usr/include/python3.5 \
/usr/lib/python3.5/dist-packages/numpy/core/include
# 使用python的caffe層
WITH_PYTHON_LAYER := 1
3.caffe編譯
j
代表多線程編譯。
make all -j8
make alltest -j8
編譯python版本的caffe
make pycaffe
然後配置一下環境變量:
$sudo gedit ~/.bashrc
添加: export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH
$sudo source ~/.bashrc
4.問題
1.error: hdf5.h: No such file or directory
解決方案:將/usr/include/hdf5/serial
添加到文件Makefile.config的INCLUDE_DIRS
中
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
修改爲:
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
但是待會會出現一個新的錯誤,找不到-lhdf5
和-lhdf5_hl
文件。
修改Makefile文件:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
修改爲:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
2.如果是虛擬環境的話,如何配置python?
修改Makefile.config:
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include
修改爲:
PYTHON_INCLUDE := ~/.pyenv/versions/3.6.0/include \
~/.pyenv/versions/3.6.0/include/python3.6m \
~/.pyenv/versions/env360/lib/python3.6/site-packages/numpy/core/include
其中路徑前綴需要根據自己實際的環境進行配置。
PYTHON_LIB:=/usr/lib
修改爲:
PYTHON_LIB:= ~/.pyenv/versions/env360/lib