When I want to use Keras with TensorFlow 2 I got this error:
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
When I want to use Keras with TensorFlow 2 I got this error:
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
The Keras API (https://keras.io/) has multiple implementations, including the original and reference implementation (https://github.com/keras-team/keras), but also various other implementations, including tf.keras, which is part of TensorFlow.
So there are two ways you can use Keras with TensorFlow:
To use tf.keras, you must make sure to use the correct imports:
from tensorflow import keras
# NOT: import keras
Similarly, use:
from tensorflow.keras.layers import Dense
# Not from keras.layers import Dense
Hope this helps.
Since TensorFlow 2 defaults to eager execution Keras will need some changes in order to be compatible with it, but until then a previous version of TensorFlow is required.