【问题标题】:python3 recognizes tensorflow, but doesn't recognize any of its attributespython3识别张量流,但不识别它的任何属性
【发布时间】:2020-02-22 18:08:39
【问题描述】:

python3 无法识别任何 tensorflow 属性

AttributeError: 模块 'tensorflow' 没有属性 'variable_scope'

AttributeError: 模块 'tensorflow' 没有属性 'squared_difference'

tensorflow 已安装

pip3 列表 | grep 张量流 张量流 2.0.0
张量流估计器 2.0.1

【问题讨论】:

    标签: tensorflow attributeerror


    【解决方案1】:

    TensorFlow 2.0 清理了一些 API。 squared_difference() 等数学函数现在在 tf.math 下。

    TensorFlow 2.0 中没有tf.variable_scope()。我建议阅读this post,其中包含有关如何将代码迁移到 TF2 的示例。

    如果您希望您的代码与旧版本的 TensorFlow 兼容,可以使用tf.compat.v1.variable_scope()

    【讨论】:

    • 谢谢,其他属性错误呢?不仅不能识别variable_scope,还有:name_scope, contrib, get_variable, AUTO_REUSE, float32, placeholder, Saver, Session, global_variables_initializer, ...
    • 其中大部分已被完全替换。 TF2 中没有范围、会话或占位符,并且不需要初始化变量。还有一些刚刚清理干净。
    • 哎呀,好吧,我想我必须重写我的代码或使用旧版本的 tensorflow。没想到发生了这么大的变化。
    • 你总是可以在兼容模式下运行它:tf.compat.v1....,但你迟早要适应
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 2017-06-21
    • 2022-01-04
    • 2020-09-10
    • 2011-10-06
    • 2020-10-03
    • 1970-01-01
    相关资源
    最近更新 更多