Android 在颤振中使用tflite处理自定义模型时,应用程序崩溃。我怎么修理它?
我已经建立了一个定制的tflite模型,它是从Keras hdf5模型转换而来的。但是,当使用转换后的模型时,在进行预测时,android中的应用程序正在崩溃,但当我使用从internet下载的mobile net tflite模型时,该应用程序运行良好。我需要做什么改变?问题是在模型转换还是在应用程序中 我尝试使用tflite软件包的内置功能,该软件包支持移动网络和tflite提供的各种其他网络,我改为自定义构建模型预测功能,并保留转换后的文件模型。在第一种情况下,它起作用了,但在第二种情况下,它没有起作用Android 在颤振中使用tflite处理自定义模型时,应用程序崩溃。我怎么修理它?,android,flutter,keras,prediction,Android,Flutter,Keras,Prediction,我已经建立了一个定制的tflite模型,它是从Keras hdf5模型转换而来的。但是,当使用转换后的模型时,在进行预测时,android中的应用程序正在崩溃,但当我使用从internet下载的mobile net 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;
});
}
我在资产中添加了两个模型:
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();
}
flatterclean
另外,如果能从调试控制台获得更多关于错误的详细信息,那就太好了。在labels.txt或labelmap.txt上保留额外的行将是一个问题。请确保不要保留新线路