Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between ClientSession and Session in TensorFlow C++ API

Tags:

c++

tensorflow

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?

like image 933
Tomi Avatar asked Mar 05 '17 02:03

Tomi


People also ask

What is a session in TensorFlow?

A session allows to execute graphs or part of graphs. It allocates resources (on one or more machines) for that and holds the actual values of intermediate results and variables.

Does TensorFlow have a C++ API?

Tensorflow is built using C++ and it offers an API to make it relatively easier to deploy models (and even train models if you wish to) in C++.

Is TensorFlow faster C++?

If you write a C++ program utilizing TensorFlow, it Will (providing you know how to program) be magnitudes faster than a Python equivalent.


1 Answers

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.

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.

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.

like image 174
mrry Avatar answered Nov 06 '22 02:11

mrry