As mentioned in this question, in Tensorflow v1 you could retrieve a tensor or operation output via its Graph within a session:
with tf.Session() as sess:
# ...
tf.get_default_graph().get_tensor_by_name("example:0")
In Tensorflow 2 direct use of the graph is deprecated, and thus not the preferred approach.
The get_tensor_by_name
method still exists, but to get the implicit graph you would have to call something like tf.compat.v1.get_default_graph()
, which essentially is a way of making TF1 code work in TF2.
Is there some canonical way in Tensorflow 2 of retrieving a tensor which exists in the implicit computation graph, but which you do not have any reference to except for by name?