0

I want to classify multiple images iteratively, I tried it with

  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(() {});

}

Everything runs fine if I just select one image, as soon as I go on selecting multiple images I get the following error:

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

I tried my best but couldn't resolve the issue.

I would really appreciate it if you can suggest how to make inferences on multiple selected images(ImagePicker).

Thanks!

1 Answer 1

-1

this worked for me:

for 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));
    }
  }}
2
  • you're essentially just running a loop. OPs question is regarding batch processing Commented Apr 13, 2023 at 12:16
  • This is what he wanted to do , classify multiple selected image , same issue i faced and worked for me. The critical line was adding the delay
    – VikTor
    Commented May 17, 2023 at 23:21

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.