简体   繁体   English

导入时出错 keras: AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'register_clear_session_function'

[英]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 kerasimport 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'

you can should use import tensorflow.keras instead of import keras .您可以使用import tensorflow.keras而不是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.这可能是由于 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.

相关问题 模块“tensorflow.compat.v2.__internal__”没有属性“tf2” - module 'tensorflow.compat.v2.__internal__' has no attribute 'tf2' 属性 AttributeError:模块“tensorflow.compat.v2”没有属性“_internal_” - Attribute AttributeError: module 'tensorflow.compat.v2' has no attribute '_internal_' AttributeError:模块'tensorflow_core.compat.v2'没有属性'__internal__'(一周前工作?) - AttributeError: module 'tensorflow_core.compat.v2' has no attribute '__internal__' (Worked a week ago?) AttributeError: 模块“tensorflow_core.compat.v1”没有属性“contrib” - AttributeError: module 'tensorflow_core.compat.v1' has no attribute 'contrib' AttributeError:模块 'tensorflow.compat.v2' 没有属性 'logging' - AttributeError: module 'tensorflow.compat.v2' has no attribute 'logging' 模块 'tensorflow._api.v1.compat.v2' 没有属性 '__internal__' google colab 错误 - module 'tensorflow._api.v1.compat.v2' has no attribute '__internal__' google colab error Tensorflow.compat.v2.__internal__.tracking' has no attribute 'TrackableSaver' 错误 - Tensorflow.compat.v2.__internal__.tracking' has no attribute 'TrackableSaver' Error AttributeError:加载 tf.compat.v1.train.SessionRunHook 时模块“tensorflow”没有属性“compat” - AttributeError: module 'tensorflow' has no attribute 'compat' when loading tf.compat.v1.train.SessionRunHook Tensorflow 对象检测 AttributeError:模块“tensorflow._api.v1.compat”没有属性“v2” - Tensorflow Object Detection AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v2' AttributeError:模块“ tensorflow._api.v1.compat.v1”没有属性“ pywrap_tensorflow” - AttributeError: module 'tensorflow._api.v1.compat.v1' has no attribute 'pywrap_tensorflow'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM