tensorflow: tf.lite.TFLiteConverter crashes when converting Keras model
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): OSX 10.15.5- TensorFlow installed from (source or binary): binary
- TensorFlow version (use command below): v1.12.1-37224-ga6cd18a133 2.4.0-dev20200722
- Python version: 3.7
Describe the current behavior
It throws exception
Describe the expected behavior It should finish the conversion successfully
Standalone code to reproduce the issue
import numpy as np
import tensorflow as tf
model = tf.keras.models.Sequential([
tf.keras.layers.Input(shape=(28, 28), name='input'),
tf.keras.layers.Bidirectional(
tf.keras.layers.LSTM(20, return_sequences=True)),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(10, activation=tf.nn.softmax, name='output')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.summary()
run_model = tf.function(lambda x: model(x))
# This is important, let's fix the input size.
BATCH_SIZE = 1
STEPS = 28
INPUT_SIZE = 28
concrete_func = run_model.get_concrete_function(
tf.TensorSpec([BATCH_SIZE, STEPS, INPUT_SIZE], model.inputs[0].dtype))
# model directory.
MODEL_DIR = "keras_lstm"
# converter = tf.lite.TFLiteConverter.from_concrete_functions([concrete_func])
# converter = tf.lite.TFLiteConverter.from_saved_model(MODEL_DIR)
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.experimental_new_converter = True
tflite_model = converter.convert()
with tf.io.gfile.GFile('tflite_test.tflite', 'wb') as f:
f.write(tflite_model)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (10 by maintainers)
@renjie-liu Of course not. You figured out the root cause, but it still crashes. Is fused op supposed to throw exception?