网络编程
位置:首页>> 网络编程>> 网络编程>> tensorflow 重置/清除计算图的实现

tensorflow 重置/清除计算图的实现

作者:hitrjj  发布时间:2023-07-23 00:41:58 

标签: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 tf.Session(): block.
#不能用
#3
tf.InteractiveSession()
#Your regions
#不能用
sess.close().

也就是说这个函数需要在with tf.session()外部调用。

来源:https://blog.csdn.net/u014636245/article/details/84073239

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com