In Tensorflow, how can I rename a specific operation name?

I think this question may seem strange. Let, say, there exists a tensor a .

 x = tf.placeholder(tf.float32, [None, 2400], name="x") y = tf.placeholder(tf.float32, [None, 2400], name="y") a = tf.add(x, y, name="a") 

Is there an efficient way to refer to a with a different name, like out ? I think a dummy operation is kind of

 b = tf.add(a, 0, name="out") 

I ask about this because I am trying to use different network architectures, and regardless of architecture, I would like to access the output tensor with a consistent name like

 tf.get_default_graph().get_tensor_by_name("out:0")` 

Currently, output tensors depend on architectures such as fc1/fc1wb:0 or fc2/fc2wb:0 . How can I wrap a final op with a specific name?

+7
python tensorflow
source share
1 answer

This answer assumes that tf.Graph added only, you cannot change it.

As said, a slightly better way to rename the tensor is to use tf.identity as follows:

 tf.identity(a, name="out") 

EDIT: after figuring out the answer to one of my own questions, I see a slightly better way to do this:

 graph_def.node[<index of the op you want to change>].name = "out" 

index usually -1 because the final output tensors are at the end of graph_def

+8
source share

All Articles