【环境搭建】mnn - android

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 stdio
5.1 android stdio -> android device

lsudb
sudo vim /etc/udev/rules.d/51-Android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="4ee7"
sudo chmod 777 /etc/udev/rules.d/51-Android.rules
adb kill-server
adb start-server
adb devices

选择android device,启动

5.2 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

你可能感兴趣的:(环境搭建)