# tensorflow::ClientSession

`#include <client_session.h>`

A `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session` object lets the caller drive the evaluation of the TensorFlow graph constructed with the C++ API.

## Summary

Example:

```
Scope root = Scope::NewRootScope();
auto a = Placeholder(root, DT_INT32);
auto c = Add(root, a, {41});

ClientSession session(root);
std::vector outputs;

Status s = session.Run({ {a, {1}} }, {c}, &outputs);
if (!s.ok()) { ... }  
```

<br />

| ### Constructors and Destructors ||
|---|---|
| `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1ac52798100986741ff24aba4a758d8e4d(const https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, const string & target)` Create a new session to evaluate the graph contained in `scope` by connecting to the TensorFlow runtime specified by `target`. ||
| `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a791dce94ca627aec0c4318b125f60b6f(const https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope)` Same as above, but use the empty string ("") as the target specification. ||
| `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a997f25e1940f59e004d99be1ce8b1d6a(const https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, const SessionOptions & session_options)` Create a new session, configuring it with `session_options`. ||
| `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a9372a82c049463a1197b002f8d08808d()` ||

| ### Public types ||
|---|---|
| `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a5a406e8a9e34fab90abedb64eaff9b64` | typedef `int64` A handle to a subgraph, created with `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a1173b3254b1940937a59c5adfb196316`. |
| `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1acc9df9cd0b78bc70aa100c122e1d0b79` | typedef `std::unordered_map< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output, https://www.tensorflow.org/versions/r2.0/api_docs/cc/struct/tensorflow/input/initializer#structtensorflow_1_1_input_1_1_initializer, https://www.tensorflow.org/versions/r2.0/api_docs/cc/struct/tensorflow/output-hash#structtensorflow_1_1_output_hash >` A data type to represent feeds to a Run call. |

| ### Public functions ||
|---|---|
| `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a1173b3254b1940937a59c5adfb196316(const CallableOptions & callable_options, https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a5a406e8a9e34fab90abedb64eaff9b64 *out_handle)` | `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/status#classtensorflow_1_1_status` Creates a `handle` for invoking the subgraph defined by `callable_options`. |
| `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a7f028aa32b4b924e1be040c49c44221a(https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a5a406e8a9e34fab90abedb64eaff9b64 handle)` | `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/status#classtensorflow_1_1_status` Releases resources associated with the given `handle` in this session. |
| `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1abba158c5343b74800d2d00b6ce75cf79(const std::vector< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output > & fetch_outputs, std::vector< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor > *outputs) const ` | `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/status#classtensorflow_1_1_status` Evaluate the tensors in `fetch_outputs`. |
| `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a69299ff76cb16b83467e93569870250a(const https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1acc9df9cd0b78bc70aa100c122e1d0b79 & inputs, const std::vector< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output > & fetch_outputs, std::vector< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor > *outputs) const ` | `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/status#classtensorflow_1_1_status` Same as above, but use the mapping in `inputs` as feeds. |
| `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a706a9b3dfde4aa64c7ca9e85ac666b1d(const https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1acc9df9cd0b78bc70aa100c122e1d0b79 & inputs, const std::vector< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output > & fetch_outputs, const std::vector< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation > & run_outputs, std::vector< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor > *outputs) const ` | `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/status#classtensorflow_1_1_status` Same as above. Additionally runs the operations ins `run_outputs`. |
| `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a46e06a478a61001923a545e0922038e2(const RunOptions & run_options, const https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1acc9df9cd0b78bc70aa100c122e1d0b79 & inputs, const std::vector< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output > & fetch_outputs, const std::vector< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation > & run_outputs, std::vector< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor > *outputs, RunMetadata *run_metadata) const ` | `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/status#classtensorflow_1_1_status` Use `run_options` to turn on performance profiling. |
| `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1ad5ba274d6e978e36be7aa8e53207faa2(https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a5a406e8a9e34fab90abedb64eaff9b64 handle, const std::vector< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor > & feed_tensors, std::vector< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor > *fetch_tensors, RunMetadata *run_metadata)` | `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/status#classtensorflow_1_1_status` Invokes the subgraph named by `handle` with the given options and input tensors. |
| `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1aa27cbcc70e682e0e5290821376722c2d(https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a5a406e8a9e34fab90abedb64eaff9b64 handle, const std::vector< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor > & feed_tensors, std::vector< https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor > *fetch_tensors, RunMetadata *run_metadata, const thread::ThreadPoolOptions & options)` | `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/status#classtensorflow_1_1_status` Invokes the subgraph named by `handle` with the given options and input tensors. |

