TensorFlow C++ API 中 ClientSession 和 Session 的区别 [英] Difference between ClientSession and Session in TensorFlow C++ API
问题描述
TensorFlow r1.0 C++ API 带有 Session
和 ClientSession
类.TensorFlow 附带的一些示例使用 ClientSession
,其他示例使用 Session
.这两种不同类型的会话是否在幕后使用相同的底层机制,还是其中一种优于另一种?使用它们的语法有点不同,但除此之外在行为上还有什么不同吗?
TensorFlow r1.0 C++ API comes with Session
and ClientSession
classes. Some of the examples shipping with TensorFlow use ClientSession
and others use Session
. Do these two different types of session use the same underlying mechanism under the hood or is one of the preferred over another? The syntax for using them is a bit different but other than that are there any differences in behavior?
推荐答案
在 TensorFlow 的 C++ API 中,tensorflow::Session
API 是一个低级接口,用于处理序列化的 GraphDef
协议缓冲区,并为运行子图.
In TensorFlow's C++ API, the tensorflow::Session
API is a low-level interface that deals with serialized GraphDef
protocol buffers and provides a string-based interface for running subgraphs.
相比之下,tensorflow::ClientSession
API 更高级别,并与用于构建 TensorFlow 图的新 C++ API 集成 - 与 Python tf.Graph
和 tf.Session
类可以.
By contrast, the tensorflow::ClientSession
API is higher level, and integrates with the new C++ API for building TensorFlow graphs—much in the same way as the Python tf.Graph
and tf.Session
classes do.
因此,如果您使用 C++ API 构建图形,您可能希望使用 tensorflow::ClientSession
,但 tensorflow::Session
接口更容易如果您已经有一个序列化的 GraphDef
(代表例如一个预训练的模型)并且只想在该模型上运行推理,请使用.
Therefore, you will probably want to use a tensorflow::ClientSession
if you are building the graph with the C++ API, but the tensorflow::Session
interface is easier to use if you already have a serialized GraphDef
(representing e.g. a pre-trained model) and just want to run inference on that model.
这篇关于TensorFlow C++ API 中 ClientSession 和 Session 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!