Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix][Frontend][TF] Fix incorrect calculations in tf SLICE #4518

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/tvm/relay/frontend/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def _impl(inputs, attr, params):
end = size
for i in range(data_dim):
if size[i] == -1:
end[i] = data_shape[i] - begin[i]
end[i] = data_shape[i]
else:
end[i] += begin[i]
return _op.strided_slice(inputs[0], begin=begin, end=end)
Expand Down
9 changes: 5 additions & 4 deletions tests/python/frontend/tensorflow/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -2209,14 +2209,15 @@ def _test_forward_slice_operation_input(input_value, begin_value, size_value):
with tf.Graph().as_default():
input_tensor = tf.placeholder(
shape=input_data.shape, dtype=input_data.dtype, name="input")
begin_tensor = tf.expand_dims(begin_value, axis=0)
size_tensor = tf.expand_dims(size_value, axis=0)
slice_tensor = tf.slice(input_tensor, begin_tensor, size_tensor, name='slice_output')
tf.slice(input_tensor, begin_value, size_value, name='slice_output')
compare_tf_with_tvm([input_data], ['input:0'], 'slice_output:0')


def test_forward_slice():
_test_forward_slice_operation_input([1, 1], 0, 2)
_test_forward_slice_operation_input([1, 1], [0], [2])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to add below lines inside _test_forward_slice_operation_input to also accept begin_value, size_value input as a single int?

    begin_value = [begin_value] if isinstance(begin_value, int) else begin_value
    size_value = [size_value] if isinstance(size_value, int) else size_value

Copy link
Contributor Author

@inadob inadob Dec 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, in the TF documentation is said that tf.slice() arguments begin & size both should be tensors. I am aware that the scalars are 0D tensors but if the TF function, in general, doesn't accept scalars, then from my point of view, it doesn't make sense to test something that is not supposed to work like this.

_test_forward_slice_operation_input([0, 1, 2, 3], [3], [-1])
_test_forward_slice_operation_input([[0, 1, 2, 3], [4, 5, 6, 7]],
begin_value=[0, 1], size_value=[-1, -1])

def test_forward_ceil():
ishape = (1, 3, 10, 10)
Expand Down