在計(jì)算機(jī)視覺(jué)和深度學(xué)習(xí)領(lǐng)域,NCNN(Netural Network Computer Vision)是一個(gè)輕量級(jí)的神經(jīng)網(wǎng)絡(luò)計(jì)算框架,被廣泛應(yīng)用于各類嵌入式設(shè)備和移動(dòng)平臺(tái)。今天,讓我們一同跟隨共創(chuàng)社團(tuán)隊(duì)的步伐,揭秘他們?nèi)绾芜M(jìn)行NCNN的交叉編譯,并在ELF 1開(kāi)發(fā)板上演繹實(shí)踐,以此驗(yàn)證模型推理性能。
1、從GitHub下載NCNN源碼:https://github.com/Tencent/ncnn
2、將ncnn-master.zip拷貝到開(kāi)發(fā)環(huán)境的/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
將下面的內(nèi)容添加到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目錄下)和項(xiàng)目文件夾下的benchmark文件夾打包并放到U盤里:
elf@ubuntu:~/work/ncnn-master/build$ tar cvjf benchmark.tar.bz2 benchmark/ ../benchmark/
6、將U盤插入到ELF 1開(kāi)發(fā)板上,拷貝壓縮包到/home/root路徑下并解壓:
root@ELF1:~# cp /run/media/sda1/benchmark.tar.bz2 .
root@ELF1:~# tar xvf benchmark.tar.bz2
7、測(cè)試:
root@ELF1:~# cd benchmark/
root@ELF1:~/benchmark# ./benchncnn