Session

public final class Session

Driver for Graph execution.

A Session instance encapsulates the environment in which Operation s in a Graph are executed to compute Tensors . For example:

// Let's say graph is an instance of the Graph class
 // for the computation y = 3 * x

 try (Session s = new Session(graph)) {
   try (Tensor x = Tensor.create(2.0f);
       Tensor y = s.runner().feed("x", x).fetch("y").run().get(0)) {
       System.out.println(y.floatValue());  // Will print 6.0f
   
   try (Tensor x = Tensor.create(1.1f);
       Tensor y = s.runner().feed("x", x).fetch("y").run().get(0)) {
       System.out.println(y.floatValue());  // Will print 3.3f
   }
 }
 }

WARNING: A Session owns resources that must be explicitly freed by invoking close() .

Instances of a Session are thread-safe.

Nested Classes

class Session.Run Output tensors and metadata obtained when executing a session.
class Session.Runner Run Operation s and evaluate Tensors .

Public Constructors

Session ( Graph g)
Construct a new session with the associated Graph .
Session ( Graph g, byte[] config)
Construct a new session with the associated Graph and configuration options.

Public Methods

void
close ()
Release resources associated with the Session.
Session.Runner
runner ()
Create a Runner to execute graph operations and evaluate Tensors.

Inherited Methods

Public Constructors

public Session ( Graph g)

Construct a new session with the associated Graph .

public Session ( Graph g, byte[] config)

Construct a new session with the associated Graph and configuration options.

Parameters
g The Graph the created Session will operate on.
config Configuration parameters for the session specified as a serialized ConfigProto protocol buffer.
Throws
IllegalArgumentException if the config is not a valid serialization of the ConfigProto protocol buffer.

Public Methods

public void close ()

Release resources associated with the Session.

Blocks until there are no active executions ( run() calls). A Session is not usable after close returns.

public Session.Runner runner ()

Create a Runner to execute graph operations and evaluate Tensors.