## Public types

### CallableHandle

```
int64 CallableHandle
```
A handle to a subgraph, created with `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/client-session#classtensorflow_1_1_client_session_1a1173b3254b1940937a59c5adfb196316`.

### FeedType

```
std::unordered_map< Output, Input::Initializer, OutputHash > FeedType
```
A data type to represent feeds to a Run call.

This is a map of `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output` objects returned by op-constructors to the value to feed them with. See `https://www.tensorflow.org/versions/r2.0/api_docs/cc/struct/tensorflow/input/initializer#structtensorflow_1_1_input_1_1_initializer` for details on what can be used as feed values.

## Public functions

### ClientSession

```
 ClientSession(
  const Scope & scope,
  const string & target
)
```
Create a new session to evaluate the graph contained in `scope` by connecting to the TensorFlow runtime specified by `target`.

### ClientSession

```
 ClientSession(
  const Scope & scope
)
```
Same as above, but use the empty string ("") as the target specification.

### ClientSession

```
 ClientSession(
  const Scope & scope,
  const SessionOptions & session_options
)
```
Create a new session, configuring it with `session_options`.

### MakeCallable

```
Status MakeCallable(
  const CallableOptions & callable_options,
  CallableHandle *out_handle
)
```
Creates a `handle` for invoking the subgraph defined by `callable_options`.

NOTE: This API is still experimental and may change.

### ReleaseCallable

```
Status ReleaseCallable(
  CallableHandle handle
)
```
Releases resources associated with the given `handle` in this session.

NOTE: This API is still experimental and may change.

### Run

```
Status Run(
  const std::vector< Output > & fetch_outputs,
  std::vector< Tensor > *outputs
) const 
```
Evaluate the tensors in `fetch_outputs`.

The values are returned as `https://www.tensorflow.org/versions/r2.0/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor` objects in `outputs`. The number and order of `outputs` will match `fetch_outputs`.

### Run

```
Status Run(
  const FeedType & inputs,
  const std::vector< Output > & fetch_outputs,
  std::vector< Tensor > *outputs
) const 
```
Same as above, but use the mapping in `inputs` as feeds.

### Run

```
Status Run(
  const FeedType & inputs,
  const std::vector< Output > & fetch_outputs,
  const std::vector< Operation > & run_outputs,
  std::vector< Tensor > *outputs
) const 
```
Same as above. Additionally runs the operations ins `run_outputs`.

### Run

```
Status Run(
  const RunOptions & run_options,
  const FeedType & inputs,
  const std::vector< Output > & fetch_outputs,
  const std::vector< Operation > & run_outputs,
  std::vector< Tensor > *outputs,
  RunMetadata *run_metadata
) const 
```
Use `run_options` to turn on performance profiling.

`run_metadata`, if not null, is filled in with the profiling results.

### RunCallable

```
Status RunCallable(
  CallableHandle handle,
  const std::vector< Tensor > & feed_tensors,
  std::vector< Tensor > *fetch_tensors,
  RunMetadata *run_metadata
)
```
Invokes the subgraph named by `handle` with the given options and input tensors.

The order of tensors in `feed_tensors` must match the order of names in `CallableOptions::feed()` and the order of tensors in `fetch_tensors` will match the order of names in `CallableOptions::fetch()` when this subgraph was created. NOTE: This API is still experimental and may change.

### RunCallable

```
Status RunCallable(
  CallableHandle handle,
  const std::vector< Tensor > & feed_tensors,
  std::vector< Tensor > *fetch_tensors,
  RunMetadata *run_metadata,
  const thread::ThreadPoolOptions & options
)
```
Invokes the subgraph named by `handle` with the given options and input tensors.

The order of tensors in `feed_tensors` must match the order of names in `CallableOptions::feed()` and the order of tensors in `fetch_tensors` will match the order of names in `CallableOptions::fetch()` when this subgraph was created. NOTE: This API is still experimental and may change.

### \~ClientSession

```
 ~ClientSession()
```