赞
踩
我会陆续将最近学习过程中,配置各平台caffe等AI框架开发环境的经验写下来,一来为了巩固所学,二来让后来者少走弯路,今天更新第一期,关于如何在ARM开发板上编译caffe。
系统环境:
Debian10
MSM8996(QCOM ARM处理器)
sudo vim /etc/apt/source.list
修改source.list文件为如下内容:
deb http://mirrors.163.com/debian/ buster main non-free contrib
deb http://mirrors.163.com/debian/ buster-updates main non-free contrib
deb http://mirrors.163.com/debian/ buster-backports main non-free contrib
deb-src http://mirrors.163.com/debian/ buster main non-free contrib
deb-src http://mirrors.163.com/debian/ buster-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ buster-backports main non-free contrib
deb http://mirrors.163.com/debian-security/ buster/updates main non-free contrib
deb-src http://mirrors.163.com/debian-security/ buster/updates main non-free contrib
Download boost source code:
tar --bzip2 -xf boost_1_64_0.tar.bz2
cd boost_1_64_0
设置boost安装目录
./bootstrap.sh --prefix=/usr/local/boost_1_64_0 --with-libraries= system,filesystem,thread,python
本文档是我在学习如何配置ARM NN开发环境时所写,所以这里会针对ARM NN对boost的编译选项的要求,添加一些编译选项:
sudo ./b2 link=static cxxflags=-fPIC --with-filesystem --with-test --with-log --with-program_options --with-python
linaro@linaro-alip:~/workspace/ARM_NN/boost_1_64_0$ sudo ./b2 link=static cxxflags=-fPIC --with-filesystem --with-test --with-log --with-program_options --with-python
然后会打印根据我们上面命令出现的配置信息
Performing configuration checks
- 32-bit : no (cached)
- 64-bit : yes (cached)
- arm : yes (cached)
Building the Boost C++ Libraries.
- symlinks supported : yes (cached)
- native-atomic-int32-supported : yes (cached)
- native-syslog-supported : yes (cached)
- pthread-supports-robust-mutexes : yes (cached)
- compiler-supports-visibility : yes (cached)
- has_icu builds : no (cached)
- lockfree boost::atomic_flag : yes (cached)
Component configuration:
- atomic : not building
- chrono : not building
- container : not building
- context : not building
- coroutine : not building
- coroutine2 : not building
- date_time : not building
- exception : not building
- fiber : not building
- filesystem : building
- graph : not building
- graph_parallel : not building
- iostreams : not building
- locale : not building
- log : building
- math : not building
- metaparse : not building
- mpi : not building
- program_options : building
- python : building
- random : not building
- regex : not building
- serialization : not building
- signals : not building
- system : not building
- test : building
- thread : not building
- timer : not building
- type_erasure : not building
- wave : not building
我们主要关注上面的Component configuration
如:
- python : building
编译完成后会提示:
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/home/linaro/workspace/ARM_NN/boost_1_64_0
The following directory should be added to linker library paths:
/home/linaro/workspace/ARM_NN/boost_1_64_0/stage/lib
sudo ./b2 install
如果提示:
test_boost.cpp:1:10: fatal error: boost/regex.hpp: No such file or directory
#include <boost/regex.hpp>
很多网站解释说,出现上面的问题,可能是编译boost后并没有安装,也就是忘记加install选项了。
即使你再次执行sudo ./b2 install也白扯。
然并卵…
事实证明,这样完全解决不了问题!我们使用下述方法来解决该问题,一句话GCC没有找到库和文件
export C_INCLUDE_PATH=/usr/local/boost_1_64_0/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/usr/local/boost_1_64_0/include:$CPLUS_INCLUDE_PATH
export LD_LIBRARY_PATH=/usr/local/boost_1_64_0/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=/usr/local/boost_1_64_0/lib:$LIBRARY_PATH
其实,上面安装完成后,打印的log也提示了大家一定要将编译的链接路径加进去:
The following directory should be added to compiler include paths:
/home/linaro/workspace/ARM_NN/boost_1_64_0
The following directory should be added to linker library paths:
/home/linaro/workspace/ARM_NN/boost_1_64_0/stage/lib
这部分可以参考:
http://caffe.berkeleyvision.org/installation.html
简要步骤如下:
git clone https://github.com/BVLC/caffe.git
$ cp Makefile.config.example Makefile.config
中修改如下内容:
1. 如果你的电脑没有NVIDIA的GPU则需要将这个注释放开:CPU_ONLY := 1
2. 修改hdf5库的路径
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/aarch64-linux-gnu/hdf5/serial
3. PYTHON_INCLUDE
这个选项要根据你的python安装路径决定,如果选用anaconda的话,则需要设置ANACONDA_HOME以及对应的PYTHON_INCLUDE
由于ARM平台上暂时没有用到anaconda,所以这里没有对anaconda的路径进行重新配置。
make all -j4 编译全部模块
make test -j4 编译测试模块
make runtest -j4 运行测试
make pycaffe -j4 编译python库
unknown file: Failure
C++ exception with description "locale::facet::_S_create_c_locale name not valid" thrown in the test fixture's constructor.
*** Aborted at 1522312851 (unix time) try "date -d @1522312851" if you are using GNU date ***
PC: @ 0x0 (unknown)
*** SIGSEGV (@0x0) received by PID 7394 (TID 0xffff7b4d5440) from PID 0; stack trace: ***
@ 0xffff7c8076c0 ([vdso]+0x6bf)
@ 0x11bc49c20 (unknown)
@ 0x11bc4f484 (unknown)
@ 0x11bc492d8 (unknown)
@ 0x11bc493d0 (unknown)
@ 0x11bc498a0 (unknown)
@ 0x11bc499dc (unknown)
@ 0x11b9ec614 (unknown)
@ 0xffff7b66d624 __libc_start_main
Segmentation fault
Makefile:532: recipe for target 'runtest' failed
make: *** [runtest] Error 139
解决方案:
~/.bashrc末尾添加新的环境变量:
export LC_ALL="C"
再次执行make runtest就没问题了
sudo apt-get install python-skimage
则说明你的PYTHONPATH环境变量配置不对,本质原因可能是没有编译pycaffe, 因此执行make pycaffe进行编译
stackflow上有云:
a)You need to have _caffe.so in caffe/python/caffe. If not, run 'make pycaffe' in caffe source folder.
b)You need to add only caffe/python to$PYTHONPATH but not caffe/python/caffe as mentioned in documentation. I don'tknow why adding caffe/python/caffe causes the error, though.
第一次在编译boost的时候没有加–with-python选项,所以没有生成python库:libboost_python.ap
sudo apt-get install python-protobuf
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。