Raspberry Pi zero w安装ncnn

一、介绍

本文将介绍如何在树莓派zero w上安装腾讯开发的ncnn框架。对更多的信息可以从ncnn官方github上去获取:https://github.com/Tencent/ncnn

注:本文介绍的安装版本是C++的,不适用于python。

二、检查版本

 1.检查操作系统版本[1]

 2.检查gcc编译器版本[1]

三、扩大交换空间

1.交换空间必须足够大以支持building ncnn[1]

2.检查交换空间[1]

 3.使用zram扩大交换空间[1]

# remove the old dphys version
$ sudo /etc/init.d/dphys-swapfile stop
$ sudo apt-get remove --purge dphys-swapfile
# install zram
$ sudo wget -O /usr/bin/zram.sh https://raw.githubusercontent.com/novaspirit/rpi_zram/master/zram.sh
# set autoload
$ sudo nano /etc/rc.local
# add the next line before exit 0
/usr/bin/zram.sh &
# save with <Ctrl+X>, <Y> and <Enter>
$ sudo chmod +x /usr/bin/zram.sh
$ sudo nano /usr/bin/zram.sh
# alter the limit with * 2
mem=$(( ($totalmem / $cores)* 1024 * 2))
# save with <Ctrl+X>, <Y> and <Enter>
$ sudo reboot

四、安装

1.如果opencv没有安装,先安装opencv[2]

opencv安装教程:https://qengineering.eu/install-opencv-4.4-on-raspberry-pi-4.html

2.安装依赖,下载ncnn[2]

# check for updates
$ sudo apt-get update
$ sudo apt-get upgrade
# install dependencies
$ sudo apt-get install cmake wget
$ sudo apt-get install libprotobuf-dev protobuf-compiler
# download ncnn
$ git clone --depth=1 https://github.com/Tencent/ncnn.git

3.修改makefile文件[3][4][5][6]

$ cd ncnn/toolchains/
$ sudo nano arm-linux-gnueabihf.toolchain.cmake

这步如果配置错了,make也可能成功,但是当想要使用ncnn的时候,会出现Illegal instruction的错误。这个错误的出现是因为要被执行的代码被编译在一个不同的架构上了,树莓派zero w使用ARM架构。[7]

4.安装ncnn[2][8]

​# go to ncnn directory
$ cd ..
# install ncnn
$ cd ncnn
$ mkdir build
$ cd build
# build 32-bit ncnn
$ cmake -D NCNN_DISABLE_RTTI=OFF \
        -D CMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf.toolchain.cmake ..
$ make -j$(nproc)
$ make install
# copy output to dirs
$ sudo mkdir /usr/local/lib/ncnn
$ sudo cp -r install/include/ncnn /usr/local/include/ncnn
$ sudo cp -r install/lib/libncnn.a /usr/local/lib/ncnn/libncnn.a

参考文献

[1] https://qengineering.eu/install-raspberry-64-os.html

[2] https://qengineering.eu/install-ncnn-on-raspberry-pi-4.html

[3] https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-arm-cortex-a-family-with-cross-compiling

[4] https://github.com/Tencent/ncnn/blob/master/toolchains/arm-linux-gnueabihf.toolchain.cmake

[5] https://github.com/Tencent/ncnn/issues/1554

[6] https://raspberrypi.stackexchange.com/questions/91475/crosscompiling-exact-archictecture-for-all-models

[7] https://stackoverflow.com/questions/37748358/python-illegal-instruction-on-raspberry-pi-zero

[8] https://medium.com/trueface-ai/trueface-tutorials-how-to-cross-compile-popular-computer-vision-c-frameworks-for-raspberry-pi-4-afcbe2dcc302

注:转载请注明出处

微信公众号

喜欢我的还可以关注我的微信公众号:傻猫爱学习,里面有你意想不到的惊喜哦!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值