Error while import keras: AttributeError: module ‘tensorflow.compat.v2.__internal__’ has no attribute ‘register_clear_session_function’

We Are Going To Discuss About Error while import keras: AttributeError: module ‘tensorflow.compat.v2.__internal__’ has no attribute ‘register_clear_session_function’. So lets Start this Python Article.

Error while import keras: AttributeError: module ‘tensorflow.compat.v2.__internal__’ has no attribute ‘register_clear_session_function’

  1. How to solve Error while import keras: AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'register_clear_session_function'

    you can should use import tensorflow.keras instead of import keras.
    More info here

  2. Error while import keras: AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'register_clear_session_function'

    you can should use import tensorflow.keras instead of import keras.
    More info here

Solution 1

you can should use import tensorflow.keras instead of import keras.
More info here

Original Author MHP Of This Content

Solution 2

!pip install -U -q segmentation-models
!pip install -q tensorflow==2.1
!pip install -q keras==2.3.1
!pip install -q tensorflow-estimator==2.1.

## Imports libs
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ["SM_FRAMEWORK"] = "tf.keras"

from tensorflow import keras
import segmentation_models as sm

Original Author AKSHAY KUMAR RAY Of This Content

Solution 3

This can be caused by a version mismatch between Keras installation and Tensorflow. Make sure their versions match.

Original Author xuhdev Of This Content

Solution 4

None of the other answers here worked for me. I ended up updating keras and tensorflow as follows:

pip install --upgrade keras
pip install --upgrade tensorflow

Now, it works for me.

Original Author Hagbard Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment