在计算机视觉和深度学习领域,NCNN(Netural Network Computer Vision)是一个轻量级的神经网络计算框架,被广泛应用于各类嵌入式设备和移动平台。今天,让我们一同跟随共创社团队的步伐,揭秘他们如何进行NCNN的交叉编译,并在ELF 1开发板上演绎实践,以此验证模型推理性能。
1、从GitHub下载NCNN源码:https://github.com/Tencent/ncnn
2、将ncnn-master.zip拷贝到开发环境的/home/elf/work目录下并解压:
elf@ubuntu:~/work$ unzip ncnn-master.zip
3、配置CMake:
elf@ubuntu:~/work$ cd ncnn-master/toolchains/
elf@ubuntu:~/work/ncnn-master/toolchains$ vi arm-poky-linux-gnueabi.cmake
将下面的内容添加到arm-poky-linux-gnueabi.cmake文件中:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER "arm-poky-linux-gnueabi-gcc")
set(CMAKE_CXX_COMPILER "arm-poky-linux-gnueabi-g++")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard --sysroot=/opt/fsl-imx-x11/4.1.15-2.0.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi")
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard --sysroot=/opt/fsl-imx-x11/4.1.15-2.0.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi")
# cache flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags")
4、编译:
elf@ubuntu:~/work/ncnn-master$ mkdir build
elf@ubuntu:~/work/ncnn-master$ cd build/
elf@ubuntu:~/work/ncnn-master/build$ . /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
elf@ubuntu:~/work/ncnn-master/build$ cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-poky-linux-gnueabi.cmake -DNCNN_SIMPLEOCV=ON -DNCNN_BUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release ..
elf@ubuntu:~/work/ncnn-master/build$ make
5、将编译完成得到的benchmark文件夹(build目录下)和项目文件夹下的benchmark文件夹打包并放到U盘里:
elf@ubuntu:~/work/ncnn-master/build$ tar cvjf benchmark.tar.bz2 benchmark/ ../benchmark/
6、将U盘插入到ELF 1开发板上,拷贝压缩包到/home/root路径下并解压:
root@ELF1:~# cp /run/media/sda1/benchmark.tar.bz2 .
root@ELF1:~# tar xvf benchmark.tar.bz2
7、测试:
root@ELF1:~# cd benchmark/
root@ELF1:~/benchmark# ./benchncnn
阅读全文