wyc-ruiker commented on a change in pull request #4805: [Frontend][TFlite] Add
parser support for relu6, leaky_relu, relu_n1_to_1, log_softmax
URL: https://github.com/apache/incubator-tvm/pull/4805#discussion_r374724376
##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -463,6 +484,114 @@ def convert_relu(self, op):
return out
+ def convert_relu6(self, op):
+ """Convert TFLite ReLU6"""
+ try:
+ from tflite.Operator import Operator
+ except ImportError:
+ raise ImportError("The tflite package must be installed")
+
+ assert isinstance(op, Operator)
+ 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)
+
+ 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:
+ in_expr = self.dequantize(in_expr, input_tensor)
+ out = _op.clip(in_expr, a_min=0, a_max=6)
+ if output_tensor.qnn_params:
+ out = self.quantize(out, output_tensor)
+
+ return out
+
+ def convert_leaky_relu(self, op):
+ """Convert TFLite LEAKY_RELU"""
+ try:
+ from tflite.Operator import Operator
+ from tflite.BuiltinOptions import BuiltinOptions
+ from tflite.LeakyReluOptions import LeakyReluOptions
+ except ImportError:
+ raise ImportError("The tflite package must be installed")
+
+ assert isinstance(op, Operator)
+ 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)
+
+ assert op.BuiltinOptionsType() == BuiltinOptions.LeakyReluOptions
+ op_options = op.BuiltinOptions()
+ leaky_relu_options = LeakyReluOptions()
+ leaky_relu_options.Init(op_options.Bytes, op_options.Pos)
+ alpha_tensor = leaky_relu_options.Alpha()
+
+ 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:
+ in_expr = self.dequantize(in_expr, input_tensor)
+ out = _op.nn.leaky_relu(in_expr, alpha_tensor)
+ if output_tensor.qnn_params:
+ out = self.quantize(out, output_tensor)
+
+ return out
+
+ def convert_relu_n1_to_1(self, op):
+ """Convert TFLite RELU_N1_TO_1"""
Review comment:
Not important, I think it should be `"""Convert TFLite ReLU_n1_to_1"""` to
align with `"""One iteration of ReLU_n1_to_1"""`.
----------------------------------------------------------------
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]
With regards,
Apache Git Services