简体   繁体   English

拥有多个tf.Graph有什么意义?

[英]What's the point of having more than one tf.Graph?

What's the point of having more than one tf.Graph ? 拥有多个tf.Graph什么tf.Graph

I'm thinking specifically about hyperparameter tuning of machine learning models, where a model is either a graph on its own, or several models are defined as disconnected components within the same graph. 我正在专门考虑机器学习模型的超参数调整,其中一个模型要么是一个单独的图,要么几个模型被定义为同一图中的断开连接的组件。

I understand that having more than one tf.Session is bad because task scheduling cannot be done right, so I assume it's possible to have multiple tf.Graph objects in one session (though tf.Session(graph=...) begs to differ) but what would be the point of doing that instead of having several components with something like tf.variable_scope instead? 我知道拥有多个tf.Session是不好的,因为无法正确地进行任务调度,因此我假设一个会话中可能有多个tf.Graph对象(尽管tf.Session(graph=...)可能会有所不同),而不是像tf.variable_scope那样具有多个组件,这样做的目的是什么呢? Is it mostly a matter of what gets saved with tf.train.Saver , visualized in TensorBoard, and so on? 这主要与使用tf.train.Saver保存,在TensorBoard中可视化等等保存什么有关吗? Which method is preferable? 哪种方法更好? Should models share a graph or each have their own for hyperparameter tuning? 模型应该共享一个图形还是每个模型都有自己的超参数调整?

It seems simpler to just use tf.reset_default_graph(); sess = tf.InteractiveSession() 使用tf.reset_default_graph(); sess = tf.InteractiveSession()似乎更简单tf.reset_default_graph(); sess = tf.InteractiveSession() tf.reset_default_graph(); sess = tf.InteractiveSession() and to forget about both tf.Graph and tf.Session throughout the rest of the code base. tf.reset_default_graph(); sess = tf.InteractiveSession() ,并在整个代码库的其余部分都忘记了tf.Graphtf.Session What am I missing? 我想念什么?

If you have a single session, then there's no point in having multiple graphs. 如果您只有一个会话,那么拥有多个图表毫无意义。 Session is linked to a graph, so if you try to run an element from another graph, you'll get xyz is not an element of this graph error. 会话链接到一个图,因此,如果您尝试从另一个图运行一个元素,则会得到xyz is not an element of this graph错误xyz is not an element of this graph

It makes sense to have multiple graphs when you have multiple sessions. 当您有多个会话时,具有多个图形是有意义的。 For instance, suppose you are using distributed TensorFlow, but also want to do some computations locally. 例如,假设您正在使用分布式TensorFlow,但还想在本地进行一些计算。 You could do something like this 你可以做这样的事情

local_session = tf.Session("", graph=local_graph)
remote_session = tf.Session("grpc://...", graph=remote_graph)

You could potentially use two sessions with the same tf.Graph object however, however any additions to this object will result in a TF_ExtendGraph call on the next session.run even if it's not necessary for that session. 您可能会在同一个tf.Graph对象上使用两个会话,但是,对该对象的任何添加都会导致在下一个session.run上调用TF_ExtendGraph ,即使该会话不是必需的。 In other words, sharing the graph means sending <=2GB graph description to all sessions when the graph is modified. 换句话说,共享图意味着在修改图时向所有会话发送<= 2GB的图描述。

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

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