tensorflow / flutter-tflite

Apache License 2.0
464 stars 126 forks source link

If the newest version support float model? #179

Open zhaoxiaohai opened 8 months ago

zhaoxiaohai commented 8 months ago

I have an Android application, which uses the example . In this application, I use my own float model, which can run normally. When I try to use flutter for development according to your current example with the same model, the results are not ideal. My understanding is that the your demo uses a quant model. I want to know whether there is a problem with my usage or my model. Thank you.

anish891 commented 8 months ago

A loss of precision due to quantization may have an impact on the model's performance. Verify whether the quantized model from the Flutter example differs noticeably from the float model you started with. You may wish to experiment with alternative quantization settings or even utilize the original float model in your Flutter application if the quantization procedure generates too much inaccuracy.

qu-ngx commented 7 months ago

@zhaoxiaohai I am not sure if my answer is correct. But here is my thought: the example uses unsigned integer 8 bit list to declare the type of the image (decoded image). The original model or "float" model is a 32 bit model, which means there is a huge gap in precision. Quantization shrinks down the model from 32 bit to 8 bit to befit the images that you feed to the model (I would call this bit-overflows). I used to get some bad fluke ML inferences in which they only predict 1 label for every object I tried. I guess this is not about problem with the model, but how we implement it. Fun thing to do: try declaring the input image as Uint32List and predict it with your orginal or float model (I have never tried it before). But my speculation is that either the model or the input image staying in 8 bit is to optimize the performance of tflite models on Edge Mobile Devices, which have resource constraints. If your fun implementation doesn't work, you are more than welcome to quantize the model for your smoother implementation.