简体   繁体   English

在颤振中使用 tflite 处理自定义模型时,应用程序崩溃。 我如何解决它?

[英]Application is crashing when working with custom model using tflite in flutter. How do i fix it?

I have built a custom tflite model which got converted from Keras hdf5 model.我已经构建了一个从 Keras hdf5 模型转换而来的自定义 tflite 模型。 But when using the converted model, while making prediction the application is crashing in android, but when I am using the mobile net tflite model which is downloaded from internet works fine with the application.但是当使用转换后的模型时,在进行预测时,应用程序在 android 中崩溃,但是当我使用从互联网下载的移动网络 tflite 模型时,该应用程序可以正常工作。 What changes do I have to make?我必须做出哪些改变? Whether the problem is in the model conversion or in the application?是模型转换的问题还是应用的问题?

I have tried using the inbuilt function by tflite package that supports mobile net and various other nets that are given by tflite, I changed to custom build model prediction function and kept the converted file model.我尝试使用tflite包的内置功能,支持移动网络和tflite提供的各种其他网络,我改为自定义构建模型预测功能并保留转换后的文件模型。 In the first case, it worked, but in the second case, it did not.在第一种情况下,它起作用了,但在第二种情况下,它没有。

Future prediction(File image) async{
  _recognitions= null;
  var recognitions = await Tflite.runModelOnImage(
  path: image.path,   // required
  imageMean: 0.0,   // defaults to 117.0
  imageStd: 255.0,  // defaults to 1.0
  numResults: 2,    // defaults to 5
  threshold: 0.2,   // defaults to 0.1
  asynch: true      // defaults to true
);
  // var recognitions = await Tflite.detectObjectOnImage(
  //   path: image.path,
  //   model: "SSDMobileNet",
  //   imageMean: 127.5,
  //   threshold: 0.4,
  //   numResultsPerClass: 2,
  //   asynch: true
  // );
  print(recognitions);
  setState(() {
    _recognitions=recognitions;
  });
}

I have added 2 models in assets:我在资产中添加了 2 个模型:

  assets:
   - images/webdoctor.png
   - assets/detect.tflite
   - assets/labelmap.txt
   - assets/labels.txt
   - assets/modelPneumonia.tflite

Expected results would be the working of custom model without app crashing.预期结果将是自定义模型的工作,而不会导致应用程序崩溃。

I ran into a similar problem and it was a memory leak that crashed the app.我遇到了类似的问题,是内存泄漏导致应用程序崩溃。 I solved it by doing the following:我通过执行以下操作解决了它:

  1. Add the following to close any resource添加以下内容以关闭任何资源

    @override void dispose() { // you can add to close tflite if error is caused by tflite // tflite.close(); controller?.dispose(); // this is to dispose camera controller if you are using live detection super.dispose(); }
  2. Run the Command: flutter clean运行命令: flutter clean

  3. Rebuild your project重建你的项目

PS It would be nice if more details on the error from the debug console was given. PS 如果提供有关调试控制台错误的更多详细信息,那就太好了。

Keeping extra lines on labels.txt or labelmap.txt would be an issue.在 labels.txt 或 labelmap.txt 上保留额外的行将是一个问题。 Please make sure you don't keep new lines.请确保您不保留新行。

做:

别:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Glide 时如何修复崩溃的应用程序 - How do I fix crashing Application when using Glide 如何更改完全卷积 tflite model 的输入尺寸? - how do I change the input dimensions for fully convolutional tflite model? 在 flutter 中使用 Snack Bar 和 Navigator 时,如何修复“不要使用 BuildContexts accros async gaps” - How do I fix "Do not use BuildContexts accros async gaps" when using Snack Bar and Navigator in flutter 无法在 Android 应用程序中正确获取自定义模型 Tflite 模型的输出 - Unable to correctly get the output of Custom Model Tflite Model in Android application Flutter:Agora 无法在 Android 中运行。 如何使用 agora 修复我的实时流的 android 应用程序中的黑屏问题? - Flutter:Agora is not working in Android. How can I fix black screen issues in my android application of live stream using agora? 扑。 使用主题,如何更改滚动偏移颜色? - Flutter. Using Theme, how to change scroll offset color? 如何修复AdMob导致我的Android应用崩溃? - How do I fix AdMob crashing my Android app? 如何修复滚动视图崩溃的 Android 应用程序? - How do I fix scrollview crashing Android app? 如何修复 Flutter for Android 问题? - How do I fix a Flutter for Android issue? 如何使用我的自定义 model (tflite) 在 Android Studio 中运行? - How to use my custom model (tflite) to run in Android Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM