使用git命令将github上caffe最新的代码下载下来。
(1)安装git:
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git
- 1
- 2
- 3
查看版本信息:
git --version
- 1
(2)下载源代码:
git clone https://github.com/BVLC/caffe.git
- 1
2. caffe配置
在源码的第一层目录中,有一个文件Makefile.config.example
。首先进行文件拷贝:
cp Makefile.config.example Makefile.config
- 1
然后对Makefile.config
进行修改:
# 如果使用CUDNN的话,需要改为下面的形式
USE_CUDNN := 1
# 如果是在CPU上进行开发,需要改为下面的形式
CPU_ONLY := 1
# 根据系统安装好的OpenCV版本进行设置
OPENCV_VERSION := 3
# 根据实际的Python环境进行配置
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python3.5/dist-packages/numpy/core/include
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
3.caffe编译
j代表多线程编译。
make all -j8
make alltest -j8
- 1
- 2
编译python版本的caffe
make pycaffe
- 1
然后配置一下环境变量:
$sudo gedit ~/.bashrc
添加: export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH
$sudo source ~/.bashrc
- 1
- 2
- 3
- 4
- 5
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
- 1
- 2
修改为:
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
- 1
- 2
但是待会会出现一个新的错误,找不到-lhdf5
和-lhdf5_hl
文件。
修改Makefile文件:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
- 1
修改为:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
- 1
- 2
2.如果是虚拟环境的话,如何配置python?
修改Makefile.config:
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python3.5/dist-packages/numpy/core/include
- 1
- 2
修改为:
PYTHON_INCLUDE := .env/versions/env270/include/python2.7 \
.env/versions/env270/lib/python2.7/dist-packages/numpy/core/include
- 1
- 2
其中路径前缀需要根据自己实际的环境进行配置。
PYTHON_LIB:=/usr/lib
- 1
修改为:
PYTHON_LIB:=.env/versions/env270/lib
- 1