赞
踩
利用神经网络算法优化噪点,目前是想在app上跑神经网络算法。在网上查找腾讯开源了ncnn框架。
集成步骤如下:
这个也可以自己编译,简单集成下载库地址为https://github.com/Tencent/ncnn/releases,除了下载android之外还要下载window包,因为windows包有我们需要的模型转换工具和模型转为代码文件工具。
android studio 4版本,新建native c++ 项目,新建好后,在ide菜单file->project structure->modules选择ndk版本和build工具版本。在src/main文件夹上新建jni文件夹把相关的库进去arm64-v8a/libncnn.a,armeabi-v7a/libncnn.a。
首先配置build.gradle里面的信息在externalNativeBuild添加如下编译参数
externalNativeBuild {
cmake {
arguments "-DANDROID_TOOLCHAIN=clang"
cFlags "-fopenmp -static-openmp -O2 -fvisibility=hidden -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -ffast-math "
cppFlags "-fopenmp -static-openmp -O2 -fvisibility=hidden -fvisibility-inlines-hidden -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -ffast-math "
arguments "-DANDROID_STL=c++_shared", "-DANDROID_CPP_FEATURES=rtti exceptions"
cppFlags ""
cppFlags "-std=c++11"
cppFlags "-frtti"
cppFlags "-fexceptions"
}
}
ndk{
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
然后再配置cmakelist.text
# For more information about using CMake with Android Studio, read the # documentation: https://d.android.com/studio/projects/add-native-code.html # Sets the minimum version of CMake required to build the native library. cmake_minimum_required(VERSION 3.10.2) # Declares and names the project. project("ncnnexample") # Creates and names a library, sets it as either STATIC # or SHARED, and provides the relative paths to its source code. # You can define multiple libraries, and CMake builds them for you. # Gradle automatically packages shared libraries with your APK. add_library( # Sets the name of the library. native-lib # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). native-lib.cpp ) # Searches for a specified prebuilt library and stores the path as a # variable. Because CMake includes system libraries in the search path by # default, you only need to specify the name of the public NDK library # you want to add. CMake verifies that the library exists before # completing its build. find_library( # Sets the name of the path variable. log-lib # Specifies the name of the NDK library that # you want CMake to locate. log ) # Specifies libraries CMake should link to your target library. You # can link multiple libraries, such as libraries you define in this # build script, prebuilt third-party libraries, or system libraries. target_link_libraries( # Specifies the target library. native-lib ncnn android jnigraphics z m # Links the target library to the log library # included in the NDK. ${log-lib} ) include_directories(src/main/cpp/include) add_library(ncnn STATIC IMPORTED) SET_TARGET_PROPERTIES( ncnn PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../jni/${CMAKE_ANDROID_ARCH_ABI}/libncnn.a)
1、libomp.so not found这个是ndk版本有关系,可以网上查下。
2、ncnn运行结果出错或崩溃,这个需要使用同一个版本ncnn,包括onnx2ncnn,ncnn2mem和.a要一致。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。