如何运行带FlutterTensorFlow Lite Movenet lightning 模型?

xzv2uavs  于 2023-04-21  发布在  Flutter
关注(0)|答案(1)|浏览(158)

TFLite (movenet/multipose/lightning/tflite/float16)我已经成功加载了模型,但是每当我试图运行它时...它只是崩溃了应用程序。下面是加载和运行模型的代码:

Future loadModel() async {
try {
  res = await Tflite.loadModel(
    model:
    "assets/lite-model_movenet_multipose_lightning_tflite_float16_1.tflite",
  );
  print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> model loaded: " + res.toString());
} catch (e) {
  print(e);
  print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Failed to load model.');
} }

  Future poseNet(File image) async {
int startTime = new DateTime.now().millisecondsSinceEpoch;

var output = await Tflite.runPoseNetOnImage(
  threshold: 0.7,
  path: image.path,
  numResults: 5,
  nmsRadius: 15
);

print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> recognitions: ${output}');

setState(() {
  _recognitions = output!;
});
int endTime = new DateTime.now().millisecondsSinceEpoch;
print(
    ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Inference took ${endTime - startTime}ms ");}

以下是日志:

I/tflite  (11904): Initialized TensorFlow Lite runtime.
I/flutter (11904): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> model loaded: success
W/System  (11904): A resource failed to call close. 
D/EGL_emulation(11904): eglCreateContext: 0xead612c0: maj 2 min 0 rcv 2
E/flutter (11904): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(Failed to run model, length=3; index=3, java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
E/flutter (11904):  at sq.flutter.tflite.TflitePlugin.initPoseNet(TflitePlugin.java:1262)
E/flutter (11904):  at sq.flutter.tflite.TflitePlugin$RunPoseNet.<init>(TflitePlugin.java:1290)
E/flutter (11904):  at sq.flutter.tflite.TflitePlugin.runPoseNetOnImage(TflitePlugin.java:1217)
E/flutter (11904):  at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:179)
E/flutter (11904):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter (11904):  at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:178)
E/flutter (11904):  at io.flutter.embedding.engine.dart.DartMessenger.lambda$handleMessageFromDart$0$DartMessenger(DartMessenger.java:206)
E/flutter (11904):  at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$6ZD1MYkhaLxyPjtoFDxe45u43DI.run(Unknown Source:12)
E/flutter (11904):  at android.os.Handler.handleCallback(Handler.java:938)
E/flutter (11904):  at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (11904):  at android.os.Looper.loop(Looper.java:223)
E/flutter (11904):  at android.app.ActivityThread.main(ActivityThread.java:7656)
E/flutter (11904):  at java.lang.reflect.Method.invoke(Native Method)
E/flutter (11904):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/flutter (11904):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter (11904): , null)
E/flutter (11904): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (11904): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
E/flutter (11904): <asynchronous suspension>
E/flutter (11904): #2      Tflite.runPoseNetOnImage (package:tflite/tflite.dart:350:12)
E/flutter (11904): <asynchronous suspension>
E/flutter (11904): #3      _SelectImageState.poseNet (package:model_ui/main/select_image.dart:105:18)
E/flutter (11904): <asynchronous suspension>
E/flutter (11904):

任何帮助将不胜感激!谢谢!

oewdyzsn

oewdyzsn1#

我不是一个Maven。但tflite插件是过时的。你应该试试你的运气与tflite_flutter,这也是有点过时。但为我工作。

相关问题