Skip to content

How to specify shape of input for TFLite model after receiving SavedModel format? #30180

@Oktai15

Description

@Oktai15

I use TF 2.0. Let's suppose I have a model that I successfully converted to SavedModel format. I used following code to convert my model in Imperative API (subclassed tf.keras.Model) to SavedModel:

tf.keras.experimental.export_saved_model(
    model, file_path,
    serving_only=True,
    input_signature=[tf.TensorSpec(shape=[None, None, None, 3], dtype=tf.float32)])

Now I want to convert my model to TFLite, but I have a problem, because I need to specify all dims except for batch. It's okay, but I want to do it after saving my model in SavedModel format. For example, if I want to do several models with different shapes, this feature is required (e.g, [None, 1280, 720, 3], [None, 600, 600, 3] etc.).

How can I do it in step where I convert my model to TFLite? I mean in this step (or something like that after receiving SavedModel format):

converter = tf.lite.TFLiteConverter.from_saved_model(file_path)
tflite_model = converter.convert()

Maybe I can specify input_shape in convert() or another way?

Metadata

Metadata

Assignees

Labels

TF 2.0Issues relating to TensorFlow 2.0comp:liteTF Lite related issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions