wyc-ruiker commented on a change in pull request #4978: [TFLITE]Activation functions support URL: https://github.com/apache/incubator-tvm/pull/4978#discussion_r386856187
########## File path: python/tvm/relay/frontend/tflite.py ########## @@ -454,6 +456,45 @@ def convert_l2_normalization(self, op): return out + def convert_lrn(self, op): + """Convert TFLite LOCAL_RESPONSE_NORMALIZATION """ + try: + from tflite.Operator import Operator + from tflite.BuiltinOptions import BuiltinOptions + from tflite.LocalResponseNormalizationOptions import LocalResponseNormalizationOptions + except ImportError: + raise ImportError("The tflite package must be installed") + + assert isinstance(op, Operator) + if self.is_quantized(op): + raise tvm.error.OpNotImplemented( + 'TFlite quantized LRN operator is not supported yet.') + + 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" + + assert op.BuiltinOptionsType() == BuiltinOptions.LocalResponseNormalizationOptions + op_options = op.BuiltinOptions() + lrn_options = LocalResponseNormalizationOptions() + lrn_options.Init(op_options.Bytes, op_options.Pos) + radius = lrn_options.Radius() + bias = lrn_options.Bias() + alpha = lrn_options.Alpha() + beta = lrn_options.Beta() + size = (radius * 2) + 1 + alpha = alpha * size + + # TFLite supports lrn only over the last dim + input_tensor_rank = len(input_tensor.tensor.ShapeAsNumpy()) + axis = input_tensor_rank - 1 Review comment: I observed that here is `attr_new['axis'] = 3 # Fix axis, NHWC format` in tensorflow.py. Are the two implementations consistent? ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services