从图中删除节点或重置整个默认graphics
使用默认全局图时,是否可以在添加节点后删除节点,或者将默认图重置为空? 当在IPython中以交互方式使用TF时,我发现自己不得不重新启动内核。 如果可能,我希望能够更容易地尝试图表。
更新11/2/2016
tf.reset_default_graph() 
老东西
 有reset_default_graph ,但不是公共API的一部分(我认为应该是,有人想在GitHub上提出问题 ?) 
我的工作重置是这样的:
 from tensorflow.python.framework import ops ops.reset_default_graph() sess = tf.InteractiveSession() 
默认情况下,会话是围绕默认图构build的。 为了避免在会话中留下死亡的节点,您需要控制默认graphics或使用明确的graphics。
- 
要清除默认graphics,可以使用tf.reset_default_graph函数。
tf.reset_default_graph() sess = tf.InteractiveSession() - 
您也可以显式构build一个graphics,并避免使用默认的graphics。 如果您使用普通
Session,则需要在构build会话之前完全创buildgraphics。 对于InteractiveSession,您可以声明graphics并将其用作上下文来声明进一步的更改: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], ...) 
 编辑:对于张量tensorflow (1.0+)的最新版本,正确的function是g.as_default 。 
IPython / Jupyter笔记本电脑保持单元运行之间的状态。
创build一个自定义graphics:
 def main(): # Define your model data = tf.placeholder(...) model = ... with tf.Graph().as_default(): main() 
一旦运行,graphics被清理。