How to fix "AttributeError: module 'tensorflow' has no attribute 'get_default_graph'"?
Please try:
from tensorflow.keras.models import Sequential
instead of
from keras.models import Sequential
for latest tensorflow 2 replace the above code with below code with some changes
for details check keras documentation: https://www.tensorflow.org/guide/keras/overview
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.models import Sequential, load_model
model = tf.keras.Sequential()
model.add(layers.Dense(32, input_dim=784))
model.add(layers.Activation('relu'))
model.add(layers.LSTM(17))
model.add(layers.Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer=tf.keras.optimizers.Adam(0.01), metrics=['accuracy'])
For tf 2.1.0 I change to tf.compat.v1.get_default_graph()
import tensorflow as tf
# sess = tf.compat.v1.Session(graph=tf.import_graph_def(), config=session_conf)
sess = tf.compat.v1.Session(graph=tf.compat.v1.get_default_graph(), config=session_conf)
tf.compat.v1.keras.backend.set_session(sess)