Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras 'set_session' not available for Tensorflow 2.0

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?

like image 941
Bert Hanz Avatar asked Jul 10 '20 17:07

Bert Hanz


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)
like image 142
Nick Avatar answered Nov 11 '22 04:11

Nick