【发布时间】:2020-02-14 13:43:29
【问题描述】:
我创建一个张量流图并定义一些张量并运行一些东西。完成后,我想删除我制作的图表,并释放所有资源。我该怎么做?
temporary_graph = tf.Graph()
with temporary_graph.as_default(), tf.Session() as sess:
foo = tf.placeholder(tf.float32, (2,2))
bar = foo@foo
res = sess.run(bar, feed_dict={foo: np.ones((2,2))})
print(res)
delete_graph_and_free_up_resources(temporary_graph)
This answer 声称上下文管理器会清理图表,但事实并非如此,文档也没有声明这样的事情:
>>> temporary_graph.get_operations()
[<tf.Operation 'Placeholder' type=Placeholder>, <tf.Operation 'matmul' type=MatMul>]
处理图表的最佳方法是什么?
【问题讨论】:
-
您可以使用sess.close() 释放与会话相关的所有资源。
-
@Hamed,但这并没有清除图表。张量中的实际值随着会话而消失,但图表仍然存在。
标签: tensorflow