A `ClientSession` object lets the caller drive the evaluation of the TensorFlow graph constructed with the C++ API. 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()) { ... }
| 51 | /// Status s = session.Run({ {a, {1}} }, {c}, &outputs); |
| 52 | /// if (!s.ok()) { ... } |
| 53 | class ClientSession { |
| 54 | public: |
| 55 | /// A data type to represent feeds to a Run call. |
| 56 | /// |
| 57 | /// This is a map of `Output` objects returned by op-constructors to the value |
| 58 | /// to feed them with. See `Input::Initializer` for details on what can be |
| 59 | /// used as feed values. |
| 60 | typedef std::unordered_map<Output, Input::Initializer, OutputHash> FeedType; |
| 61 | |
| 62 | /// Create a new session to evaluate the graph contained in `scope` by |
| 63 | /// connecting to the TensorFlow runtime specified by `target`. |
| 64 | ClientSession(const Scope& scope, const string& target); |
| 65 | |
| 66 | /// Same as above, but use the empty string ("") as the target specification. |
| 67 | ClientSession(const Scope& scope); |
| 68 | |
| 69 | /// Create a new session, configuring it with `session_options`. |
| 70 | ClientSession(const Scope& scope, const SessionOptions& session_options); |
| 71 | |
| 72 | ~ClientSession(); |
| 73 | |
| 74 | /// Evaluate the tensors in `fetch_outputs`. The values are returned as |
| 75 | /// `Tensor` objects in `outputs`. The number and order of `outputs` will |
| 76 | /// match `fetch_outputs`. |
| 77 | Status Run(const std::vector<Output>& fetch_outputs, |
| 78 | std::vector<Tensor>* outputs) const; |
| 79 | |
| 80 | /// Same as above, but use the mapping in `inputs` as feeds. |
| 81 | Status Run(const FeedType& inputs, const std::vector<Output>& fetch_outputs, |
| 82 | std::vector<Tensor>* outputs) const; |
| 83 | |
| 84 | /// Same as above. Additionally runs the operations ins `run_outputs`. |
| 85 | Status Run(const FeedType& inputs, const std::vector<Output>& fetch_outputs, |
| 86 | const std::vector<Operation>& run_outputs, |
| 87 | std::vector<Tensor>* outputs) const; |
| 88 | |
| 89 | /// Use `run_options` to turn on performance profiling. `run_metadata`, if not |
| 90 | /// null, is filled in with the profiling results. |
| 91 | Status Run(const RunOptions& run_options, const FeedType& inputs, |
| 92 | const std::vector<Output>& fetch_outputs, |
| 93 | const std::vector<Operation>& run_outputs, |
| 94 | std::vector<Tensor>* outputs, RunMetadata* run_metadata) const; |
| 95 | |
| 96 | /// \brief A handle to a subgraph, created with |
| 97 | /// `ClientSession::MakeCallable()`. |
| 98 | typedef int64 CallableHandle; |
| 99 | |
| 100 | /// \brief Creates a `handle` for invoking the subgraph defined by |
| 101 | /// `callable_options`. |
| 102 | /// NOTE: This API is still experimental and may change. |
| 103 | Status MakeCallable(const CallableOptions& callable_options, |
| 104 | CallableHandle* out_handle); |
| 105 | |
| 106 | /// \brief Invokes the subgraph named by `handle` with the given options and |
| 107 | /// input tensors. |
| 108 | /// |
| 109 | /// The order of tensors in `feed_tensors` must match the order of names in |
| 110 | /// `CallableOptions::feed()` and the order of tensors in `fetch_tensors` will |