android - 无法应用委托:Android 中的 TFlite 崩溃
问题描述
当我尝试使用tflite GPU
. 我正在使用MoveNet
这里的模型单击。我在 CPU 中运行这个模型没有错误。
这是我的解释器初始化代码。
val compatList = CompatibilityList()
val options = Interpreter.Options().apply{
if(compatList.isDelegateSupportedOnThisDevice){
// if the device has a supported GPU, add the GPU delegate
val delegateOptions = compatList.bestOptionsForThisDevice
this.addDelegate(GpuDelegate(delegateOptions))
} else {
// if the GPU is not supported, run on 4 threads
this.setNumThreads(8)
}
}
interpreter = Interpreter(loadTFFile(),options)
毕业(模块):
implementation 'org.tensorflow:tensorflow-lite:2.3.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.3.0'
implementation 'org.tensorflow:tensorflow-lite-support:0.1.0'
错误:
java.lang.IllegalArgumentException: Internal error: Failed to apply delegate: Following operations are not supported by GPU delegate:
ARG_MAX: Operation is not supported.
CAST: Operation is not supported.
CONCATENATION: OP is supported, but tensor type isn't matched!
DEQUANTIZE:
FLOOR_DIV: Operation is not supported.
GATHER_ND: Operation is not supported.
MUL: OP is supported, but tensor type isn't matched!
PACK: Operation is not supported.
RESHAPE: OP is supported, but tensor type isn't matched!
SUB: OP is supported, but tensor type isn't.
我在 android 8.1 上测试这个
解决方案
我正在使用此代码来委托 tflite 模型,这是有效的。
tfliteModel = FileUtil.loadMappedFile(activity, this.getModelPath())
tfliteOptions.setNumThreads(numThreads)
tflite =
try {
val options = Interpreter.Options()
options.addDelegate(NnApiDelegate())
Interpreter(tfliteModel, options)
} catch (e: Exception) {
e.printStackTrace()
try {
val options = Interpreter.Options()
options.addDelegate(GpuDelegate())
Interpreter(tfliteModel, options)
} catch (e: Exception) {
val options = Interpreter.Options()
try {
Interpreter(tfliteModel, options)
} catch (e: Exception) {
e.printStackTrace()
null
}
}
}
这是 kotlin 语言
推荐阅读
- powershell - 如何在一行中输出多个变量
- c# - 如何在 C# 中使用 Json.net 解析未知的 Json 文件
- c++ - registerDialogClass 会导致问题吗?
- ffmpeg - 使用 Android NDK r20 构建 FFMPEG 4.2
- entity-framework - ASP.NET Core 2.2 如何使用依赖注入将两个构造函数添加到同一个类?
- parsing - 是否可以使用 EBNF 描述块注释?
- c# - 索引文档后删除模板
- python - 为什么张量流重塑数组超出范围
- mysql - Laravel foreign_key 表定义不正确;只能有一个自动列,并且必须将其定义为键
- sql-server - 将大型数据集从 SQL Server 转换为 Azure SQL 的方法?