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_r357221039
##########
File path: tests/python/frontend/tflite/test_forward.py
##########
@@ -219,6 +219,26 @@ def test_forward_split():
_test_split((1, 3, 6, 5), -2, 3, 'float32')
_test_split((1, 3, 5, 6), -1, 3, 'float32')
+#######################################################################
+# slice
+# -----
+
+def _test_slice(data, begin, size):
+ """ One iteration of SLICE """
+ with tf.Graph().as_default():
+ in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)
+ out = array_ops.slice(in_data, begin, size)
+ compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out])
+
+def test_forward_slice():
+ """ SLICE """
+ _test_slice(np.arange(4, dtype=np.float32).reshape((4, )), begin=[0],
size=[2])
+ _test_slice(np.arange(18, dtype=np.int32).reshape((3, 2, 3)), begin=[1, 0,
0], size=[1, 1, 3])
+ # tflite 1.13 outputs nonsense values if size[i] == -1
+ if package_version.parse(tf.VERSION) >= package_version.parse('1.14.0'):
+ _test_slice(np.arange(8, dtype=np.int32).reshape((2, 4)), begin=[0,
1], size=[-1, -1])
Review comment:
I believe that adding **+1** to the formula is the correct way to calculate
end[i] since the indexing of elements in every dimension starts from 0 (**i.e 0
<= begin[i] <= len(dimension) - 1** ). However input_tensor_shape[i] is the
length of the i-th dimenson so **1 <=input_tensor_shape[i] <= len(dimension)**.
If we stick to the formula without **+1** we get an assertion error in the
last test case:
- **x - tflite output**
- **y - TVM output**
- input [[0, 1, 2, 3], [4, 5, 6, 7]]

Also, there is no test case added in the TF frontend that covers size[i] =
-1 so the calculations has not been checked in any way.
----------------------------------------------------------------
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