tensorflow: tf.Graph.get_tensor_by_name does not work as expected in TF2
System information
- Have I written custom code: yes
- OS Platform and Distribution: Max OSX 10.15.3 (Catalina)
- Mobile device: N/A
- TensorFlow installed from (source or binary): source
- TensorFlow version: v2.1.0-rc2-17-ge5bf8de410 2.1.0
- Python version: 3.7.6
- Bazel version (if compiling from source): N/A
- GCC/Compiler version (if compiling from source): N/A
- CUDA/cuDNN version: - GPU model and memory: N/A
Describe the current behavior
tf.Graph.get_tensor_by_name
returns ‘resource’ dtype tensors, which do not evaluate as expected in a session. For example, the code below will return something like:
array([( 10,), ( 44,), ( 47,), (106,), (111,), ( 98,), ( 58,), (108,),
(111,), ( 99,), ( 97,), (108,), (104,), (111,), (115,), (116,),
( 47,), (114,), (101,), (112,), (108,), (105,), ( 99,), ( 97,),
( 58,), ( 48,), ( 47,), (116,), ( 97,), (115,), (107,), ( 58,),
( 48,), ( 47,), (100,), (101,), (118,), (105,), ( 99,), (101,),
( 58,), ( 67,), ( 80,), ( 85,), ( 58,), ( 48,), ( 18,), ( 9,),
(108,), (111,), ( 99,), ( 97,), (108,), (104,), (111,), (115,),
(116,), ( 26,), ( 1,), (120,), ( 32,), (224,), (167,), (192,),
(135,), ( 18,), ( 42,), ( 18,), ( 78,), ( 49,), ( 48,), (116,),
(101,), (110,), (115,), (111,), (114,), (102,), (108,), (111,),
(119,), ( 51,), ( 86,), ( 97,), (114,), ( 69,), ( 50,), ( 4,),
( 8,), ( 3,), ( 18,), ( 0,)], dtype=[('resource', 'u1')])
Describe the expected behavior
Expect v1 compatible code to work as it does in TF1.X. In particular, the code below should return 3
.
Standalone code to reproduce the issue
import tensorflow.compat.v1 as tf
tf.disable_eager_execution()
x = tf.Variable(3, name='x')
y = tf.get_default_graph().get_tensor_by_name('x:0')
with tf.Session() as sess:
sess.run(y)
Other info / logs
- When instantiating a
tf.Variable
:
WARNING:tensorflow:From /Users/shermes/Projects/tensorflow/venv2/lib/python3.7/site-packages/tensorflow_core/python/ops/resource_variable_ops.py:1635: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
- From
sess.run
block:
/Users/shermes/Projects/tensorflow/venv2/lib/python3.7/site-packages/tensorflow_core/python/client/session.py:1445: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
(This error shows up when using numpy 1.16 as well as 1.17 and 1.18.)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 21 (8 by maintainers)
Try