AttributeError: module 'tensorflow.keras' has no attribute 'get_default_graph'
时间: 2023-09-19 13:06:15 浏览: 162
module ‘tensorflow’ has no attribute ‘get_default_graph’
This error occurs when you try to access the `get_default_graph` function in `tensorflow.keras` module, which does not exist.
In TensorFlow 2.0, the default graph is now implicit and is managed automatically. You no longer need to create a graph and set it as the default graph. Therefore, you should remove any references to `get_default_graph` in your code.
Instead, you can use TensorFlow 2.0's eager execution mode, which allows you to execute TensorFlow operations immediately as they are called, without building a computational graph.
To enable eager execution, simply add the following line at the beginning of your code:
```
import tensorflow as tf
tf.compat.v1.enable_eager_execution()
```
With eager execution, you can use the `tf.function` decorator to define TensorFlow operations as functions, and then call them directly.
阅读全文