本文主要是介绍【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路径
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
这篇关于【Caffe】Linux配置Pycaffe的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!