Commit 6025f064 authored by Yong Tang's avatar Yong Tang Committed by Shanqing Cai
Browse files

Improve shape inference for `tf.slice` (#13561)



* Improve shape inference for `tf.slice`

This fix is an effort to address the issue raised by 4590 where
improvement of shape inference for `tf.slice` is needed.

When one of the size element is unknwon, the output shape is completely
unknwon (with right rank):
```
>>> z = tf.zeros((1, 2, 3))
>>> z.get_shape().as_list()
[1, 2, 3]
>>> m = tf.slice(z, [0, 0, 0], [tf.constant(1) + 0, 2, -1])
>>> m.get_shape().as_list()
[None, None, None]
```

This fix improves the shape inference so that:
```python
>>> import tensorflow as tf
>>> z = tf.zeros((1, 2, 3))
>>> m = tf.slice(z, [0, 0, 0], [tf.constant(1) + 0, 2, -1])
>>> m.get_shape().as_list()
[None, 2, None]
```

Note: this fix does not handle the case where one of the size element is
`-1` and one of the size element is unknown. However, it is an improvement
nevertheless.

Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>

* Add test cases for partial shape inference for `tf.slice`

Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>

* Address review feedback

Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>

* Inline `SliceHelper` for simplication

Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>
parent 23cce3c4
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment