Always Predicts the Same Class

I trained the MobilenetV3 model with the input of range [-1,1] by passing the argument

include_preprocessing = True

Then, while the model is predicting with the

var output = await Tflite.runModelOnImage(
      path: image.path,
      numResults: 14,
      imageMean: 127.5,
      imageStd: 127.5,

function on TFLite, it always predicts the same class.

Colab Link of the model


Just to have some more info, did you follow a tutorial? can you share the link?
where did you get the [-1, 1] range?

are you running this on JS?

the colab link needs permission, maybe if you put on a public repository it would be easier to share on this forum.

I got from here:

I updated the permission, can you check it again?

ok, got it!

I’ve read your colab and two things:

  • I think your train/validation split is a little bit weird. (That doesn’t affect the issue you are mentioning)
  • given that you want to convert to TFLite and it looks like it’s a simple image classification model, I’d suggest you try using Model Maker. It will take care of converting the model and doing all the magic for you. It will also make it easier to use it with the Task Lib

If you decide to use Model Maker, you can use a MobileNetV3 model spec (the model is available on TF Hub).

sorry for the non-answer

1 Like

Thanks for the answers Gus. Of course you helped me. I also follow you on Twitter and love your tweets. But I wonder why the test/train set split is weird, could you explain?

Thanks for the information, I will try model maker but I’m wondering where I’m wrong.

I’m sorry the Colab link I shared didn’t save my latest work, so it showed sketchy work. I updated the link again, those who want to help can take a look.

1 Like

I don’t know if the preprocessing is correct but you could check also the preprocessing in:


That’s what I need exactly. I was not aware of such a repo. Thank you so much.

Your train/test split was pointing to the same data so the model would train and test on the same data and that gives a wrong perspective of the quality of your model.

Did you had time to try Model Maker? that might help you!

1 Like

I split train/test like in the tutorial here:

If you think the Colab link I updated still has the same mistake, please let me know.

Unfortunately, I hadn’t time to try, but if I have, I’m going to reply. Thanks.

1 Like

I guess the problem of always predicting the same class is caused by the MobilenetV3. By making Preprocessing False, I normalized the images myself to a range of [-1,1] and the model is working fine.
I tried ModelMaker and downloaded the model from TF Hub, it makes the process easier a lot. I will probably use it in my next projects. Thank you to everyone who helped.


glad to help and that you could find the issue!

1 Like

I suppose that the normalization options saved in the metadata are supported by the tasklib

1 Like