首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android12(Api级别31):TfLiteGpuDelegate调用: GpuDelegate必须运行在初始化它的线程上

问Android12(Api级别31):TfLiteGpuDelegate调用: GpuDelegate必须运行在初始化它的线程上
EN

Stack Overflow用户
提问于 2022-03-15 16:06:08
回答 1查看 263关注 0票数 0

在将我的android升级到版本12之后,我的代码停止了工作,我使用了颤振插件tflite_flutter 0.9.0,并孤立地启动了tflite。

它抛出此错误:

代码语言:javascript
复制
TfLiteGpuDelegate Invoke: GpuDelegate must run on the same thread where it was initialized.
E/tflite (20055): Node number 64 (TfLiteGpuDelegateV2) failed to invoke.
E/flutter (20055): [ERROR:flutter/runtime/dart_isolate.cc(1111)] Unhandled exception:
E/flutter (20055): Bad state: failed precondition
E/flutter (20055): #0 checkState (package:quiver/check.dart:74:5)
E/flutter (20055): #1 Interpreter.invoke (package:tflite_flutter/src/interpreter.dart:150:5)
E/flutter (20055): #2 Interpreter.runForMultipleInputs (package:tflite_flutter/src/interpreter.dart:190:5)
E/flutter (20055): #3 Classifier.predict (package:myai/ai/tflite/mobilenet/object/classifier.dart:179:19)
E/flutter (20055): #4 IsolateHelper.entryPoint (package:myai/ai/helper/isolate_helper.dart:51:30)

我的代码:

代码语言:javascript
复制
final gpuDelegateV2 = GpuDelegateV2(
options: GpuDelegateOptionsV2(
isPrecisionLossAllowed:true,
inferencePreference:TfLiteGpuInferenceUsage.preferenceSustainSpeed,
inferencePriority1:TfLiteGpuInferencePriority.minMemoryUsage,
inferencePriority2:TfLiteGpuInferencePriority.auto,
inferencePriority3:TfLiteGpuInferencePriority.auto,
)
);
var interpreterOptions = InterpreterOptions()..addDelegate(gpuDelegateV2);
_interpreter = interpreter ??
await Interpreter.fromAsset(
MODEL_FILE_NAME,
options: interpreterOptions
);

有人面临这样的问题吗?有什么建议怎么解决吗?

EN

回答 1

Stack Overflow用户

发布于 2022-09-14 09:32:21

您遇到的错误有可能是Can not open OpenCL library on this device - dlopen failed: library "libOpenCL.so" not found吗?版本12需要在清单中声明依赖项模块。针对Sdk时,需要将TFLite依赖项添加到清单中。阅读以下摘自这里的相关评论。

注意:您现在可以使用清单中的targetSdkVersion="S“作为targetSdkVersion=的目标,或者在Gradle defaultConfig中使用targetSdkVersion "S”(API )。在这种情况下,您应该将AndroidManifestGpu.xml的内容合并到安卓应用程序的清单中。如果不进行此更改,GPU委托将无法访问OpenCL库进行加速。AGP 4.2.0或更高版本才能工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71485371

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档