[FIXED] Flutter tflite always showing the same output

Issue

I’m using tflite with flutter with tflite package. The model I’m using is created by my team member. The model identifies leaf diseases and classifies them into 3 stages.
But I’m always getting the same output every single time as,

response: [{confidence: 0.9917954802513123, index: 0, label: 0 early blight}]

only confidence is changing slightly.

image analyzing function,

runAnalyze() async {
if (pickedImage != null) {
  try {
    final temp = (await Tflite.runModelOnImage(
      imageMean: 127.5,
      imageStd: 127.5,
      path: pickedImage!.path,
      numResults: 1,
      threshold: .5,
    ));
    print('response: $temp');

    setState(() {
      errorText = temp.toString();
    });
  } on PlatformException catch (err) {
    print('error: $err');
    errorText = err.toString();
  }
}}

loading model on main,

 void main() async{
  WidgetsFlutterBinding.ensureInitialized();
  print(await Tflite.loadModel(
    model: 'assets/converted_model.tflite',
    labels: 'assets/labels.txt',
  ));
  runApp(const MyApp());
}

Solution

please change numResults: 1, to the number of items from label.txt
i.e, if your label.txt contains 6 diseases then numResult = 6

Answered By – aswinbbc

Answer Checked By – Dawn Plyler (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published