u99127 commented on a change in pull request #4788: [FRONTEND][TFLITE]Gather,
StridedSlice op support added
URL: https://github.com/apache/incubator-tvm/pull/4788#discussion_r381990653
##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -852,6 +855,193 @@ def convert_logical_or(self, op):
"""Convert tflite LOGICAL_OR"""
return self._convert_logical_binary(_op.logical_or, op)
+ def convert_gather(self, op):
+ """Method to Convert TFLite GATHER operator"""
+ try:
+ from tflite.BuiltinOptions import BuiltinOptions
+ from tflite.GatherOptions import GatherOptions
+ from tflite.TensorType import TensorType
+ except ImportError:
+ raise ImportError("The tflite package must be installed")
+
+ input_tensors = self.get_input_tensors(op)
+ assert len(input_tensors) == 2, "input tensors length should be 2"
+
+ data = self.get_expr(input_tensors[0].tensor_idx)
+
+ indices = input_tensors[1]
+ indices_type = indices.tensor.Type()
+ assert indices_type in (TensorType.INT32, TensorType.INT64)
+ indices_type_str = self.get_tensor_type_str(indices_type)
+ indices = self.exp_tab.new_const(self.get_tensor_value(indices),
+ dtype=indices_type_str)
+
+ assert op.BuiltinOptionsType() == BuiltinOptions.GatherOptions
+ op_options = op.BuiltinOptions()
+ gather_options = GatherOptions()
+ gather_options.Init(op_options.Bytes, op_options.Pos)
+ axis = gather_options.Axis()
+
+ # Check the indices are oob, tflite is unpredictable in case of oob.
Review comment:
Maybe improve comment to :
Check that the indices are within bounds ?
Is the tflite specification clear that out of bounds indices results in
unpredictable behaviour ?
----------------------------------------------------------------
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