简体   繁体   中英

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

I want to import keras after I did pip install keras , but it shows message as shown below. I even can't call any function from keras library. Can anyone know about this?

import keras

Error:

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

!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

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

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.

from keras.models import Model

ERROR:

AttributeError: module 'tensorflow.compat.v2. internal ' has no attribute 'register_clear_session_function'

after tf2, you should use

from tensorflow import keras

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM