在Tensorflow中更改tf.placeholder对象的当前图:可能吗? [英] Changing the current graph of tf.placeholder objects in Tensorflow: Is it possible?

查看:159
本文介绍了在Tensorflow中更改tf.placeholder对象的当前图:可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,由于某种原因,我正在更改当前的默认图形,并从头开始重建所有计算逻辑。这自然会导致一些错误,因为我的 tf.placeholder 项目保留在旧图中。我可以自然地再次声明它们,但是为了做到这一点,我必须编写很多胶水代码,使所有内容复杂化。我需要的是在当前图形中获取所有 tf.placeholder 对象,然后将其转移到要创建的新图形中。有什么办法吗?我的初步研究没有给出任何有意义的结果,但是我非常肯定Tensorflow中应该有一种方法。

In my code, I am changing my current default graph for some reason and rebuild all the computation logic from scratch. This naturally leads to some errors, since my tf.placeholder items stay in the old graph. I can naturally declare these again, but in order to do that, I have to write a lot of glue-junk code which will needlesly complicate everything. What I need is to get all tf.placeholder objects in my current graph and then transfer to them into the new graph I am going to create. Is there any way to do that? My preliminary research did not give any meaningful results but I am highly positive there should be a way to do this in Tensorflow.

推荐答案

如果您有2个图,则可以使用 tf.contrib.copy_graph 模块。

If you have 2 graphs, you can copy operations and variables from a graph to the other using the tf.contrib.copy_graph module.

特别是,您可以使用 copy_op_to_graph 将占位符 pl 从图 g1 复制到图 g2

In particular, you can use the copy_op_to_graph to copy the placeholder pl from graph g1 to graph g2:

tf.contrib.copy_graph.copy_op_to_graph(
    pl,
    g2,
    [],
    scope=''
)

这篇关于在Tensorflow中更改tf.placeholder对象的当前图:可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