diff --git a/python/tvm/relay/frontend/tflite.py b/python/tvm/relay/frontend/tflite.py index 200352c57fd2..fd56ff5f04c4 100644 --- a/python/tvm/relay/frontend/tflite.py +++ b/python/tvm/relay/frontend/tflite.py @@ -2763,7 +2763,12 @@ def convert_quantize(self, op): assert len(input_tensors) == 1, "input tensors length should be 1" input_tensor = input_tensors[0] input_tensor_type_str = self.get_tensor_type_str(input_tensor.tensor.Type()) - in_expr = self.get_expr(input_tensor.tensor_idx) + + if self.has_expr(input_tensor.tensor_idx): + in_expr = self.get_expr(input_tensor.tensor_idx) + else: + in_value = self.get_tensor_value(input_tensor) + in_expr = self.exp_tab.new_const(in_value, dtype=self.get_tensor_type_str(input_tensor.tensor.Type())) output_tensors = self.get_output_tensors(op) assert len(output_tensors) == 1, "output tensors length should be 1" diff --git a/tests/python/frontend/tflite/test_forward.py b/tests/python/frontend/tflite/test_forward.py index 4d7fc06c7fba..656e8aff3988 100644 --- a/tests/python/frontend/tflite/test_forward.py +++ b/tests/python/frontend/tflite/test_forward.py @@ -1888,7 +1888,7 @@ def _test_quantize_dequantize(data): # First TFLite quantize op converts float32 tensor to int8 tensor - Qnn quantize. # Second TFLite quantize op converts int8 tensor to int8 tensor - Qnn requantize. data_in = tf.keras.layers.Input(shape=data.shape[1:]) - relu = tf.keras.layers.ReLU()(data_in) + relu = tf.keras.layers.ReLU()(data) add = tf.keras.layers.Add()([data_in, relu]) concat = tf.keras.layers.Concatenate(axis=0)([relu, add]) keras_model = tf.keras.models.Model(inputs=data_in, outputs=concat)