How to "add" Op at the beginning of the TensorFlow chart?

I have a prototype of GraphDef that I am importing with tf.import_graph_def . Ops can be added at the end of the chart as follows:

 final_tensor = tf.import_graph_def(graph_def, name='', return_elements=['final_tensor']) new_tensor = some_op(final_tensor) 

But I want to add Ops at the beginning of the graph, so essentially the first Op in graph_def should take the output of my Op as input, how to do it?

+5
source share
1 answer

Finally found a way to do this. I am sure that the Yarolsav function mentioned in the comments does something similar inside.

 new_input = graph_def.node.add() new_input.op = 'new_op_name' # eg: 'Const', 'Placeholder', 'Add' etc new_input.name = 'some_new_name' # set any attributes you want for new_input here old_input.input[0] = 'some_new_name' # must match with the name above 

For more information on how to set attributes, see this file .

+3
source

Source: https://habr.com/ru/post/1263494/


All Articles