0

I have a model of saved_model format, and I need convert it to tflite with quantization.

The problem is model have two input nodes, named "serving_default_input.1" and "serving_default_input.81", and I'm confuse about code of convertion.

I write below code with reference(link).

import numpy as np
import tensorflow as tf

def representative_dataset_gen():
    for _ in range(20):
        yield [{
                "serving_default_input.1": np.random.rand(1, 3, 240, 320).astype(np.float32),
                "serving_default_input.81": np.random.rand(1, 3, 240, 320).astype(np.float32)
                }]

converter = tf.lite.TFLiteConverter.from_saved_model("./stereonet_240x320")
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.uint8  # or tf.int8
converter.inference_output_type = tf.uint8  # or tf.int8
converter.representative_dataset = representative_dataset_gen
tflite_model = converter.convert()
with open("./stereonet_240x320.tflite", "wb") as fp:
    fp.write(tflite_model)

How do I fix my code?

Thanks for your help!!!

heiheihei
  • 659
  • 1
  • 6
  • 15

0 Answers0