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:Yong Tang <yong.tang.github@outlook.com> * Add test cases for partial shape inference for `tf.slice` Signed-off-by:
Yong Tang <yong.tang.github@outlook.com> * Address review feedback Signed-off-by:
Yong Tang <yong.tang.github@outlook.com> * Inline `SliceHelper` for simplication Signed-off-by:
Yong Tang <yong.tang.github@outlook.com>
Loading
Please sign in to comment