【环境搭建】mnn - android
程序员文章站
2024-02-01 18:13:58
1,安装...
1,准备
1.1 android ndk
下载android-ndk-r17c,https://developer.android.com/ndk/downloads/
vim ~/.bashrc
# 添加android-NDK
export ANDROID_NDK=~/android-ndk-r21
source ~/.bashrc
1.2 vulkan
# https://vulkan.lunarg.com/sdk/home,下载,vulkansdk-linux-x86_64-1.2.141.0.tar.gz
tar -xf vulkansdk-linux-x86_64-1.2.141.0.tar.gz
sudo apt install vulkan-utils
# setup vulkan env
export VULKAN_SDK=$HOME/vulkansdk-linux-x86_64-1.2.141.0/x86_64
export PATH=$VULKAN_SDK/bin:$PATH
export LD_LIBRARY_PATH=$VULKAN_SDK/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=$VULKAN_SDK/lib:$LIBRARY_PATH
export VK_LAYER_PATH=$VULKAN_SDK/etc/vulkan/explicit_layer.d
1.3 protobuf > 3.0
1.4 cmake > 3.0
2,安装
git clone https://github.com/alibaba/MNN.git
cd MNN
修改CMakeLists.txt
# backend options
option(MNN_METAL "Enable Metal" OFF)
option(MNN_OPENCL "Enable OpenCL" ON)
option(MNN_OPENGL "Enable OpenGL" ON)
option(MNN_VULKAN "Enable Vulkan" ON)
option(MNN_ARM82 "Enable ARM82" ON)
./schema/generate.sh
cd project/android
# 编译armv7动态库:mkdir build_32 && cd build_32 && ../build_32.sh
# 编译armv8动态库:mkdir build_64 && cd build_64 && ../build_64.sh
mkdir build_64
cd build_64
../build_64.sh
make -j4
3,测试
cd MNN/benchmark
./bench_android.sh
5,android
5.1 android添加库
public class MNNNetNative { // load libraries
static {
System.loadLibrary("MNN");
System.loadLibrary("MNN_Arm82");
System.loadLibrary("mnncore");
}
}
5.2 代码
// 创建session需要的配置
MNN::ScheduleConfig config;
// 选择Backend
config.type = MNN_FORWARD_CPU;
// 线程数
config.numThread = 2;
// 配置相应的Backend
BackendConfig backendConfig;
// 选择低精度/一般配置计算
backendConfig.precision = BackendConfig::Precision_Low;
// 或者
// backendConfig.precision = BackendConfig::Precision_Normal;
config.backendConfig = &backendConfig;
6,Inference
https://blog.csdn.net/qq_37643960/article/details/99775939
https://my.oschina.net/u/4394438/blog/4335516
本文地址:https://blog.csdn.net/luolinll1212/article/details/107412777
推荐阅读
-
【环境搭建】mnn - android
-
[Tomcat源码分析] Eclipse中搭建Apache Tomcat源码调试环境
-
Win2008 PHP 配置环境搭建 教程_PHP教程
-
Nginx+Keepalived(双机热备)搭建高可用负载均衡环境(HA)
-
记一次Docker生产环境搭建的方法
-
聊聊Nginx+Keepalived(双机热备)搭建高可用负载均衡环境(HA) 的技术
-
windows和Linux环境下php apache mysql 环境的搭建教程
-
WIN8.1下搭建PHP5.6环境,win8.1搭建php5.6_PHP教程
-
linux 生产环境搭建,linux环境搭建
-
PHP Eclipse PDT ZEND FrameWork Windos下开发环境搭建