tflite to JSON to tflite quantization error
tforgaard opened this issue · comments
Hi!
When I convert my int8 quantized tflite model to JSON and back the quantization scale parameters are different (they are correct up to ~4 decimals).
This makes the edgetpu compiler return an error when I try to convert it
edgetpu_compiler -m 13 -sa model_unroll.tflite
Edge TPU Compiler version 16.0.384591198
Started a compilation timeout timer of 180 seconds.
ERROR: :514 output->params.scale == 1. / 256 was not true.
ERROR: Node number 6 (LOGISTIC) failed to prepare.
Compilation failed: Model failed in Tflite interpreter. Please ensure model can be loaded/run in Tflite interpreter.
Compilation child process completed within timeout period.
Compilation failed!
Any idea of how to fix this?
This tool (environment) only provides a simple mechanism to call Google's official tool, flatc
. I don't know what flatc
did when you generated the JSON from tflite.
- Have you checked the contents of the generated JSON file?
- What kind of processing did you do to the JSON file?
If you are only shown the results, it doesn't tell you anything. Therefore, it is a good idea to read and look at the source code for flatbuffers.
https://github.com/google/flatbuffers
- I see now that the scale parameters in the JSON file only contain six decimals
- I originally tried to remove an unnecessary Unpack operation, but I tried to convert to JSON and back without doing any processing as a sanity check as well
I think I found a related issue to work with: google/flatbuffers#5371
I see. This issue seems to have stopped the discussion in the middle. It doesn't look like a good idea to go through a JSON file to process the quantization parameters.
I wish there was a way to read and process the binary value of flatbuffer directly.
Btw, I have tried to convert a byte array of flatbuffer as follows. 2 years ago.
I am parsing the binary values read by TFLite runtime, but I have used JSON for intermediate files, so the same phenomenon is likely occurring.
It might not be the best solution, but I think I'm gonna go for changing the source code for flatbuffers to use more decimals when parsing floats as described here google/flatbuffers#5371 (comment) .
Excellent.
So you are saying that you intend to rewrite and recompile here.
return FloatToString(t, 6);
Yes, I will let you know if it works or not.
Worked like a charm!
Nice! Thanks for updating the repo