模块 'tensorflow' 没有属性 'logging'

module 'tensorflow' has no attribute 'logging'

我正在尝试 运行 v2.0 中的 tensorflow 代码,但出现以下错误

AttributeError: module 'tensorflow' has no attribute 'logging'

我不想简单地从代码中删除它。

tf.logging 用于 Logging and Summary Operations 并且在 TF 2.0 中它已被删除以支持开源 absl-py,并使主要的 tf.* 命名空间具有将被使用频率更高。

在 TF.2 中,较少使用的功能已消失或移动到 tf.math

等子包中

因此,您可以:

而不是 tf.logging
  • tf_upgrade_v2 将升级脚本并将 tf.logging 更改为 tf.compat.v1.logging
  • Python 可以改用日志模块
  • 导入absl-py库

如果您使用的是其他人的代码,最好安装与作者使用的相同的 Tensorflow 版本,或者降级您的 Tensorflow 版本。你可能想试试这个:

pip install tensorflow==1.15.0

或者如果你有 GPU:

pip install tensorflow-gpu==1.15.0

您可能仍会收到 depricated 警告,但是您不需要修改多个文件,将 tf 替换为 tf.compat.v1