今天小编就为大家分享一篇tensorflow 重置/清除计算图的实现,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
调用tf.reset_default_graph()重置计算图
当在搭建网络查看计算图时,如果重复运行程序会导致重定义报错。为了可以在同一个线程或者交互式环境中(ipython/jupyter)重复调试计算图,就需要使用这个函数来重置计算图,随后修改计算图再次运行。
#重置计算图,清理当前定义节点 import tensorflow as tf tf.reset_default_graph() #Your model defined below #
需要注意的是,下面三种情况使用这个函数会报错:
#1 with graph.as_default(): #不能用 #2 with t<strong style="color:transparent">来源gaodai#ma#com搞@代~码网</strong>f.Session(): block. #不能用 #3 tf.InteractiveSession() #Your regions #不能用 sess.close().
也就是说这个函数需要在with tf.session()外部调用。
以上就是tensorflow 重置/清除计算图的实现的详细内容,更多请关注gaodaima搞代码网其它相关文章!