public final class Session.Runner extends Object
Operation
s and evaluate Tensors
.
A Runner runs the necessary graph fragments to execute every Operation
required to
evaluate the Tensors
to fetch. The feed(String,int,Tensor)
call allows
callers to override the value of Tensors
in the graph by substituting the
provided Tensors
for the outputs of the operations provided to feed(String,int,Tensor)
.
Constructor and Description |
---|
Runner() |
Modifier and Type | Method and Description |
---|---|
Session.Runner |
addTarget(Operand<?> operand)
|
Session.Runner |
addTarget(Operation operation)
|
Session.Runner |
addTarget(String operation)
|
Session.Runner |
feed(Operand<?> operand,
Tensor<?> t)
Use
t instead of the Tensor referred to by executing the operation referred to by
operand . |
Session.Runner |
feed(String operation,
int index,
Tensor<?> t)
Avoid evaluating the
index -th output of operation by substituting t
for the value it produces. |
Session.Runner |
feed(String operation,
Tensor<?> t)
Avoid evaluating
operation and substitute t for the value it produces. |
Session.Runner |
fetch(Operand<?> operand)
Makes
run() return the Tensor referred to by the output of operand . |
Session.Runner |
fetch(Output<?> output)
Makes
run() return the Tensor referred to by output . |
Session.Runner |
fetch(String operation)
Make
run() return the output of operation . |
Session.Runner |
fetch(String operation,
int index)
|
List<Tensor<?>> |
run()
Execute the graph fragments necessary to compute all requested fetches.
|
Session.Run |
runAndFetchMetadata()
Execute graph fragments to compute requested fetches and return metadata about the run.
|
Session.Runner |
setOptions(byte[] options)
(Experimental method): set options (typically for debugging) for this run.
|
public Session.Runner feed(String operation, Tensor<?> t)
operation
and substitute t
for the value it produces.operation
- Is either the string name of the operation, in which case this method is a
shorthand for feed(operation, 0)
, or it is a string of the form
operation_name:output_index , in which case this method acts like feed(operation_name, output_index)
. These colon-separated names are commonly used in the
SignatureDef
protocol buffer messages that are included in SavedModelBundle.metaGraphDef()
.public Session.Runner feed(String operation, int index, Tensor<?> t)
index
-th output of operation
by substituting t
for the value it produces.
Operations in a Graph
can have multiple outputs, index
identifies which
one t
is being provided for.
public Session.Runner feed(Operand<?> operand, Tensor<?> t)
t
instead of the Tensor referred to by executing the operation referred to by
operand
.public Session.Runner fetch(String operation)
run()
return the output of operation
.operation
- Is either the string name of the operation, in which case this method is a
shorthand for fetch(operation, 0)
, or it is a string of the form
operation_name:output_index , in which case this method acts like fetch(operation_name, output_index)
. These colon-separated names are commonly used in
the SignatureDef
protocol buffer messages that are included in SavedModelBundle.metaGraphDef()
.public Session.Runner fetch(String operation, int index)
public Session.Runner fetch(Output<?> output)
run()
return the Tensor referred to by output
.public Session.Runner fetch(Operand<?> operand)
run()
return the Tensor referred to by the output of operand
.public Session.Runner addTarget(String operation)
public Session.Runner addTarget(Operation operation)
IllegalArgumentException
- if the operation is not a GraphOperation
public Session.Runner addTarget(Operand<?> operand)
public Session.Runner setOptions(byte[] options)
The options are presented as a serialized RunOptions protocol buffer.
The org.tensorflow package is free of any protocol buffer dependencies in order to remain friendly to resource constrained systems (where something like nanoproto may be more appropriate). A cost of that is this lack of type-safety in this API function. This choice is under review and this function may be replaced by more type-safe equivalents at any time.
public List<Tensor<?>> run()
WARNING: The caller assumes ownership of all returned Tensors
, i.e.,
the caller must call Tensor.close()
on all elements of the returned list to free up
resources.
TODO(ashankar): Reconsider the return type here. Two things in particular: (a) Make it
easier for the caller to cleanup (perhaps returning something like AutoCloseableList in
SessionTest.java), and (b) Evaluate whether the return value should be a list, or maybe a
Map<Output, Tensor>
?
TODO(andrewmyers): It would also be good if whatever is returned here made it easier to extract output tensors in a type-safe way.
public Session.Run runAndFetchMetadata()
This is exactly like run()
, but in addition to the requested Tensors, also
returns metadata about the graph execution in the form of a serialized RunMetadata
protocol buffer.
Copyright © 2022. All rights reserved.