-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Relay][Frontend][TF] Fix slice when begin or size is not Const #4372
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -626,8 +626,14 @@ def _impl(inputs, attr, params): | |
|
||
def _slice(): | ||
def _impl(inputs, attr, params): | ||
begin = _get_list_param(params, inputs[1]) | ||
size = _get_list_param(params, inputs[2]) | ||
try: | ||
begin = _get_list_param(params, inputs[1]) | ||
except: | ||
begin = _infer_value_simulated(inputs[1], params).asnumpy()[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yongwww There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
try: | ||
size = _get_list_param(params, inputs[2]) | ||
except: | ||
size = _infer_value_simulated(inputs[2], params).asnumpy()[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same as begin |
||
data_shape = attr['_input_shapes'][inputs[0]] | ||
data_dim = len(data_shape) | ||
end = size | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2188,6 +2188,20 @@ def test_forward_transpose(): | |
_test_forward_tranapose_axes_input((2, 3, 4, 5), (3, 0, 1, 2)) | ||
|
||
|
||
def _test_forward_slice_operation_input(input_value, begin_value, size_value): | ||
input_data = np.array(input_value, dtype=np.float32) | ||
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') | ||
compare_tf_with_tvm([input_data], ['input:0'], 'slice_output:0') | ||
|
||
|
||
def test_forward_slice(): | ||
_test_forward_slice_operation_input([1, 1], 0, 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add test cases to cover begin & size as tensor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yongwww begin and size as tensor are already covered. In the
|
||
|
||
def test_forward_ceil(): | ||
ishape = (1, 3, 10, 10) | ||
inp_array = np.random.uniform(size=ishape).astype(np.float32) | ||
|
@@ -2762,6 +2776,7 @@ def test_forward_add_n(): | |
if __name__ == '__main__': | ||
|
||
# Transforms | ||
test_forward_slice() | ||
test_forward_transpose() | ||
test_forward_reshape() | ||
test_forward_depthtospace() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably only catch the exceptions we expect to see here (like
IndexError
orAttributeError
), and let the others go through.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it