newGraph

Creates a new reference-counted Graph object.

@nogc nothrow @trusted
newGraph
()

Examples

Export/import graph.

import tfd.tensor;

TF_Buffer* buffer;
scope (exit) TF_DeleteBuffer(buffer);
{
  auto graph = newGraph;
  with (graph)
  {
    auto a = placeholder!int("a");
    assert(TF_GraphOperationByName(graph, "a"));
    auto b = constant(3, "b");
    assert(TF_GraphOperationByName(graph, "b"));
    // TODO(karita): provide name "add", identity?
    auto add = a + b;
    assert(TF_GraphOperationByName(graph, "add"));
  }
  buffer = graph.serialize;
  // for coverage
  graph.write("tmp.bin");
}
with (newGraph) {
  // Import from the GraphDef (protobuf)
  deserialize(buffer.data[0 .. buffer.length]);
  auto a = getOperationByName("a");
  auto add = getOperationByName("add");
  const t = session.run([add], [a: 1.tensor])[0].tensor;
  assert(t.scalar!int == 1 + 3);
}

Meta