AttributeError: module 'tensorflow_core.python.keras.api._v2.keras.backend' has no attribute 'get_session'


I’m trying to execute this hello world example (26):

But got this error after completing the 5 training epochs:
Traceback (most recent call last):

  • File “”, line 95, in *
  • main()*
  • File “”, line 92, in main*
  • save(model, filename=“models/lenet5.pb”)*
  • File “”, line 78, in save*
  • sess = tf.keras.backend.get_session()*
    AttributeError: module ‘tensorflow_core.python.keras.api._v2.keras.backend’ has no attribute 'get_session

how can i solve it?

this is my keras version:
xavier@xavier-desktop:/usr/src/tensorrt/samples/python/end_to_end_tensorflow_mnist$ sudo pip list | grep Keras
WARNING: The directory ‘/home/xavier/.cache/pip’ or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
Keras 2.3.1
Keras-Applications 1.0.8
Keras-Preprocessing 1.1.0