tensorflow: ```tf.stack``` returns different shapes when run in eager and graph mode
Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
- TensorFlow installed from (source or binary):binary
- TensorFlow version (use command below):2.3
- Python version:
- Bazel version (if compiling from source):
- GCC/Compiler version (if compiling from source):
- CUDA/cuDNN version:
- GPU model and memory:
You can collect some of this information using our environment capture script You can also obtain the TensorFlow version with:
- TF 1.0:
python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)" - TF 2.0:
python -c "import tensorflow as tf; print(tf.version.GIT_VERSION, tf.version.VERSION)"
Describe the current behavior
tf.stack(list(np.ones([2,0,3]))).shape
returns EagerTensor with shape [2,0]
Describe the expected behavior
tf.stack(list(np.ones([2,0,3]))).shape
returns EagerTensor with shape [2,0,3] which same as graph mode
Standalone code to reproduce the issue Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/Jupyter/any notebook. Eager mode:
import tensorflow as tf
print(tf.stack(list(np.ones([2,0,3]))).shape)
tf.compat.v1.disable_eager_execution()
print(tf.stack(list(np.ones([2,0,3]))).shape)
Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (11 by maintainers)
The issue is really due to
tf.convert_to_tensorwhich does not handling shape correctly:It looks like
tf.convert_to_tensor()in eager mode (or more specificallyInitEagerTensor), dropped the dimension of3.Hi @fsx950223 ! This issue is getting resolved with
tf.config.run_functions_eagerly(False)instead oftf.compat.v1.disable_eager_execution(). Attaching gist for reference. Thank you!