是否有一种方法来实现批量分类在扑动与Tflite?



我想对多个图像进行迭代分类,我尝试了

Future pickImages() async {
final List<XFile>? images = await ImagePicker().pickMultiImage();
if (images == null) return;

images.forEach((image) async {
print('- Name: ${image.path}');
await runModel(image.path);
});
}
Future runModel(String imagePath) async {
var recognitions = await Tflite.runModelOnImage(
path: imagePath,
numResults: 1,
threshold: 0.5,
imageMean: 127.5,
imageStd: 127.5,
asynch: true // defaults to true
);
print(recognitions);
await Future.delayed(Duration(seconds: 1));
setState(() {});
}

如果我只选择一个图像,一切都运行良好,一旦我继续选择多个图像,我得到以下错误:

PlatformException (PlatformException(Failed to run model, Interpreter busy, java.lang.RuntimeException: Interpreter busy

我尽了最大的努力,但还是解决不了这个问题。

如果你能建议如何对多个选定的图像(ImagePicker)进行推断,我将非常感激。

谢谢!

这对我有用:

pickImage:

async {
final ImagePicker _picker = ImagePicker();
final pickedFile = await _picker.pickMultiImage();
List<XFile> xfilePick = pickedFile;
setState(
() {
if (xfilePick.isNotEmpty) {
for (var i = 0; i < xfilePick.length; i++) {
selectedImages.add(File(xfilePick[i].path));
}
}
},
);

for (var i = 0; i < selectedImages.length; i++){
await Future.delayed(const Duration(seconds: 1));{
imageClassification(selectedImages[i]);
await Future.delayed(const Duration(seconds: 1));
}
}}

最新更新