当前位置:   article > 正文

AI环境搭建系列2 ARM开发板编译安装caffe方法(ARM NN)_arm编译安装caffe

arm编译安装caffe

我会陆续将最近学习过程中,配置各平台caffe等AI框架开发环境的经验写下来,一来为了巩固所学,二来让后来者少走弯路,今天更新第一期,关于如何在ARM开发板上编译caffe。

系统环境:
    Debian10
    MSM8996(QCOM ARM处理器)
  • 1
  • 2
  • 3

1.更新源

sudo vim /etc/apt/source.list
  • 1

修改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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

2.安装boost

Download boost source code:

tar --bzip2 -xf boost_1_64_0.tar.bz2
cd boost_1_64_0
  • 1
  • 2

设置boost安装目录

./bootstrap.sh --prefix=/usr/local/boost_1_64_0 --with-libraries= system,filesystem,thread,python
  • 1

本文档是我在学习如何配置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
  • 1
  • 2

然后会打印根据我们上面命令出现的配置信息

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

我们主要关注上面的Component configuration
如:

    - python                   : building
  • 1

编译完成后会提示:


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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

如果提示:

    test_boost.cpp:1:10: fatal error: boost/regex.hpp: No such file or directory
    #include <boost/regex.hpp>
  • 1
  • 2

很多网站解释说,出现上面的问题,可能是编译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
  • 1
  • 2
  • 3
  • 4

其实,上面安装完成后,打印的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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

3.安装Caffe

这部分可以参考:

http://caffe.berkeleyvision.org/installation.html
  • 1

简要步骤如下:

1st step

git clone https://github.com/BVLC/caffe.git
$ cp Makefile.config.example Makefile.config
  • 1
  • 2

中修改如下内容:

1. 如果你的电脑没有NVIDIAGPU则需要将这个注释放开: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的路径进行重新配置。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

2nd step

make all -j4   编译全部模块
make test -j4  编译测试模块
make runtest -j4  运行测试
make pycaffe -j4  编译python库
  • 1
  • 2
  • 3
  • 4

4. 遇到的一些问题

4.1 make runtest报错

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

解决方案:
~/.bashrc末尾添加新的环境变量:

export LC_ALL="C"
  • 1

再次执行make runtest就没问题了

4.2 ImportError: No module named skimage.io

sudo apt-get install python-skimage

4.3 AttributeError: ‘module’ object has no attribute ‘bool_’

则说明你的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.
  • 1
  • 2
  • 3

第一次在编译boost的时候没有加–with-python选项,所以没有生成python库:libboost_python.ap

4.4 ImportError: No module named google.protobuf.internal

sudo apt-get install python-protobuf

References:

  1. https://developer.arm.com/technologies/machine-learning-on-arm/developer-material/how-to-guides/configuring-the-arm-nn-sdk-build-environment-for-caffe/setting-up-the-build-dependencies
  2. http://caffe.berkeleyvision.org/installation.html
  3. https://blog.csdn.net/xushungou/article/details/52853110
  4. http://valleylord.github.io/post/201601-boost-install/
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/864896
推荐阅读
相关标签
  

闽ICP备14008679号