@Namespace(value="tensorflow") @Properties(inherit=tensorflow.class) public class Session extends AbstractSession
c++
tensorflow::GraphDef graph;
// ... Create or load graph into "graph".
// This example uses the default options which connects
// to a local runtime.
tensorflow::SessionOptions options;
std::unique_ptr<tensorflow::Session>
session(tensorflow::NewSession(options));
// Create the session with this graph.
tensorflow::Status s = session->Create(graph);
if (!s.ok()) { ... }
// Run the graph and fetch the first output of the "output"
// operation, and also run to but do not return anything
// for the "update_state" operation.
std::vector<tensorflow::Tensor> outputs;
s = session->Run({}, {"output:0"}, {"update_state"}, &outputs);
if (!s.ok()) { ... }
// Map the output as a flattened float tensor, and do something
// with it.
auto output_tensor = outputs[0].flat<float>();
if (output_tensor(0) > 0.5) { ... }
// Close the session to release the resources associated with
// this session.
session->Close();
A Session allows concurrent calls to Run(), though a Session must
be created / extended by a single thread.
Only one thread must call Close(), and Close() must only be called
after all other calls to Run() have returned.AbstractSession.DeleteDeallocator
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator, Pointer.ReferenceCounter
Constructor and Description |
---|
Session(Pointer p)
Pointer cast constructor.
|
Session(SessionOptions options)
Calls
tensorflow#NewSession(SessionOptions) and registers a deallocator. |
Modifier and Type | Method and Description |
---|---|
Status |
Close()
\brief Closes this session.
|
Status |
Close(RunOptions run_options) |
Status |
Create(GraphDef graph)
\brief Create the graph to be used for the session.
|
Status |
Create(RunOptions run_options,
GraphDef graph)
NOTE: This API is still experimental and may change.
|
Status |
Extend(GraphDef graph)
\brief Adds operations to the graph that is already registered with the
Session.
|
Status |
Extend(RunOptions run_options,
GraphDef graph) |
Status |
ListDevices(DeviceAttributes response)
\brief List devices in the session.
|
Status |
LocalDeviceManager(DeviceMgr output) |
Status |
LocalDeviceManager(PointerPointer output) |
Status |
MakeCallable(CallableOptions callable_options,
long... out_handle) |
Status |
MakeCallable(CallableOptions callable_options,
LongBuffer out_handle) |
Status |
MakeCallable(CallableOptions callable_options,
LongPointer out_handle)
\brief Creates a
handle for invoking the subgraph defined by
callable_options . |
Status |
PRun(BytePointer handle,
StringTensorPairVector inputs,
StringVector output_names,
TensorVector outputs)
\brief Continues the pending execution specified by
handle with the
provided input tensors and fills outputs for the endpoints specified
in output_names . |
Status |
PRun(String handle,
StringTensorPairVector inputs,
StringVector output_names,
TensorVector outputs) |
Status |
PRunSetup(StringVector input_names,
StringVector output_names,
StringVector target_nodes,
BytePointer handle)
\brief Sets up a graph for partial execution.
|
Status |
ReleaseCallable(long handle)
\brief Releases resources associated with the given
handle in this
session. |
Status |
Run(RunOptions run_options,
StringTensorPairVector inputs,
StringVector output_tensor_names,
StringVector target_node_names,
TensorVector outputs,
RunMetadata run_metadata)
\brief Like
Run , but allows users to pass in a RunOptions proto and
to retrieve non-Tensor metadata output via a RunMetadata proto for this
step. |
Status |
Run(StringTensorPairVector inputs,
StringVector output_tensor_names,
StringVector target_node_names,
TensorVector outputs)
\brief Runs the graph with the provided input tensors and fills
outputs for the endpoints specified in output_tensor_names . |
Status |
RunCallable(long handle,
TensorVector feed_tensors,
TensorVector fetch_tensors,
RunMetadata run_metadata)
\brief Invokes the subgraph named by
handle with the given options and
input tensors. |
Status |
RunCallable(long handle,
TensorVector feed_tensors,
TensorVector fetch_tensors,
RunMetadata run_metadata,
ThreadPoolOptions threadpool_options)
\brief Invokes the subgraph named by
handle with the given options and
input tensors. |
delete
address, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, getDirectBufferAddress, getPointer, getPointer, getPointer, getPointer, hashCode, interruptDeallocatorThread, isNull, isNull, limit, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetAddress, offsetof, offsetof, parseBytes, physicalBytes, physicalBytesInaccurate, position, position, put, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, sizeof, toString, totalBytes, totalCount, totalPhysicalBytes, withDeallocator, zero
public Session(Pointer p)
Pointer(Pointer)
.public Session(SessionOptions options)
tensorflow#NewSession(SessionOptions)
and registers a deallocator.@ByVal public Status Create(@Const @ByRef GraphDef graph)
@ByVal public Status Extend(@Const @ByRef GraphDef graph)
@ByVal public Status Run(@Const @ByRef StringTensorPairVector inputs, @Const @ByRef StringVector output_tensor_names, @Const @ByRef StringVector target_node_names, TensorVector outputs)
outputs
for the endpoints specified in output_tensor_names
.
Runs to but does not return Tensors for the nodes in
target_node_names
.
The order of tensors in outputs
will match the order provided
by output_tensor_names
.
If Run
returns OK()
, then outputs->size()
will be equal to
output_tensor_names.size()
. If Run
does not return OK()
, the
state of outputs
is undefined.
REQUIRES: The name of each Tensor of the input or output must
match a "Tensor endpoint" in the GraphDef
passed to Create()
.
REQUIRES: At least one of output_tensor_names
and
target_node_names
must be non-empty.
REQUIRES: outputs is not nullptr if output_tensor_names
is non-empty.@ByVal public Status Create(@Const @ByRef RunOptions run_options, @Const @ByRef GraphDef graph)
@ByVal public Status Extend(@Const @ByRef RunOptions run_options, @Const @ByRef GraphDef graph)
@ByVal public Status Close(@Const @ByRef RunOptions run_options)
@ByVal public Status Run(@Const @ByRef RunOptions run_options, @Const @ByRef StringTensorPairVector inputs, @Const @ByRef StringVector output_tensor_names, @Const @ByRef StringVector target_node_names, TensorVector outputs, RunMetadata run_metadata)
Run
, but allows users to pass in a RunOptions
proto and
to retrieve non-Tensor metadata output via a RunMetadata
proto for this
step. run_metadata
may be nullptr, in which case any metadata output is
discarded.
NOTE: This API is still experimental and may change.@ByVal public Status PRunSetup(@Const @ByRef StringVector input_names, @Const @ByRef StringVector output_names, @Const @ByRef StringVector target_nodes, @StdString @Cast(value={"char*","std::string*"}) BytePointer handle)
input_names
and output_names
. Returns
handle
that can be used to perform a sequence of partial feeds and
fetches.
NOTE: This API is still experimental and may change.@ByVal public Status PRun(@StdString BytePointer handle, @Const @ByRef StringTensorPairVector inputs, @Const @ByRef StringVector output_names, TensorVector outputs)
handle
with the
provided input tensors and fills outputs
for the endpoints specified
in output_names
.
NOTE: This API is still experimental and may change.@ByVal public Status PRun(@StdString String handle, @Const @ByRef StringTensorPairVector inputs, @Const @ByRef StringVector output_names, TensorVector outputs)
@ByVal public Status ListDevices(@StdVector DeviceAttributes response)
@ByVal public Status Close()
SessionOptions::target
field).@ByVal public Status LocalDeviceManager(@Cast(value="const tensorflow::DeviceMgr**") PointerPointer output)
@ByVal public Status MakeCallable(@Const @ByRef CallableOptions callable_options, @Cast(value="tensorflow::Session::CallableHandle*") LongPointer out_handle)
handle
for invoking the subgraph defined by
callable_options
.
NOTE: This API is still experimental and may change.@ByVal public Status MakeCallable(@Const @ByRef CallableOptions callable_options, @Cast(value="tensorflow::Session::CallableHandle*") LongBuffer out_handle)
@ByVal public Status MakeCallable(@Const @ByRef CallableOptions callable_options, @Cast(value="tensorflow::Session::CallableHandle*") long... out_handle)
@ByVal public Status RunCallable(@Cast(value="tensorflow::Session::CallableHandle") long handle, @Const @ByRef TensorVector feed_tensors, TensorVector fetch_tensors, RunMetadata run_metadata)
handle
with the given options and
input tensors.
The order of tensors in feed_tensors
must and fetch_tensors
will
match the order of names in CallableOptions::feed()
and
CallableOptions::fetch()
when this subgraph was created.
NOTE: This API is still experimental and may change.@ByVal public Status RunCallable(@Cast(value="tensorflow::Session::CallableHandle") long handle, @Const @ByRef TensorVector feed_tensors, TensorVector fetch_tensors, RunMetadata run_metadata, @Const @ByRef ThreadPoolOptions threadpool_options)
handle
with the given options and
input tensors.
The order of tensors in feed_tensors
must and fetch_tensors
will
match the order of names in CallableOptions::feed()
and
CallableOptions::fetch()
when this subgraph was created.
NOTE: This API is still experimental and may change.Copyright © 2022. All rights reserved.