geometrikal
geometrikal

Reputation: 3294

tf.keras.backend.get_session() and keras.backend.get_session() return different session objects

I've noticed that tf.keras.backend.get_session() and keras.backend.get_session() return different session objects.

Anyway to make sure they return the same object? I have some code that uses tf.keras.backend.get_session() to save a Keras model with tf.saved_model.simple_save but it throws an uninitialised error if the model comes from a library that uses keras instead of tensorflow.keras

Example code:

import tensorflow as tf
from keras.applications import ResNet50
import keras.backend as K
import tensorflow.keras.backend as J

model = ResNet50()
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

print(K.get_session())
print(J.get_session())

Upvotes: 1

Views: 1565

Answers (1)

Dr. Snoopy
Dr. Snoopy

Reputation: 56377

You have bigger issues, you should not mix code using keras and tf.keras, these modules are not compatible, and you will get weird errors if you mix them.

If you really have a good reason to change the session, you can use K.set_session to set the session manually to the object returned by the other implementation.

Upvotes: 2

Related Questions