当前位置: 首页 > news >正文

arm平台上的MNN编译与运行

0.成果物

直接获取成果物见:https://download.csdn.net/download/u012824853/87867665

以下为编译、运行过程

1.编译准备

在GitHub - alibaba/MNN: MNN is a blazing fast, lightweight deep learning framework, battle-tested by business-critical use cases in Alibaba下载code->downloadZIP

unzip MNN-master.zipcd MNN-mastervim CMakeLists.txt

将其中的MNN_BUILD_DEMO的option改为ON

2.生成Makefile

查看arm的架构,如armv7、v8等,赋值给CMAKE_SYSTEM_PROCESSOR

确定编译结果保存文件的路径赋值给CMAKE_INSTALL_PREFIX

确定编译工具链的位置,赋值给CMAKE_C_COMPILER、CMAKE_CXX_COMPILER

whereis arm-linux-gnueabihf-gcc
arm-linux-gnueabihf-gcc: /root/arm-linux-compiler/gcc-linaro-12.2.1-2023.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
whereis arm-linux-gnueabihf-g++
arm-linux-gnueabihf-g++: /root/arm-linux-compiler/gcc-linaro-12.2.1-2023.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++
mkdir install && mkdir build && cd build
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DMNN_BUILD_DEMO=ON \
-DMNN_USE_INT8_FAST=true \
-DMNN_BUILD_TEST=true\
-DMNN_OPENCL=ON \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_VERSION=1 \
-DCMAKE_SYSTEM_PROCESSOR=armv7 \
-DCMAKE_INSTALL_PREFIX=/root/mnn/MNN-master/install \
-DCMAKE_C_COMPILER=/root/arm-linux-compiler/gcc-linaro-12.2.1-2023.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \
-DCMAKE_CXX_COMPILER=/root/arm-linux-compiler/gcc-linaro-12.2.1-2023.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++

3.编译

执行make

如果遇到报错:

/root/mnn/MNN-master/source/math/Vec.hpp:342:71: error: cannot convert ‘int16x8_t’ to ‘int8x16_t’342 |         auto m0m1 = vtrnq_s8(reinterpret_cast<int8x16_t>(vec0.value), reinterpret_cast<int16x8_t>(vec1.value));|                                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|                                                                       ||                                                                       int16x8_t
In file included from /root/mnn/MNN-master/source/math/Vec.hpp:15:
/root/arm-linux-compiler/gcc-linaro-12.2.1-2023.01-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/12.2.1/include/arm_neon.h:9532:36: note:   initializing argument 2 of ‘int8x16x2_t vtrnq_s8(int8x16_t, int8x16_t)’9532 | vtrnq_s8 (int8x16_t __a, int8x16_t __b)|                          ~~~~~~~~~~^~~
/root/mnn/MNN-master/source/math/Vec.hpp:343:71: error: cannot convert ‘int16x8_t’ to ‘int8x16_t’343 |         auto m2m3 = vtrnq_s8(reinterpret_cast<int8x16_t>(vec2.value), reinterpret_cast<int16x8_t>(vec3.value));|                                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|                                                                       ||                                                                       int16x8_t

则将/root/mnn/MNN-master/source/math/Vec.hpp的342、343行

auto m0m1 = vtrnq_s8(reinterpret_cast<int8x16_t>(vec0.value), reinterpret_cast<int16x8_t>(vec1.value));
auto m2m3 = vtrnq_s8(reinterpret_cast<int8x16_t>(vec2.value), reinterpret_cast<int16x8_t>(vec3.value));

改为

auto m0m1 = vtrnq_s8(reinterpret_cast<int8x16_t>(vec0.value), reinterpret_cast<int8x16_t>(vec1.value));
auto m2m3 = vtrnq_s8(reinterpret_cast<int8x16_t>(vec2.value), reinterpret_cast<int8x16_t>(vec3.value));

重新make -j4

如果发生make进度卡住的情况,则不要加-j4

成果物是libMNN.so

4.模型准备

在Model Zoo · 语雀中找合适的模型,比如:GitHub - Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB: 💎1MB lightweight face detection model (1MB轻量级人脸检测模型)

code->downloadZIP,解压

将刚才编译的build的目录/MNN-master/build下的libMNN.so拷贝到Ultra-Light-Fast-Generic-Face-Detector-1MB-master/MNN/mnn/lib下

在Ultra-Light-Fast-Generic-Face-Detector-1MB-master/MNN/CMakeLists.txt中添加:

set(OpenCV_DIR /opencv-3.4.1/build)

opencv3.4.1在ARM平台上的编译方法见:

opencv arm交叉编译与仿真验证详细流程_opencv交叉编译arm_I_am_Damon的博客-CSDN博客

将Ultra-Light-Fast-Generic-Face-Detector-1MB-master/MNN/src/main.cpp中的cv:imshow和cv::waitkey注释掉,因为嵌入式端一般不能显示图像

在Ultra-Light-Fast-Generic-Face-Detector-1MB-master/MNN/下执行:

mkdir build;
cd build;
cmake .. -DCMAKE_SYSTEM_PROCESSOR=armv7 \
-DCMAKE_C_COMPILER=/root/arm-linux-compiler/gcc-linaro-12.2.1-2023.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \
-DCMAKE_CXX_COMPILER=/root/arm-linux-compiler/gcc-linaro-12.2.1-2023.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++
make -j4;

可生成可执行程序:Ultra-face-mnn

5.板端运行

将opencv生成的所有动态库拷贝到执行设备(arm一般是嵌入式板子)上的/lib/目录下

将libMNN.so也拷贝到执行设备上的/lib/目录下

然后按照Ultra-Light-Fast-Generic-Face-Detector-1MB-master/MNN/README.md执行测试用例:

./Ultra-face-mnn ./model/version-RFB/RFB-320.mnn ./imgs/1.jpg

即可生成代码检测框的图片:

http://www.lryc.cn/news/92057.html

相关文章:

  • python 编译安装指定版本 for linux
  • 在Linux系统下基于Docker搭建Redis集群
  • 牛客网刷题Day5
  • Vue.js 中的动态组件是什么?如何使用动态组件?
  • 2023年京东618预售数据:传统滋补成预售黑马,预售额超27亿
  • 【Linux系统基础快速入门详解】Linux 常用文件过滤编辑命令原理详解和每个命令使用场景以及实例
  • 05WEB系统的通信原理图
  • 降低试错成本,低代码或成企业数字化转型突破口
  • 串口助手(串口发送接收数据, 定时, 清空, hex显示)
  • bp神经网络
  • strace交叉编译后对特定文件的写流程进行监控和过滤
  • 初识网络之TCP网络套接字
  • 自然语言处理从入门到应用——自然语言处理的基本问题:文本分类(Text Classification, Text Categorization)
  • 【论文】——Robust High-Resolution Video Matting with Temporal Guidance浅读
  • 第四章、用户体验五要素之范围层解析(本文作用是通俗讲解,让你更容易理解)
  • 计算机毕业论文内容参考|基于python的农业温室智能管理系统的设计与实现
  • Java 进阶 -- 流
  • 硬件 TCP/IP 协议栈
  • word恢复和粘贴按钮变灰色,不可用怎么办?
  • 【unity技巧】Physics2D Raycast、Overlapcircle、OverlapBox检测的用法
  • 一、kafka入门
  • 公司新来一00后,真让人崩溃...
  • (1Gb)S28HS01GTGZBHA030/ S28HS01GTGZBHV033/ S28HS01GTGZBHA033 FLASH - NOR闪存器件
  • 苹果服务端通知v2处理(AppStore Server Notifications V2)
  • matlab 道路点云路缘石边界提取
  • 二叉树详解:带你掌握二叉树
  • LNMP网站框架搭建(编译安装)
  • 详解Servlet API
  • 【小白教程】Docker安装使用教程,以及常用命令!
  • TypeScript基础