tflite convert() reduces model input shape

29 Views Asked by At

I am converting a tf model to tflite, but the conversion seems to change the input shape for no apparent reason

import os
import tensorflow as tf
from basic_pitch import ICASSP_2022_MODEL_PATH
model_best_path = os.path.join(ICASSP_2022_MODEL_PATH, 'saved_model.pb')
model_best_dir = str(ICASSP_2022_MODEL_PATH)
model_original = tf.saved_model.load(model_best_dir)

input_original = tf.convert_to_tensor(np.ones([11,43844,1]), dtype=tf.float32)
output_original = model_original(input_original)

# Converting a SavedModel to a TensorFlow Lite model.
converter = tf.lite.TFLiteConverter.from_saved_model(model_best_dir)
tflite_model = converter.convert()
with open('quantized_model.tflite', 'wb') as f:
    f.write(tflite_model)

interpreter = tf.lite.Interpreter(model_path='quantized_model.tflite')
interpreter.allocate_tensors()
input_quantized = interpreter.get_input_details()

print(input_quantized[0]['shape'], input_original.shape)

The output is

[    1 43844     1] (11, 43844, 1)

Notice that I've utilized from_saved_model() instead of from_keras_model() as suggested HERE. Why is this happening?

0

There are 0 best solutions below