【Caffe】Linux配置Pycaffe

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_VERSION := 3
# 根据实际的Python环境进行配置
PYTHON_INCLUDE := /usr/include/python2.7 \
                /usr/lib/python3.5/dist-packages/numpy/core/include

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/python3.5/dist-packages/numpy/core/include

修改为:

PYTHON_INCLUDE := .env/versions/env270/include/python2.7 \
                .env/versions/env270/lib/python2.7/dist-packages/numpy/core/include

其中路径前缀需要根据自己实际的环境进行配置。

PYTHON_LIB:=/usr/lib

修改为:

PYTHON_LIB:=.env/versions/env270/lib

猜你喜欢

转载自blog.csdn.net/twt520ly/article/details/80445432
今日推荐