tensorflow: Failed to convert weights to 8 bit precision: "Quantize weights tool only supports tflite models with one subgraph"
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Google Colab (GPU)
- TensorFlow installed from (source or binary): Binary
- TensorFlow version (use command below): 2.1.0-dev20191217
- Python version: 3
- Exact command to reproduce:
!pip install tf-nightly
import tensorflow as tf
from tensorflow.keras import Sequential
from tensorflow.keras.layers import GRU, Dense, Dropout
model = Sequential()
model.add(GRU(100, activation='relu', return_sequences=False, input_shape=(128,2)))
model.add(Dropout(0.2))
model.add(Dense(11, activation='softmax'))
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.experimental_new_converter = True
tflite_model = converter.convert()
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
tflite_model_quant = converter.convert()
Error message
E tensorflow/lite/tools/optimize/quantize_weights.cc:351] Quantize weights tool only supports tflite models with one subgraph.
Describe the problem
First, I used the new converter (with the experimental flag converter.experimental_new_converter = True) to convert an RNN model from TensorFlow to TensorFlow Lite’s flat buffer format, as suggested in the issue #32608.
This works correctly, but then when I try to perform a post-training weight quantization, I got an error saying that the quantize weights tool only supports tflite models with one subgraph.
Is there a problem with my procedure? Or is that feature not yet supported? In that case, I would like to request this feature.
Thanks in advance for your help.
Source code / logs
The attached file can be used to reproduce the error with a trained model (.h5). GRU_1L.zip
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 26 (4 by maintainers)
I have a very similar setup, with LSTM layers. I can convert the model with experimental set up and the inference works, but as soon as I try to do post training optimization in form of weight quantization, I get the same error.