[英]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:
我通过执行以下操作解决了它:
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(); }
Run the Command: flutter clean
运行命令:
flutter clean
Rebuild your project重建你的项目
PS It would be nice if more details on the error from the debug console was given. PS 如果提供有关调试控制台错误的更多详细信息,那就太好了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.