[英]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.我想在执行pip install keras
后import keras
keras,但它显示的消息如下所示。 I even can't call any function from keras library.我什至无法从 keras 库调用任何 function。 Can anyone know about this?任何人都可以知道这件事吗?
import keras
Error:错误:
AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'register_clear_session_function'
!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.这可能是由于 Keras 安装和 Tensorflow 之间的版本不匹配造成的。 Make sure their versions match.确保它们的版本匹配。
None of the other answers here worked for me.这里没有其他答案对我有用。 I ended up updating keras and tensorflow as follows:我最终更新了 keras 和 tensorflow 如下:
pip install --upgrade keras
pip install --upgrade tensorflow
Now, it works for me.现在,它对我有用。
from keras.models import Model从 keras.models 进口 Model
ERROR:错误:
AttributeError: module 'tensorflow.compat.v2. AttributeError:模块'tensorflow.compat.v2。 internal ' has no attribute 'register_clear_session_function'内部'没有属性'register_clear_session_function'
after tf2, you should use在 tf2 之后,你应该使用
from tensorflow import keras
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.