Keras 'set_session' not available for Tensorflow 2.0

Viewed 9977

Attempting to do the following:

import tensorflow as tf
from keras.models import load_model, Model
from keras import backend as K

sess = tf.compat.v1.Session()
K.set_session(sess)

When I run this in Google Colab I get:

RuntimeError: `set_session` is not available when using TensorFlow 2.0.

Does anyone know how to fix this?

1 Answers

try using the keras backend from the tensorflow path. Your code gives me an error, but this works for me.

import tensorflow as tf
from tensorflow.keras.models import load_model, Model
from tensorflow.python.keras import backend as K

sess = tf.compat.v1.Session()
K.set_session(sess)
Related