本文主要是介绍TFLite:编译(app, so,jar, aar),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
对Lite : NDK r14b,bazel 0.18, tensorflow 1.12以下是没问题的
对mobile:NDK R16b, bazel 0.18 tensorflow 1.12是没有问题的。
bazel 编译app
bazel build --cxxopt=--std=c++11 //tensorflow/contrib/lite/java/demo/app/src/main:TfLiteCameraDemo
这种方式编译的app是源码编译生成的AAR,jni还是下载下来的?
bazel 编译tensorflowlite库
bazel build --cxxopt='--std=c++11' //tensorflow/contrib/lite/java:tensorflowlite \
--crosstool_top=//external:android/crosstool \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--cpu=armeabi
--cpu=armeabi
--cpu=armeabi-v7a
--cpu=arm64-v8a
--cpu=mips
--cpu=mips64
--cpu=x86
--cpu=x86_64
bazel-bin/tensorflow/contrib/lite/java/libtensorflowlite_jni.so
bazel-bin/tensorflow/contrib/lite/java/libtensorflowlitelib.jar
通过这种方式生成的文件,怎样编译到应用中去?
To build a standalone cc_binary
or cc_library
for Android without using an android_binary
, use the --crosstool_top
, --cpu
and --host_crosstool_top
flags.
For example:
bazel build //my/cc/jni:target \--crosstool_top=@androidndk//:default_crosstool \--cpu=<abi> \--host_crosstool_top=@bazel_tools//tools/cpp:toolchain
使用自定义 TensorFlow Lite 版本
bazel build --cxxopt='--std=c++11' -c opt \
--fat_apk_cpu=x86,x86_64,arm64-v8a,armeabi-v7a \
//tensorflow/contrib/lite/java:tensorflow-lite
creating: lib/
creating: lib/arm64-v8a/
inflating: lib/arm64-v8a/libtensorflowlite_jni.so
creating: lib/armeabi-v7a/
inflating: lib/armeabi-v7a/libtensorflowlite_jni.so
creating: lib/x86/
inflating: lib/x86/libtensorflowlite_jni.so
creating: lib/x86_64/
inflating: lib/x86_64/libtensorflowlite_jni.so
adding: jni/arm64-v8a/libtensorflowlite_jni.so (deflated 63%)
adding: jni/armeabi-v7a/libtensorflowlite_jni.so (deflated 53%)
adding: jni/x86/libtensorflowlite_jni.so (deflated 65%)
adding: jni/x86_64/libtensorflowlite_jni.so (deflated 65%)
Target //tensorflow/contrib/lite/java:tensorflow-lite up-to-date:
bazel-genfiles/tensorflow/contrib/lite/java/tensorflow-lite.aar
NNAPI的支持,并不是那么简单
// ASharedMemory_create was added in Android 8.0, so safe to use with NNAPI
// which was added in 8.1.
static void* handle = loadLibrary("libandroid.so");
libandroid.so是怎么生成的?
static void* handle = loadLibrary("libneuralnetworks.so");
编译文件并没有提供怎么生成libneuralnetworks.so
应该是和文件nnapi_delegate.cc有关
看懂tensorflowlite框架源码
要是你有tensorflow训练模型的知识,看懂tensorflowlite框架源码(主要就是interpreter.cc、model.cc)
这篇关于TFLite:编译(app, so,jar, aar)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!