inadob commented on a change in pull request #4502: [Relay][Frontend][TFlite]
Add parses support for SLICE
URL: https://github.com/apache/incubator-tvm/pull/4502#discussion_r358786969
##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -1033,6 +1034,35 @@ def convert_split(self, op):
return out
+ def convert_slice(self, op):
+ """Convert TFLite SLICE"""
+ try:
+ from tflite.Operator import Operator
+ 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) == 3, "input tensors length should be == 3"
+ input_tensor = input_tensors[0]
+ in_expr = self.get_expr(input_tensor.tensor_idx)
+
+ begin = list(self.get_tensor_value(input_tensors[1]))
+ size = list(self.get_tensor_value(input_tensors[2]))
+ # strided_slice(Relay) needs the slice's end indices, not the size
+ end = size
+ input_tensor_shape = input_tensor.tensor.ShapeAsNumpy()
+ input_tensor_rank = len(input_tensor_shape)
+ for i in range(input_tensor_rank):
+ if size[i] == -1:
+ end[i] = input_tensor_shape[i] - begin[i] + 1
Review comment:
@kevinthesun I see what you mean, but **end[i] is zero-based** while
**data_shape is one-based** so following your logic, end[i] = data_shape[i] **-
1**
----------------------------------------------------------------
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