-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tflite regression model gives different output while input is the same #35
Comments
Strange, the interpreter generally works on all tflite models, (not tested for custom ops till now). Please share your These kinds of issues are mostly a result of input/output format mismatch. I recommend using https://pub.dev/packages/tflite_flutter_helper, to eliminate such errors. |
Here is my flutter doctor -v: [√] Flutter (Channel stable, v1.17.5, on Microsoft Windows, locale en-CA) [√] Android toolchain - develop for Android devices (Android SDK version 29.0.3) [√] Android Studio (version 3.6) [√] Connected device (1 available) • No issues found! I also tried tflite_flutter_helper. here is my code:
which doesn't work and gives me the following error: the error referes to this line of code: The problem goes away when I use the ImageProcessorBuilder. Then my code is:
But all the input and output stuff will be incorrect. the input shape should be 13060*3 = 5400 while after using the imageProcessor it's 21600 ( which is 5400 * 4). also the ouput is [35, 204, 170, 74], and all of them are incorrect. Also outputs are integer instead of float. The output should be just 1 float number ( 60.5) |
I also changed the model from a regression to a classifier by making 118 output neurons instead of 1 neuron. I trained the new classifier CNN. The outputs of the classifier is also different from what I'm getting in python from h5 and tflite model. @am15h Did you find a chance to make some test experiments? Is it possible to make an example that classifies MNIST with the package? |
Finally working with tflite_flutter_helper the problem is gone using the following code:
|
I have a tflite regression model, I tested the output of my tflite model in python. It's giving me the same output result as the .h5 model. However, tflite_flutter interpretter gives me wrong results. I have randomly checked 10 different pixels and the input values are totally same. So the input is same, the models are same, but tflite_flutter interpretter gives a different result than tensorflow tflite interpretter.
Here is my code:
var interpreterOptions = InterpreterOptions()..addDelegate(NnApiDelegate());
final interpreter = await Interpreter.fromAsset('modelPath',options: interpreterOptions);
var imageBytes = (await rootBundle.load('imagePath')).buffer;
imageLib.Image oriImage = imageLib.decodePng(imageBytes.asUint8List());
imageLib.Image copyImage = imageLib.copyCrop(oriImage, 60, 0, 60, 30);
var resizedImage = copyImage.getBytes(format: imageLib.Format.rgb);
var input = [];
for (int i = 0 ; i < resizedImage.length ; i++){ input.add(resizedImage[i].toDouble() / 255); }
input = input.reshape([1,30,60,3]);
var output = List(1).reshape([1,1]);
interpreter.run(input, output);
Have you tested the package for DL regression models? I'm using a Deep CNN regressor.
The text was updated successfully, but these errors were encountered: