tensorflow-lite-select-tf-ops 和从源 tflite 模型构建的 tensorflow-lite AAR 找不到 org.tensorflow.lite.Interpreter
tensorflow-lite-select-tf-ops and tensorflow-lite AAR built from source tflite model cannot find org.tensorflow.lite.Interpreter
我按照 tensorflow android 指南从源代码生成 tensorflow-lite.aar
和 tensorflow-lite-select-tf-ops.aar
。
https://www.tensorflow.org/lite/guide/build_android
我当前的应用程序适用于,
dependencies {
...
implementation 'org.tensorflow:tensorflow-lite:2.3.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.3.0'
implementation 'org.tensorflow:tensorflow-lite-select-tf-ops:2.3.0'
}
我希望减小 tensorflow-lite-select-tf-ops.aar
的大小以减小应用程序 apk
的大小。
我正在按照 build_aar.sh
流程来减小我的 tflite 模型的大小。使用的命令,
bash tensorflow/lite/tools/build_aar.sh --input_models=custom_model.tflite --target_archs=arm64-v8a
这会在 custom_model.tflite
的 bazel-bin/tmp
文件夹中生成 tensorflow-lite.aar
和 tensorflow-lite-select-tf-ops.aar
。 tflite 模型已 FP16
量化。
使用新生成的 aar 文件实现,
dependencies {
...
// implementation 'org.tensorflow:tensorflow-lite-select-tf-ops:2.3.0'
// implementation 'org.tensorflow:tensorflow-lite:2.3.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.3.0'
implementation files('libs/tensorflow-lite.aar')
// implementation files('libs/tensorflow-lite-gpu.aar')
implementation files('libs/tensorflow-lite-select-tf-ops.aar')
}
但是当它们包含在 android 应用程序编译错误时发生。
C:\folder\myapp\app\src\main\java\com\example\mapp\tflite\YoloV4Classifier.java:19: error: cannot find symbol
import org.tensorflow.lite.Interpreter;
^
symbol: class Interpreter
location: package org.tensorflow.lite
使用 bazel build -c opt --fat_apk_cpu=arm64-v8a --host_crosstool_top=@bazel_tools//tools/cpp:toolchain tensorflow/lite/java:tensorflow-lite
构建 tensorflow-lite.aar
时,此问题消失。但这引入了 UnsatisfiedLinkError: dlopen failed: cannot locate symbol with previous tensorflow-lite-select-tf-ops.aar
and new built tensorflow-lite.aar
with above command.
如果我把之前的 tensorflow-lite.aar
生成自 custom_model.tflite
和新的 tensorflow-lite.aar
生成的 bazel build -c opt --fat_apk_cpu=arm64-v8a --host_crosstool_top=@bazel_tools//tools/cpp:toolchain tensorflow/lite/java:tensorflow-lite
那么就会出现构建错误,
More than one file was found with OS independent path 'lib/arm64-v8a/libtensorflowlite_jni.so'
我按照基于非输入 tflite 模型的命令从源代码生成 tensorflow-lite.aar
、tensorflow-lite-gpu.aar
、tensorflow-lite-select-tf-ops.aar
,但应用程序大小变得非常大。我试过 other ways 但每次都会出现一种新的错误。
我按照 tensorflow android 指南从源代码生成 tensorflow-lite.aar
和 tensorflow-lite-select-tf-ops.aar
。
https://www.tensorflow.org/lite/guide/build_android
我当前的应用程序适用于,
dependencies {
...
implementation 'org.tensorflow:tensorflow-lite:2.3.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.3.0'
implementation 'org.tensorflow:tensorflow-lite-select-tf-ops:2.3.0'
}
我希望减小 tensorflow-lite-select-tf-ops.aar
的大小以减小应用程序 apk
的大小。
我正在按照 build_aar.sh
流程来减小我的 tflite 模型的大小。使用的命令,
bash tensorflow/lite/tools/build_aar.sh --input_models=custom_model.tflite --target_archs=arm64-v8a
这会在 custom_model.tflite
的 bazel-bin/tmp
文件夹中生成 tensorflow-lite.aar
和 tensorflow-lite-select-tf-ops.aar
。 tflite 模型已 FP16
量化。
使用新生成的 aar 文件实现,
dependencies {
...
// implementation 'org.tensorflow:tensorflow-lite-select-tf-ops:2.3.0'
// implementation 'org.tensorflow:tensorflow-lite:2.3.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.3.0'
implementation files('libs/tensorflow-lite.aar')
// implementation files('libs/tensorflow-lite-gpu.aar')
implementation files('libs/tensorflow-lite-select-tf-ops.aar')
}
但是当它们包含在 android 应用程序编译错误时发生。
C:\folder\myapp\app\src\main\java\com\example\mapp\tflite\YoloV4Classifier.java:19: error: cannot find symbol
import org.tensorflow.lite.Interpreter;
^
symbol: class Interpreter
location: package org.tensorflow.lite
使用 bazel build -c opt --fat_apk_cpu=arm64-v8a --host_crosstool_top=@bazel_tools//tools/cpp:toolchain tensorflow/lite/java:tensorflow-lite
构建 tensorflow-lite.aar
时,此问题消失。但这引入了 UnsatisfiedLinkError: dlopen failed: cannot locate symbol with previous tensorflow-lite-select-tf-ops.aar
and new built tensorflow-lite.aar
with above command.
如果我把之前的 tensorflow-lite.aar
生成自 custom_model.tflite
和新的 tensorflow-lite.aar
生成的 bazel build -c opt --fat_apk_cpu=arm64-v8a --host_crosstool_top=@bazel_tools//tools/cpp:toolchain tensorflow/lite/java:tensorflow-lite
那么就会出现构建错误,
More than one file was found with OS independent path 'lib/arm64-v8a/libtensorflowlite_jni.so'
我按照基于非输入 tflite 模型的命令从源代码生成 tensorflow-lite.aar
、tensorflow-lite-gpu.aar
、tensorflow-lite-select-tf-ops.aar
,但应用程序大小变得非常大。我试过 other ways 但每次都会出现一种新的错误。