I had created an tflite model using teachable machine and deploy into an mobile application (flutter).
Everything is going fine until I realise there is a problem when I pass in an image into the model and an error appear shown in image below. This problem only happen on specific image on specific tflite model which mean when i pass the same image into another model the error wont occur. But the model might encounter error on another image.
Error in debug console: Exception has occurred. RangeError (RangeError (index): Invalid value: Valid value range is empty: 0)
'The ripeness of Papaya is:\n${_output[0]['label'] + " \n" + _output[0]['confidence'].toStringAsFixed(2)}',
Code that used to load the model:
loadModel() async {
String res;
//this function loads our model
res = (await Tflite.loadModel(
model: 'assets/model.tflite',
labels: 'assets/labels.txt',
))!;
}
Code that used to pick image:
pickImage() async {
//this function to grab the image from camera
var image = await picker.pickImage(source: ImageSource.camera);
if (image == null) return null;
setState(() {
_image = File(image.path);
});
classifyImage(_image);
}
classifyImage(File image) async {
//this function runs the model on the image
var output = await Tflite.runModelOnImage(
path: image.path,
numResults:
4,
threshold: 0.5,
imageMean: 127.5,
imageStd: 127.5,
);
setState(() {
_output = output!;
_loading = false;
});
}
dependencies:
tflite: ^1.1.2
image_picker: ^0.8.6
build.gradle defaultconfig:
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
aaptOptions {
noCompress 'tflite'
noCompress 'lite'
}
Is there any possible fix for this problem?