The tf.graph data structure is intended as an add-only data structure. Therefore, it is not possible to delete or modify existing nodes. This is usually not a problem, since only the necessary subgraph is processed during the session.
What you can try is to copy the Variabels of your chart into a new graph and delete the old one. For archiving, it is easy to run:
old_graph = tf.get_default_graph()
If you want to iterate over all the nodes of the old graph, use:
for node in old_graph.get_operations(): if node.type == 'Variable':
Alternatively you can use:
for node in old_graph.get_collection('trainable_variables'):
See also python/framework/ops.py : 1759 for more ways to manage nodes in a graph.
However, before you start talking to tf.Graph , I highly recommend considering whether this is really required. You can usually try to generalize the calculations and use common variables by plotting, so each instance that you want to process is a subgraph of that plot.
source share