Remove nodes from the graph or reset the entire graph to default

When working with the global graph by default, can you delete nodes after adding them, or, alternatively, reset to default for an empty column? When interacting with TF in IPython, I have to restart the kernel again. I would like to experiment with charts if possible.

+60
python tensorflow
Nov 17 '15 at 19:24
source share
4 answers

Update 11/2/2016

tf.reset_default_graph()

Old stuff

There reset_default_graph , but it is not part of the public API (I think it should be, someone wants to write the question on GitHub?)

My work around reset is this:

 from tensorflow.python.framework import ops ops.reset_default_graph() sess = tf.InteractiveSession() 
+93
Nov 17 '15 at
source share
— -

By default, a session is created around the default schedule. To avoid leaving dead nodes in the session, you need to either control the default schedule or use an explicit schedule.

  • To clear the default chart, you can use the tf.reset_default_graph function.

     tf.reset_default_graph() sess = tf.InteractiveSession() 
  • You can also explicitly plot the chart and not use the standard one. If you use a regular Session , you will need to completely create a graph before constructing the session. For InteractiveSession you can simply declare a graph and use it as a context to announce further changes:

     g = tf.Graph() sess = tf.InteractiveSession(graph=g) with g.asdefault(): # Put variable declaration and other tf operation # in the graph context .... b = tf.matmul(A, x) .... sess.run([b], ...) 

EDIT: For the latest tensorflow (1.0+) versions, the correct g.as_default function g.as_default .

+34
Mar 10 '16 at 1:27
source share

IPython / Jupyter laptop cells maintain state between cell runs.

Create your own schedule:

 def main(): # Define your model data = tf.placeholder(...) model = ... with tf.Graph().as_default(): main() 

After starting the graph is cleared.

+4
Oct. 19 '17 at 5:17
source share

Not sure if I encountered the same problem, but

 tf.keras.backend.clear_session() 

at the beginning of the cell in which the model was built and trained (in my case, Keras), it helped “reduce clutter”, so that only the current graph remains in the TensorBoard visualization after repeated runs of the same cell.

Environment: TensorFlow 2.0 ( tensorflow-gpu==2.0.0b1 ) in Colab with built-in TensorBoard (using %load_ext tensorboard ).

0
Jul 24 '19 at 7:41
source share



All Articles