public final class Graph extends Object implements ExecutionEnvironment, AutoCloseable
Instances of a Graph are thread-safe.
WARNING: Resources consumed by the Graph object must be explicitly freed by invoking
the close() method then the Graph object is no longer needed.
| Modifier and Type | Class and Description |
|---|---|
static interface |
Graph.WhileSubgraphBuilder
Used to instantiate an abstract class which overrides the buildSubgraph method to build a
conditional or body subgraph for a while loop.
|
| Constructor and Description |
|---|
Graph()
Create an empty Graph.
|
| Modifier and Type | Method and Description |
|---|---|
Output<?>[] |
addGradients(Output<?> y,
Output<?>[] x)
Adds operations to compute the partial derivatives of sum of
ys w.r.t xs,
i.e., dy/dx_1, dy/dx_2... |
Output<?>[] |
addGradients(String prefix,
Output<?>[] y,
Output<?>[] x,
Output<?>[] dx)
Adds operations to compute the partial derivatives of sum of
ys w.r.t xs, i.e.,
d(y_1 + y_2 + ...)/dx_1, d(y_1 + y_2 + ...)/dx_2... |
void |
close()
Release resources associated with the Graph.
|
void |
importGraphDef(byte[] graphDef)
Import a serialized representation of a TensorFlow graph.
|
void |
importGraphDef(byte[] graphDef,
String prefix)
Import a serialized representation of a TensorFlow graph.
|
GraphOperationBuilder |
opBuilder(String type,
String name)
Returns a builder to add
Operations to the Graph. |
GraphOperation |
operation(String name)
Returns the operation (node in the Graph) with the provided name.
|
Iterator<Operation> |
operations()
Iterator over all the
Operations in the graph. |
byte[] |
toGraphDef()
Generate a serialized representation of the Graph.
|
Output<?>[] |
whileLoop(Output<?>[] inputs,
Graph.WhileSubgraphBuilder cgBuilder,
Graph.WhileSubgraphBuilder bgBuilder,
String name)
Builds a while loop.
|
public void close()
Blocks until there are no active Session instances referring to this Graph. A Graph
is not usable after close returns.
close in interface AutoCloseablepublic GraphOperation operation(String name)
Or null if no such operation exists in the Graph.
public Iterator<Operation> operations()
Operations in the graph.
The order of iteration is unspecified. Consumers of the iterator will receive no notification should the underlying graph change during iteration.
public GraphOperationBuilder opBuilder(String type, String name)
Operations to the Graph.opBuilder in interface ExecutionEnvironmenttype - of the Operation (i.e., identifies the computation to be performed)name - to refer to the created Operation in the graph.OperationBuilder, which will add the Operation to the graph when OperationBuilder.build() is invoked. If OperationBuilder.build() is not invoked,
then some resources may leak.public void importGraphDef(byte[] graphDef)
throws IllegalArgumentException
The serialized representation of the graph, often referred to as a GraphDef, can be
generated by toGraphDef() and equivalents in other language APIs.
IllegalArgumentException - if graphDef is not a recognized serialization of a graph.importGraphDef(byte[], String)public void importGraphDef(byte[] graphDef,
String prefix)
throws IllegalArgumentException
graphDef - the serialized representation of a TensorFlow graph.prefix - a prefix that will be prepended to names in graphDefIllegalArgumentException - if graphDef is not a recognized serialization of a graph.importGraphDef(byte[])public byte[] toGraphDef()
public Output<?>[] addGradients(String prefix, Output<?>[] y, Output<?>[] x, Output<?>[] dx)
ys w.r.t xs, i.e.,
d(y_1 + y_2 + ...)/dx_1, d(y_1 + y_2 + ...)/dx_2...
dx are used as initial gradients (which represent the symbolic partial derivatives
of some loss function L w.r.t. y). dx must be null or have size of
y.
If dx is null, the implementation will use dx of OnesLike for all shapes in y.
prefix is used as the name prefix applied to all nodes added to the graph to compute
gradients. It must be unique within the provided graph or the operation will fail.
If prefix is null, then one will be chosen automatically.
prefix - unique string prefix applied before the names of nodes added to the graph to
compute gradients. If null, a default one will be chosen.y - output of the function to derivex - inputs of the function for which partial derivatives are computeddx - if not null, the partial derivatives of some loss function L w.r.t. ydy with the size of xpublic Output<?>[] addGradients(Output<?> y, Output<?>[] x)
ys w.r.t xs,
i.e., dy/dx_1, dy/dx_2...
This is a simplified version of #addGradients(String, Output[], Output[], Output[]) where {@code y} is a single output, {@code dx} is null and {@code prefix} is null.
y - output of the function to derivex - inputs of the function for which partial derivatives are computeddy with the size of xpublic Output<?>[] whileLoop(Output<?>[] inputs, Graph.WhileSubgraphBuilder cgBuilder, Graph.WhileSubgraphBuilder bgBuilder, String name)
inputs - the loop inputscgBuilder - WhileSubgraphBuilder to build the conditional subgraphbgBuilder - WhileSubgraphBuilder to build the body subgraphname - name for the loopinputsCopyright © 2022. All rights reserved.