Closed mpariente closed 3 years ago
the old ophint-based method does not work well with resource variables (but it should work fine with 1.15, I have just tried in colab)
for new keras lstm/rnn, please refer here: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/examples/experimental_new_converter/keras_lstm.ipynb
thanks
Thanks a lot for the example, I'm going to try that out.
the old ophint-based method does not work well with resource variables (but it should work fine with 1.15, I have just tried in colab)
Hmm, I did run this script with tf1.15.. Did you try the snippet I provided? Are you able to reproduce the error? And could I ask what you tried in colab?
for new keras lstm/rnn, please refer here: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/examples/experimental_new_converter/keras_lstm.ipynb
Thanks for that, where can I find some more info on the experimental_new_converter please? I'm struggling with post-training quantization with pretrained LSTMs for a while now..
I used colab to import the python notebook and ran directly.
Can you try the new approach and see if the post-training works for you?
Thanks a lot!
On Thu, Dec 19, 2019 at 3:12 PM Pariente Manuel notifications@github.com wrote:
Thanks a lot for the example, I'm going to try that out.
the old ophint-based method does not work well with resource variables (but it should work fine with 1.15, I have just tried in colab) Hmm, I did run this script with tf1.15.. Did you try the snippet I provided? Are you able to reproduce the error? And could I ask what you tried in colab?
for new keras lstm/rnn, please refer here: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/examples/experimental_new_converter/keras_lstm.ipynb
Thanks for that, where can I find some more info on the experimental_new_converter please? I'm struggling with post-training quantization with pretrained LSTMs for a while now..
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/tensorflow/tensorflow/issues/35168?email_source=notifications&email_token=AIURNGKXI2OQXKXMIDIO6ETQZMNE7A5CNFSM4J3THI22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHIVCVA#issuecomment-567365972, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIURNGKBUB4OWOMIYOZVIJ3QZMNE7ANCNFSM4J3THI2Q .
-- Renjie Liu
renjieliu@google.com +1 (650) 253-4359
I used colab to import the python notebook and ran directly. Ok, that worked for me as well, I'll try to see why it failed with the script I made from the notebook..
Can you try the new approach and see if the post-training works for you?
It does not, sadly. If I add :
converter.target_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.uint8
converter.inference_output_type = tf.uint8
it works but the whole model is still in float32 (I saved the model and checked it with netron)
If I add,
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.uint8
converter.inference_output_type = tf.uint8
It does not work. Here is the traceback :
2019-12-19 10:06:42.831816: E tensorflow/lite/tools/optimize/quantize_weights.cc:351] Quantize weights tool only supports tflite models with one subgraph.
Traceback (most recent call last):
File "/home/mparient/.virtualenvs/tf_dev/bin/toco_from_protos", line 8, in <module>
sys.exit(main())
File "/home/mparient/.virtualenvs/tf_dev/lib/python3.6/site-packages/tensorflow_core/lite/toco/python/toco_from_protos.py", line 93, in main
app.run(main=execute, argv=[sys.argv[0]] + unparsed)
File "/home/mparient/.virtualenvs/tf_dev/lib/python3.6/site-packages/tensorflow_core/python/platform/app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "/home/mparient/.virtualenvs/tf_dev/lib/python3.6/site-packages/absl/app.py", line 299, in run
_run_main(main, args)
File "/home/mparient/.virtualenvs/tf_dev/lib/python3.6/site-packages/absl/app.py", line 250, in _run_main
sys.exit(main(argv))
File "/home/mparient/.virtualenvs/tf_dev/lib/python3.6/site-packages/tensorflow_core/lite/toco/python/toco_from_protos.py", line 56, in execute
enable_mlir_converter)
Exception: Quantize weights transformation failed.
Actually, sorry, I was not clear, I have been able to convert LSTM models to tflite in 1.15 using post-training quantization but some quantization nodes are left in the graph and the edgetpu_compiler
seems not to like them.
Hi Jian, can you help take a look about the lstm quantization? thanks
Any update on this issue?
@mpariente we announced Keras TF 2.0 LSTM to fused TFLite LSTM conversion support. Please see below: https://groups.google.com/a/tensorflow.org/g/tflite/c/Ub4apUvblN8
Do you want to try this? This is an e2e solution that works with the post training quantization for LSTM. Would love to see if this works for you.
Going to throw in a plug here that I successfully dynamically quantized a Torch LSTM model and deployed it on a mobile device. Was also able to track internal state and do flow controlled updates to hidden states with a stateful Torch JIT'd object (impossible in TFLite). Full architecture 9 layer LSTM (quantized to 60 Mb) running at 2x real time on a mobile CPU that was streaming audio data for speech recognition.
Hi There,
We are checking to see if you still need help on this, as you are using an older version of tensorflow which is officially considered end of life . We recommend that you upgrade to the latest 2.x version and let us know if the issue still persists in newer versions. Please open a new issue for any help you need against 2.x, and we will get you the right help.
This issue will be closed automatically 7 days from now. If you still need help with this issue, please provide us with more information.
@tensorflow/micro
System information
pip install tensorflow
Describe the problem The example provided here doesn't work. Please provide the exact sequence of commands/steps when you ran into the problem If I put together the example, it gives this :
When ran simply like
python example.py --model_dir lstms/ --tflite_model_file lstms/model.tflite
, I get the following error message :