Session.Runner

public final class Session.Runner

Run Operations 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 substituing the provided Tensors for the outputs of the operations provided to feed(String, int, Tensor).

Public Constructors

Public Methods

Session.Runner
addTarget(String operation)
Make run() execute operation, but not return any evaluated Tensors.
Session.Runner
addTarget(Operation operation)
Make run() execute operation, but not return any evaluated Tensors.
Session.Runner
feed(String operation, Tensor t)
Avoid evaluating operation and substitute t for the value it produces.
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(Output o, Tensor t)
Use t instead of the Tensor referred to by executing the operation referred to by output.
Session.Runner
fetch(String operation)
Make run() return the output of operation.
Session.Runner
fetch(Output output)
Makes run() return the Tensor referred to by output.
Session.Runner
fetch(String operation, int index)
Make run() return the index-th output of operation.
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.

Inherited Methods

Public Constructors

public Session.Runner ()

Public Methods

public Session.Runner addTarget (String operation)

Make run() execute operation, but not return any evaluated Tensors.

Parameters
operation

public Session.Runner addTarget (Operation operation)

Make run() execute operation, but not return any evaluated Tensors.

Parameters
operation

public Session.Runner feed (String operation, Tensor t)

Avoid evaluating operation and substitute t for the value it produces.

This method is a shorthand for feed(operation, 0, t).

Parameters
operation
t

public 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.

Operations in a Graph can have multiple outputs, index identifies which one t is being provided for.

Parameters
operation
index
t

public Session.Runner feed (Output o, Tensor t)

Use t instead of the Tensor referred to by executing the operation referred to by output.

Parameters
o
t

public Session.Runner fetch (String operation)

Make run() return the output of operation.

This method is a shorthand for fetch(operation, 0)

Parameters
operation

public Session.Runner fetch (Output output)

Makes run() return the Tensor referred to by output.

Parameters
output

public Session.Runner fetch (String operation, int index)

Make run() return the index-th output of operation.

Operations in a Graph can have multiple outputs, index identifies which one to return.

Parameters
operation
index

public List<Tensor> run ()

Execute the graph fragments necessary to compute all requested fetches.

WARNING: The caller assumes ownership of all returned Tensors, i.e., the caller must call 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>?

public Session.Run runAndFetchMetadata ()

Execute graph fragments to compute requested fetches and return metadata about the run.

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.

public Session.Runner setOptions (byte[] options)

(Experimental method): set options (typically for debugging) for this run.

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.

Parameters
options