|TensorFlow 1 version||View source on GitHub|
A TensorFlow computation, represented as a dataflow graph.
Compat aliases for migration
See Migration guide for more details.
Used in the notebooks
|Used in the guide||Used in the tutorials|
Graphs are used by
tf.functions to represent the function's computations.
Each graph contains a set of
tf.Operation objects, which represent units of
tf.Tensor objects, which represent the units of data that
flow between operations.
Using graphs directly (deprecated)
tf.Graph can be constructed and used directly without a
was required in TensorFlow 1, but this is deprecated and it is recommended to
tf.function instead. If a graph is directly used, other deprecated
TensorFlow 1 classes are also required to execute the graph, such as a
A default graph can be registered with the
manager. Then, operations will be added to the graph instead of being executed
eagerly. For example:
g = tf.Graph() with g.as_default(): # Define operations and tensors in `g`. c = tf.constant(30.0) assert c.graph is g
tf.compat.v1.get_default_graph() can be used to obtain the default graph.
Important note: This class is not thread-safe for graph construction. All operations should be created from a single thread, or external synchronization must be provided. Unless otherwise specified, all methods are not thread-safe.
Graph instance supports an arbitrary number of "collections"
that are identified by name. For convenience when building a large
graph, collections can store groups of related objects: for
tf.Variable uses a collection (named
all variables that are created during the construction of a graph. The caller
may define additional collections by specifying a new name.