You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/03/02 11:17:20 UTC

[GitHub] [incubator-tvm] siju-samuel opened a new pull request #4978: [TFLITE]Activation functions support

siju-samuel opened a new pull request #4978: [TFLITE]Activation functions support
URL: https://github.com/apache/incubator-tvm/pull/4978
 
 
   ELU, LEAKY_RELY, LRN, LOG_SOFTMAX activation functions supported for tflite frontend.
   Along with this PR, i sorted the op list of tflite.
   @FrozenGene @anijain2305 @wyc-ruiker Please help to review. TIA
   
   Thanks for contributing to TVM!   Please refer to guideline https://docs.tvm.ai/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from [Reviewers](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @ them in the pull request thread.
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] wyc-ruiker commented on a change in pull request #4978: [TFLITE]Activation functions support

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] FrozenGene commented on issue #4978: [TFLITE]Activation functions support

Posted by GitBox <gi...@apache.org>.
FrozenGene commented on issue #4978: [TFLITE]Activation functions support
URL: https://github.com/apache/incubator-tvm/pull/4978#issuecomment-597421428
 
 
   Thanks, it is merged

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] siju-samuel commented on a change in pull request #4978: [TFLITE]Activation functions support

Posted by GitBox <gi...@apache.org>.
siju-samuel commented on a change in pull request #4978: [TFLITE]Activation functions support
URL: https://github.com/apache/incubator-tvm/pull/4978#discussion_r390719573
 
 

 ##########
 File path: python/tvm/relay/frontend/tflite.py
 ##########
 @@ -62,70 +62,72 @@ def __init__(self, model, subgraph, exp_tab):
         # Add more operators
         self.convert_map = {
             'ABS': self.convert_abs,
+            'ADD': self.convert_add,
+            'AVERAGE_POOL_2D': self.convert_average_pool2d,
+            'BATCH_TO_SPACE_ND': self.convert_batch_to_space_nd,
+            'CAST': self.convert_cast,
+            'CEIL': self.convert_ceil,
+            'CONCATENATION': self.convert_concatenation,
+            'CONV_2D': self.convert_conv2d,
+            'COS': self.convert_cos,
+            'DEPTHWISE_CONV_2D': self.convert_depthwise_conv2d,
+            'DETECTION_POSTPROCESS': self.convert_detection_postprocess,
+            'DIV': self.convert_div,
+            'ELU': self.convert_elu,
+            'EQUAL': self.convert_equal,
 
 Review comment:
   @FrozenGene Yes. its better to be in alphabetical order like TF. And it reduces the conflicts while merging PR.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] wyc-ruiker commented on a change in pull request #4978: [TFLITE]Activation functions support

Posted by GitBox <gi...@apache.org>.
wyc-ruiker commented on a change in pull request #4978: [TFLITE]Activation functions support
URL: https://github.com/apache/incubator-tvm/pull/4978#discussion_r386865734
 
 

 ##########
 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:
   > Yes, same, nhwc format. axis=3
   
   OK, maybe we could use `axis = 3` same as tensorflow.py.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] inadob commented on issue #4978: [TFLITE]Activation functions support

Posted by GitBox <gi...@apache.org>.
inadob commented on issue #4978: [TFLITE]Activation functions support
URL: https://github.com/apache/incubator-tvm/pull/4978#issuecomment-593361049
 
 
   Some of the functions already exist in another PR #4805

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] siju-samuel commented on issue #4978: [TFLITE]Activation functions support

Posted by GitBox <gi...@apache.org>.
siju-samuel commented on issue #4978: [TFLITE]Activation functions support
URL: https://github.com/apache/incubator-tvm/pull/4978#issuecomment-593364564
 
 
   @inadob thanks for letting me know., i didnt noticed, i will update my PR.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] inadob commented on a change in pull request #4978: [TFLITE]Activation functions support

Posted by GitBox <gi...@apache.org>.
inadob commented on a change in pull request #4978: [TFLITE]Activation functions support
URL: https://github.com/apache/incubator-tvm/pull/4978#discussion_r387103760
 
 

 ##########
 File path: tests/python/frontend/tflite/test_forward.py
 ##########
 @@ -1688,6 +1715,9 @@ def test_forward_mediapipe_hand_landmark():
     test_forward_prelu()
     test_forward_fully_connected()
     test_forward_l2_normalization()
