Session

Wrapper class for TF_Session.

Constructors

this
this(TF_Graph* graph, bool useXLA)

Constructs a new session.

Destructor

~this
~this()
Undocumented in source.

Postblit

this(this)
this(this)

Not copyable

Alias This

base

Members

Functions

close
void close()

Closes and deletes input/output values explicitly.

run
void run(Operation[] inputs, Tensor[] inputValues, Operation[] outputs, Tensor[] outputValues, Operation[] targets)

Runs session to evaluate outputs by given inputs.

run
Tensor[N] run(Operation[N] outputs, Tensor[Operation] inputs)

Runs in python-like usage.

Variables

base
TF_Session* base;

Raw session data.

status
TF_Status* status;

Status

Examples

nothrow, nogc, and safe usage

import std.typecons : tuple;
import tfd.tensor : tensor, Tensor;
import tfd.graph : newGraph, Operation;

with (newGraph)
{
  Operation x = placeholder!int("x");
  Operation two = constant(2);
  Operation add = x + two;

  Operation[1] inops;
  inops[0] = x;
  Tensor[1] inputs;
  inputs[0] = 3.tensor;
  Operation[1] outops;
  outops[0] = add;
  Tensor[1] outputs;
  session.run(inops, inputs, outops, outputs);
  assert(outputs[0].scalar!int == 5);

  write("tmp.pb");
}
with (newGraph)
{
  read("tmp.pb");
  // auto x = operationByName("x");
  // auto add = operationByName("add");
}

TODO(karita): more interesting example. e.g., logistic regression.

import tfd;

/// scalar add
with (newGraph)
{
  Operation x = placeholder!int("x");
  Operation two = constant(2);
  Operation add = x + two;

  Tensor addVal = session.run([add], [x: 3.tensor])[0];
  assert(addVal.scalar!int == 5);
}

/// tensor add
with (newGraph)
{
  import mir.ndslice : as, iota;

  auto i = iota(2, 3, 4).as!float;

  Operation x = placeholder!float("x", 2, 3, 4);
  Operation two = constant(i);
  Operation add = x + two;

  Tensor addVal = session.run([add], [x: i.tensor])[0];
  assert(addVal.sliced!(float, 3) == i * 2);
}

Meta