siju-samuel commented on a change in pull request #5848:
URL: https://github.com/apache/incubator-tvm/pull/5848#discussion_r447554160
##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -651,12 +701,43 @@ def convert_shape(self, op):
def convert_relu(self, op):
"""Convert TFLite ReLU"""
+ try:
+ from tflite.ActivationFunctionType import ActivationFunctionType
+ except ImportError:
+ raise ImportError("The tflite package must be installed")
+
input_tensors = self.get_input_tensors(op)
assert len(input_tensors) == 1, "input tensors length should be 1"
-
input_tensor = input_tensors[0]
in_expr = self.get_expr(input_tensor.tensor_idx)
- out = _op.nn.relu(in_expr)
+
+ output_tensors = self.get_output_tensors(op)
+ assert len(output_tensors) == 1, "output tensors length should be 1"
+ output_tensor = output_tensors[0]
+
+ if input_tensor.qnn_params:
+ # Quantize a float value to an quantized integer value
+ scale_val =
get_scalar_from_constant(input_tensor.qnn_params['scale'])
+ zero_point_val =
get_scalar_from_constant(input_tensor.qnn_params['zero_point'])
+
+ output_tensor_type_str =
self.get_tensor_type_str(output_tensor.tensor.Type())
+ out = self.convert_qnn_fused_activation_function(\
+ expr=in_expr,
+ fused_activation_fn=ActivationFunctionType.RELU,
+ scale=scale_val,
+ zero_point=zero_point_val,
+ dtype=output_tensor_type_str)
+ else:
+ out = _op.clip(in_expr, a_min=0, a_max=6)
Review comment:
This should be relu, not clip
##########
File path: tests/python/frontend/tflite/test_forward.py
##########
@@ -1686,38 +1812,33 @@ def test_forward_squeeze():
def _test_quantize_dequantize(data):
""" One iteration of quantize and dequantize """
- # Define a dummy model
+ # Keras model to force TFLite converter to insert 2 TFLite quantize ops.
+ # First TFLite quantize op converts float32 tensor to int8 tensor - Qnn
quantize.
+ # Second TLite quantize op converts int8 tensor to int8 tensor - Qnn
requantize.
Review comment:
TLite -> TFLite
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]