get_default_graph does not work with either eager execution or
tf.function, and you should not invoke it directly. To migrate code that
uses Graph-related functions to TF2, rewrite the code without them. See the
migration guide for more
description about the behavior and semantic changes between Tensorflow 1 and
Tensorflow 2.
Description
The returned graph will be the innermost graph on which a
Graph.as_default() context has been entered, or a global default
graph if none has been explicitly created.
Returns
The default Graph being used in the current thread.
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tf.compat.v1.get_default_graph\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/framework/ops.py#L5015-L5040) |\n\nReturns the default graph for the current thread. \n\n tf.compat.v1.get_default_graph() -\u003e ../../../tf/Graph\n\n\u003cbr /\u003e\n\nMigrate to TF2\n--------------\n\n\u003cbr /\u003e\n\n| **Caution:** This API was designed for TensorFlow v1. Continue reading for details on how to migrate from this API to a native TensorFlow v2 equivalent. See the [TensorFlow v1 to TensorFlow v2 migration guide](https://www.tensorflow.org/guide/migrate) for instructions on how to migrate the rest of your code.\n\n`get_default_graph` does not work with either eager execution or\n[`tf.function`](../../../tf/function), and you should not invoke it directly. To migrate code that\nuses Graph-related functions to TF2, rewrite the code without them. See the\n[migration guide](https://www.tensorflow.org/guide/migrate) for more\ndescription about the behavior and semantic changes between Tensorflow 1 and\nTensorflow 2.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nDescription\n-----------\n\nThe returned graph will be the innermost graph on which a\n[`Graph.as_default()`](https://www.tensorflow.org/api_docs/python/tf/Graph#as_default) context has been entered, or a global default\ngraph if none has been explicitly created.\n| **Note:** The default graph is a property of the current thread. If you create a new thread, and wish to use the default graph in that thread, you must explicitly add a `with g.as_default():` in that thread's function.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| The default `Graph` being used in the current thread. ||\n\n\u003cbr /\u003e"]]