[英]Application is crashing when working with custom model using tflite in flutter. How do i fix it?
我已经构建了一个从 Keras hdf5 模型转换而来的自定义 tflite 模型。 但是当使用转换后的模型时,在进行预测时,应用程序在 android 中崩溃,但是当我使用从互联网下载的移动网络 tflite 模型时,该应用程序可以正常工作。 我必须做出哪些改变? 是模型转换的问题还是应用的问题?
我尝试使用tflite包的内置功能,支持移动网络和tflite提供的各种其他网络,我改为自定义构建模型预测功能并保留转换后的文件模型。 在第一种情况下,它起作用了,但在第二种情况下,它没有。
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;
});
}
我在资产中添加了 2 个模型:
assets:
- images/webdoctor.png
- assets/detect.tflite
- assets/labelmap.txt
- assets/labels.txt
- assets/modelPneumonia.tflite
预期结果将是自定义模型的工作,而不会导致应用程序崩溃。
我遇到了类似的问题,是内存泄漏导致应用程序崩溃。 我通过执行以下操作解决了它:
添加以下内容以关闭任何资源
@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(); }
运行命令: flutter clean
重建你的项目
PS 如果提供有关调试控制台错误的更多详细信息,那就太好了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.