Session.Runner

public final class Session.Runner

Run 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) .

Public Constructors

Public Methods

Session.Runner
addTarget (String operation)
Make run() execute operation , but not return any evaluated Tensors .
Session.Runner
addTarget ( Op op)
Make run() execute op , 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 ( Operand <?> operand, Tensor t)
Use t instead of the Tensor referred to by executing the operation referred to by operand .
Session.Runner
fetch (String operation)
Make run() return the output of operation .
Session.Runner
fetch (String operation, int index)
Make run() return the index -th output of operation .
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 .
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 ( RunOptions options)
Set options (typically for debugging) for this run.

Inherited Methods

Public Constructors

public Runner ()

Public Methods

public Session.Runner addTarget (String operation)

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

Parameters
operation the string name of the operation to execute
Returns
  • this session runner
Throws
IllegalArgumentException if no operation exists with the provided name

public Session.Runner addTarget ( Op op)

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

Parameters
op the operation to execute, as an Op
Returns
  • this session runner

public Session.Runner addTarget ( Operation operation)

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

Parameters
operation the operation to execute
Returns
  • this session runner
Throws
IllegalArgumentException if the operation is not a GraphOperation

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

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

Parameters
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 metaGraphDef() .
t the tensor substituting the operation
Returns
  • this session runner
Throws
IllegalArgumentException if no output exists with the provided name

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 the string name of the operation
t the tensor substituting the operation
Returns
  • this session runner
Throws
IllegalArgumentException if no operation exists with the provided name
IndexOutOfBoundsException if the operation has no output with the given index

public Session.Runner feed ( Operand <?> operand, Tensor t)

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

Parameters
operand the node in the graph representing the operation to substitute
t the tensor substituting the operation
Returns
  • this session runner

public Session.Runner fetch (String operation)

Make run() return the output of operation .

Parameters
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 metaGraphDef() .
Returns
  • this session runner
Throws
IllegalArgumentException if no output exists with the provided name

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 the string name of the operation
Returns
  • this session runner
Throws
IllegalArgumentException if no operation exists with the provided name
IndexOutOfBoundsException if the operation has no output with the given index

public Session.Runner fetch ( Operand <?> operand)

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

Parameters
operand the node to fetch the tensor from, as an operand
Returns
  • this session runner

public Session.Runner fetch ( Output <?> output)

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

Parameters
output the node to fetch the tensor from
Returns
  • this session runner

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> ?

TODO(andrewmyers): It would also be good if whatever is returned here made it easier to extract output tensors in a type-safe way.

Returns
  • list of resulting tensors fetched by this session runner

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 RunMetadata protocol buffer .

Returns
  • list of resulting tensors fetched by this session runner, with execution metadata

public Session.Runner setOptions ( RunOptions options)

Set options (typically for debugging) for this run.

The options are presented as a RunOptions protocol buffer .

Parameters
options a RunOptions proto
Returns
  • this session runner