1

I have a complex net for which I have created a very simple class for inferencing the model once it is serialised into a frozen graph file.

The thing is that in this file I need to load the variable with his namespace which may end up depending on how I have structured the model. In my case ends up like this:

# Load the input and output node with a singular namespace depending on the model
self.input_node = self.sess.graph.get_tensor_by_name("create_model/mymodelname/input_node:0")
self.output_node = self.sess.graph.get_tensor_by_name("create_model/mymodelname/out/output_node:0")

I would like to give these two nodes an alias before storing it into the model such as they would end up having a common name and then my Class for inferencing could be used as a general purpose Class for fetching the model. In this case I would end up doing something like this:

# Load the input and output node with a general node namespace
self.input_node = self.sess.graph.get_tensor_by_name("input_node:0")
self.output_node = self.sess.graph.get_tensor_by_name("output_node:0")

So is there any option for giving them an alias? I didn't really find anything.

Thank you very much!

adam13
  • 91
  • 4

1 Answers1

3

You can use tf.identity for the output.

output_node = sess.graph.get_tensor_by_name("create_model/mymodelname/output_node:0")
tf.identity(output_node, name="output_node")

will create a new passthrough op that has the name "output_node" and will get its value from the node you specify.

Input is a bit trickier, you'd need to change how you build the model - for example have it take its input from the outside, and then create an input placeholder with a fixed name that you then pass in to the function that builds the model.

etarion
  • 16,935
  • 4
  • 43
  • 66
  • `tf.identify`: "Return a tensor with the same shape and contents as the input tensor or value." Maybe I am lacking deeper knowledge in Tensorflow, but isn't it that it is not connected to the graph at all? Anyway if it is a new vector even though it has the value of the tensor it won't interact the same way as the original node, thus it won`t work when calling a sess.run and feeding that new input node right? – adam13 Mar 15 '17 at 11:55