Sess = tf.keras.backend.get_session() throws errora

Hi all, while executing the statement
sess = tf.keras.backend.get_session() I got the following error


AttributeError Traceback (most recent call last)

in <cell line: 1>() ----> 1 sess = tf.keras.backend.get_session()

AttributeError: module ‘keras.api._v2.keras.backend’ has no attribute ‘get_session’

The tensflow version used is 2.13.0

Let me know what could be the reason and what is the solution for it.

Thanks and Regards

Nagaraj Trivedi

Hi @Nagaraj_Trivedi

As the error stats that tf.keras.backend does not have get_session() attribute. The get_session() api was available only till TensorFlow 1.x and has been deprecated to use in TensorFlow 2.x.

The reason behind is that the Tensorflow 1.x used a static computation graph to define the computation in graph and then run it within a session. But in Tensorflow 2.x computations are performed dynamically using eager execution. Hence, there is no use of get_session() in this case in TF 2.x.