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/01/14 15:10:17 UTC
[GitHub] [incubator-tvm] inadob opened a new pull request #4704:
[Relay][Frontend][TFLite] Add parser support for arg_min_max
inadob opened a new pull request #4704: [Relay][Frontend][TFLite] Add parser support for arg_min_max
URL: https://github.com/apache/incubator-tvm/pull/4704
* this implementation supports only the case when the axis is a scalar
* tflite 1.13 removes all dims of size 1, Relay doesn't do this
* WARNING: every newer version of tflite > 1.13 needs keepdims=TRUE
in the corresponding Relay operation. If there is a way to check the tflite version that was used to
convert the model passed to the parser, I will be happy to implement that.
----------------------------------------------------------------
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 #4704:
[Relay][Frontend][TFLite] Add parser support for arg_min_max
Posted by GitBox <gi...@apache.org>.
inadob commented on a change in pull request #4704: [Relay][Frontend][TFLite] Add parser support for arg_min_max
URL: https://github.com/apache/incubator-tvm/pull/4704#discussion_r374611987
##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -826,6 +828,50 @@ def _convert_reduce_prod(self, op):
def _convert_reduce_sum(self, op):
return self._convert_reduce(_op.reduce.sum, op)
+ def _convert_arg_min_max(self, relay_op, op):
+ """Generic method to convert TFLite arg_min_max"""
+ try:
+ from tflite.Operator import Operator
+ from tflite.BuiltinOptions import BuiltinOptions
+ from tflite.ArgMinOptions import ArgMinOptions
+ from tflite.ArgMaxOptions import ArgMaxOptions
+ 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) == 2, "input tensors length should be 2"
+
+ input_tensor = input_tensors[0]
+ in_expr = self.get_expr(input_tensor.tensor_idx)
+ axis_tensor = input_tensors[1]
+ # we support the case when the axis is a scalar not a tensor
+ axis_value = int(self.get_tensor_value(axis_tensor))
+
+ if op.BuiltinOptionsType() == BuiltinOptions.ArgMinOptions:
+ arg_min_max_options = ArgMinOptions()
+ elif op.BuiltinOptionsType() == BuiltinOptions.ArgMaxOptions:
+ arg_min_max_options = ArgMaxOptions()
+ op_options = op.BuiltinOptions()
+ arg_min_max_options.Init(op_options.Bytes, op_options.Pos)
+ output_dtype = arg_min_max_options.OutputType()
+
+ # set keepdims to True since tflite 1.13 removes all dims of size 1
+ # WARNING: all other versions of tflite > 1.13 need keepdims=False
Review comment:
The issue here is that we can't use the same TFLite version check as we do in the tests since I do not think there is a way to get such information from a model that you pass to the parser.
----------------------------------------------------------------
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 #4704:
[Relay][Frontend][TFLite] Add parser support for arg_min_max
Posted by GitBox <gi...@apache.org>.
inadob commented on a change in pull request #4704: [Relay][Frontend][TFLite] Add parser support for arg_min_max
URL: https://github.com/apache/incubator-tvm/pull/4704#discussion_r385636005
##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -826,6 +828,50 @@ def _convert_reduce_prod(self, op):
def _convert_reduce_sum(self, op):
return self._convert_reduce(_op.reduce.sum, op)
+ def _convert_arg_min_max(self, relay_op, op):
+ """Generic method to convert TFLite arg_min_max"""
+ try:
+ from tflite.Operator import Operator
+ from tflite.BuiltinOptions import BuiltinOptions
+ from tflite.ArgMinOptions import ArgMinOptions
+ from tflite.ArgMaxOptions import ArgMaxOptions
+ 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) == 2, "input tensors length should be 2"
+
+ input_tensor = input_tensors[0]
+ in_expr = self.get_expr(input_tensor.tensor_idx)
+ axis_tensor = input_tensors[1]
+ # we support the case when the axis is a scalar not a tensor
+ axis_value = int(self.get_tensor_value(axis_tensor))
+
+ if op.BuiltinOptionsType() == BuiltinOptions.ArgMinOptions:
+ arg_min_max_options = ArgMinOptions()
+ elif op.BuiltinOptionsType() == BuiltinOptions.ArgMaxOptions:
+ arg_min_max_options = ArgMaxOptions()
+ op_options = op.BuiltinOptions()
+ arg_min_max_options.Init(op_options.Bytes, op_options.Pos)
+ output_dtype = arg_min_max_options.OutputType()
+
+ # set keepdims to True since tflite 1.13 removes all dims of size 1
+ # WARNING: all other versions of tflite > 1.13 need keepdims=False
Review comment:
After doing some further investigation, it turned out that `arg_min` and `arg_max` are fundamentally broken in TFL 1.13 since the behaviour described in the in flatbuff file is different from what is actually calculated if we do the inference directly (as in all our parser tests).
You can see the changes between TFL 1.13 and TFL 1.14 for these ops here: https://github.com/tensorflow/tensorflow/commit/1d0552e94d4e091ce03248675ac92c1e1e0accae
----------------------------------------------------------------
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 #4704:
[Relay][Frontend][TFLite] Add parser support for arg_min_max
Posted by GitBox <gi...@apache.org>.
inadob commented on a change in pull request #4704: [Relay][Frontend][TFLite] Add parser support for arg_min_max
URL: https://github.com/apache/incubator-tvm/pull/4704#discussion_r374611987
##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -826,6 +828,50 @@ def _convert_reduce_prod(self, op):
def _convert_reduce_sum(self, op):
return self._convert_reduce(_op.reduce.sum, op)
+ def _convert_arg_min_max(self, relay_op, op):
+ """Generic method to convert TFLite arg_min_max"""
+ try:
+ from tflite.Operator import Operator
+ from tflite.BuiltinOptions import BuiltinOptions
+ from tflite.ArgMinOptions import ArgMinOptions
+ from tflite.ArgMaxOptions import ArgMaxOptions
+ 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) == 2, "input tensors length should be 2"
+
+ input_tensor = input_tensors[0]
+ in_expr = self.get_expr(input_tensor.tensor_idx)
+ axis_tensor = input_tensors[1]
+ # we support the case when the axis is a scalar not a tensor
+ axis_value = int(self.get_tensor_value(axis_tensor))
+
+ if op.BuiltinOptionsType() == BuiltinOptions.ArgMinOptions:
+ arg_min_max_options = ArgMinOptions()
+ elif op.BuiltinOptionsType() == BuiltinOptions.ArgMaxOptions:
+ arg_min_max_options = ArgMaxOptions()
+ op_options = op.BuiltinOptions()
+ arg_min_max_options.Init(op_options.Bytes, op_options.Pos)
+ output_dtype = arg_min_max_options.OutputType()
+
+ # set keepdims to True since tflite 1.13 removes all dims of size 1
+ # WARNING: all other versions of tflite > 1.13 need keepdims=False
Review comment:
The issue here is that we can't use the same 'TFLite version' check as we do in the tests since I do not think there is a way to get the TFLite version used to convert a model that you pass to the parser.
----------------------------------------------------------------
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] anijain2305 commented on a change in pull request
#4704: [Relay][Frontend][TFLite] Add parser support for arg_min_max
Posted by GitBox <gi...@apache.org>.
anijain2305 commented on a change in pull request #4704: [Relay][Frontend][TFLite] Add parser support for arg_min_max
URL: https://github.com/apache/incubator-tvm/pull/4704#discussion_r374357079
##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -826,6 +828,50 @@ def _convert_reduce_prod(self, op):
def _convert_reduce_sum(self, op):
return self._convert_reduce(_op.reduce.sum, op)
+ def _convert_arg_min_max(self, relay_op, op):
+ """Generic method to convert TFLite arg_min_max"""
+ try:
+ from tflite.Operator import Operator
+ from tflite.BuiltinOptions import BuiltinOptions
+ from tflite.ArgMinOptions import ArgMinOptions
+ from tflite.ArgMaxOptions import ArgMaxOptions
+ 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) == 2, "input tensors length should be 2"
+
+ input_tensor = input_tensors[0]
+ in_expr = self.get_expr(input_tensor.tensor_idx)
+ axis_tensor = input_tensors[1]
+ # we support the case when the axis is a scalar not a tensor
Review comment:
A check will be helpful here along with the comment
----------------------------------------------------------------
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 #4704:
[Relay][Frontend][TFLite] Add parser support for arg_min_max
Posted by GitBox <gi...@apache.org>.
inadob commented on a change in pull request #4704: [Relay][Frontend][TFLite] Add parser support for arg_min_max
URL: https://github.com/apache/incubator-tvm/pull/4704#discussion_r385642946
##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -826,6 +828,50 @@ def _convert_reduce_prod(self, op):
def _convert_reduce_sum(self, op):
return self._convert_reduce(_op.reduce.sum, op)
+ def _convert_arg_min_max(self, relay_op, op):
+ """Generic method to convert TFLite arg_min_max"""
+ try:
+ from tflite.Operator import Operator
+ from tflite.BuiltinOptions import BuiltinOptions
+ from tflite.ArgMinOptions import ArgMinOptions
+ from tflite.ArgMaxOptions import ArgMaxOptions
+ 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) == 2, "input tensors length should be 2"
+
+ input_tensor = input_tensors[0]
+ in_expr = self.get_expr(input_tensor.tensor_idx)
+ axis_tensor = input_tensors[1]
+ # we support the case when the axis is a scalar not a tensor
+ axis_value = int(self.get_tensor_value(axis_tensor))
+
+ if op.BuiltinOptionsType() == BuiltinOptions.ArgMinOptions:
+ arg_min_max_options = ArgMinOptions()
+ elif op.BuiltinOptionsType() == BuiltinOptions.ArgMaxOptions:
+ arg_min_max_options = ArgMaxOptions()
+ op_options = op.BuiltinOptions()
+ arg_min_max_options.Init(op_options.Bytes, op_options.Pos)
+ output_dtype = arg_min_max_options.OutputType()
+
+ # set keepdims to True since tflite 1.13 removes all dims of size 1
+ # WARNING: all other versions of tflite > 1.13 need keepdims=False
Review comment:
@mshawcroft @u99127
----------------------------------------------------------------
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] tqchen commented on issue #4704:
[Relay][Frontend][TFLite] Add parser support for arg_min_max
Posted by GitBox <gi...@apache.org>.
tqchen commented on issue #4704: [Relay][Frontend][TFLite] Add parser support for arg_min_max
URL: https://github.com/apache/incubator-tvm/pull/4704#issuecomment-591702122
ping @inadob @anijain2305 please followup
----------------------------------------------------------------
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] anijain2305 commented on a change in pull request
#4704: [Relay][Frontend][TFLite] Add parser support for arg_min_max
Posted by GitBox <gi...@apache.org>.
anijain2305 commented on a change in pull request #4704: [Relay][Frontend][TFLite] Add parser support for arg_min_max
URL: https://github.com/apache/incubator-tvm/pull/4704#discussion_r374358802
##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -826,6 +828,50 @@ def _convert_reduce_prod(self, op):
def _convert_reduce_sum(self, op):
return self._convert_reduce(_op.reduce.sum, op)
+ def _convert_arg_min_max(self, relay_op, op):
+ """Generic method to convert TFLite arg_min_max"""
+ try:
+ from tflite.Operator import Operator
+ from tflite.BuiltinOptions import BuiltinOptions
+ from tflite.ArgMinOptions import ArgMinOptions
+ from tflite.ArgMaxOptions import ArgMaxOptions
+ 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) == 2, "input tensors length should be 2"
+
+ input_tensor = input_tensors[0]
+ in_expr = self.get_expr(input_tensor.tensor_idx)
+ axis_tensor = input_tensors[1]
+ # we support the case when the axis is a scalar not a tensor
+ axis_value = int(self.get_tensor_value(axis_tensor))
+
+ if op.BuiltinOptionsType() == BuiltinOptions.ArgMinOptions:
+ arg_min_max_options = ArgMinOptions()
+ elif op.BuiltinOptionsType() == BuiltinOptions.ArgMaxOptions:
+ arg_min_max_options = ArgMaxOptions()
+ op_options = op.BuiltinOptions()
+ arg_min_max_options.Init(op_options.Bytes, op_options.Pos)
+ output_dtype = arg_min_max_options.OutputType()
+
+ # set keepdims to True since tflite 1.13 removes all dims of size 1
+ # WARNING: all other versions of tflite > 1.13 need keepdims=False
Review comment:
Can we add a TFLite version check?
----------------------------------------------------------------
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 #4704:
[Relay][Frontend][TFLite] Add parser support for arg_min_max
Posted by GitBox <gi...@apache.org>.
inadob commented on issue #4704: [Relay][Frontend][TFLite] Add parser support for arg_min_max
URL: https://github.com/apache/incubator-tvm/pull/4704#issuecomment-574223969
can you please review this PR @anijain2305 @FrozenGene
----------------------------------------------------------------
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 closed pull request #4704: [Relay][Frontend][TFLite] Add parser support for arg_min_max
Posted by GitBox <gi...@apache.org>.
inadob closed pull request #4704:
URL: https://github.com/apache/incubator-tvm/pull/4704
----------------------------------------------------------------
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
[GitHub] [incubator-tvm] tqchen commented on pull request #4704: [Relay][Frontend][TFLite] Add parser support for arg_min_max
Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #4704:
URL: https://github.com/apache/incubator-tvm/pull/4704#issuecomment-650208021
ping @inadob @anijain2305
----------------------------------------------------------------
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