siju-samuel 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_r382052919
##########
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:
According to [tf latest
code](https://github.com/tensorflow/tensorflow/blob/e5bf8de410005de06a7ff5393fafdf832ef1d4ad/tensorflow/python/ops/array_ops.py#L4069),
if indices are not within bounds, they will return error for CPU and for GPU
they will return zero.
With Tensorflow, i was getting zero for GPU. For validation using _tflite_,
i was using tf 1.14 version and i was getting random numbers in places of oob
indices.
----------------------------------------------------------------
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