+    # The below activations come with TFLite >= 1.14.0 fbs schema
+    if package_version.parse(tf.VERSION) >= package_version.parse('1.14.0'):
 
 Review comment:
   move the version check inside `test_forward_local_response_normalization()`

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] inadob commented on a change in pull request #4978: [TFLITE]Activation functions support

Posted by GitBox <gi...@apache.org>.
inadob commented on a change in pull request #4978: [TFLITE]Activation functions support
URL: https://github.com/apache/incubator-tvm/pull/4978#discussion_r387106930
 
 

 ##########
 File path: python/tvm/relay/frontend/tflite.py
 ##########
 @@ -454,6 +456,42 @@ 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
+        axis = 3 # NHWC format
+        out = _op.nn.lrn(in_expr, size=size, axis=axis, bias=bias, alpha=alpha, beta=beta)
+        return out
 
 Review comment:
   I think it would be better to add an empty line before the **return**. The same applies to the rest of the functions.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] inadob edited a comment on issue #4978: [TFLITE]Activation functions support

Posted by GitBox <gi...@apache.org>.
inadob edited a comment on issue #4978: [TFLITE]Activation functions support
URL: https://github.com/apache/incubator-tvm/pull/4978#issuecomment-593361049
 
 
   Some of the operations already exist in another PR #4805

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] siju-samuel commented on issue #4978: [TFLITE]Activation functions support

Posted by GitBox <gi...@apache.org>.
siju-samuel commented on issue #4978: [TFLITE]Activation functions support
URL: https://github.com/apache/incubator-tvm/pull/4978#issuecomment-596482023
 
 
   Rebased to latest.
   @FrozenGene @anijain2305 please review and help to merge. TIA

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] inadob commented on a change in pull request #4978: [TFLITE]Activation functions support

Posted by GitBox <gi...@apache.org>.
inadob commented on a change in pull request #4978: [TFLITE]Activation functions support
URL: https://github.com/apache/incubator-tvm/pull/4978#discussion_r387110638
 
 

 ##########
 File path: python/tvm/relay/frontend/tflite.py
 ##########
 @@ -685,6 +723,22 @@ def convert_neg(self, op):
                 'TFlite quantized NEG operator is not supported yet.')
         return self._convert_unary_elemwise(_op.negative, op)
 
+    def convert_elu(self, op):
+        """Convert TFLite ELU"""
 
 Review comment:
   Please, add the necessary imports.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] FrozenGene commented on a change in pull request #4978: [TFLITE]Activation functions support

Posted by GitBox <gi...@apache.org>.
FrozenGene commented on a change in pull request #4978: [TFLITE]Activation functions support
URL: https://github.com/apache/incubator-tvm/pull/4978#discussion_r389615250
 
 

 ##########
 File path: python/tvm/relay/frontend/tflite.py
 ##########
 @@ -62,70 +62,72 @@ def __init__(self, model, subgraph, exp_tab):
         # Add more operators
         self.convert_map = {
             'ABS': self.convert_abs,
+            'ADD': self.convert_add,
+            'AVERAGE_POOL_2D': self.convert_average_pool2d,
+            'BATCH_TO_SPACE_ND': self.convert_batch_to_space_nd,
+            'CAST': self.convert_cast,
+            'CEIL': self.convert_ceil,
+            'CONCATENATION': self.convert_concatenation,
+            'CONV_2D': self.convert_conv2d,
+            'COS': self.convert_cos,
+            'DEPTHWISE_CONV_2D': self.convert_depthwise_conv2d,
+            'DETECTION_POSTPROCESS': self.convert_detection_postprocess,
+            'DIV': self.convert_div,
+            'ELU': self.convert_elu,
+            'EQUAL': self.convert_equal,
 
 Review comment:
   Do you change it as alphabetical order?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] FrozenGene merged pull request #4978: [TFLITE]Activation functions support

Posted by GitBox <gi...@apache.org>.
FrozenGene merged pull request #4978: [TFLITE]Activation functions support
URL: https://github.com/apache/incubator-tvm/pull/4978
 
 
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] siju-samuel commented on a change in pull request #4978: [TFLITE]Activation functions support

Posted by GitBox <gi...@apache.org>.
siju-samuel commented on a change in pull request #4978: [TFLITE]Activation functions support
URL: https://github.com/apache/incubator-tvm/pull/4978#discussion_r386862168
 
 

 ##########
 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:
   Yes, same, nhwc format. axis=3 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services