简体   繁体   English

如何在tensorflow中按名称重置图形?

[英]How to reset a graph by name in tensorflow?

My understanding about working with multiple tensorflow graphs is that if i am creating a graph with tf.Graph() then there are two graphs that tensorflow has created for me. 我对使用多个张量流图的理解是,如果我使用tf.Graph()创建一个图,那么张量流为我创建了两个图。 One is the graph that tensorflow sets as default when i am within no context and one that i created using tf.Graph() that will be default when i am within tf.Graph().as_default(): context. 一个是在我没有上下文时将tensorflow设置为默认的图,另一个是我使用tf.Graph()创建的图,当我在tf.Graph().as_default():上下文中时将默认设置。 Now, How do i go about resetting the graph i created with tf.Graph() since tf.reset_default_graph() cannot be used inside a tf.Graph().as_default(): context 现在,由于tf.reset_default_graph() 不能tf.Graph().as_default(): 使用 ,我该如何重置用tf.Graph()创建的图形tf.Graph().as_default():

You can create a new tf.Graph() and replace the previous one. 您可以创建一个新的tf.Graph()并替换上一个。 As long as you remember to replace all of the references, the old graph will be garbage collected, so this solution is equivalent to resetting your existing graph. 只要您记得替换所有引用,就会对旧图进行垃圾回收,因此此解决方案等效于重置现有图。

Just remember about all of the references! 只要记住所有参考资料即可! You would likely need to recreate the session that used the previous graph, as I don't think that there is a way to just replace the graph reference. 您可能需要重新创建使用前一个图形的会话,因为我认为没有一种方法可以替换图形引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM