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_r374500086
##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -792,6 +794,147 @@ def convert_not_equal(self, op):
'TFlite quantized NOT_EQUAL operator is not supported yet.')
return self._convert_elemwise(_op.not_equal, 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)
+ 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()
+
+ out = _op.take(data, indices, axis=axis)
+ return out
+
Review comment:
A comment here explaining the lowering from the tflite operator to the relay
IR seems appropriate as the code is non-obvious especially as it appears
tflite.strided_slice is not identical to relay.op.strided_slice and a final
reshape is needed.
----------------------------------------------------------------
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