【问题标题】:AttributeError: module 'tensorflow.compat.v2' has no attribute 'depth_to_space'AttributeError:模块“tensorflow.compat.v2”没有属性“depth_to_space”
【发布时间】:2021-08-15 10:41:20
【问题描述】:

我正在尝试运行使用 tensorflow 版本 1.4.0 编写的代码 我在 google colab 上运行我的代码,它提供了 tensorflow 版本 2.x。

为了运行我的代码,我使用了向后兼容性,例如: 将import tensorflow as tf 替换为

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

这适用于某些事情,但在某种程度上它归结为这个错误

AttributeError: 模块 'tensorflow.compat.v2' 没有属性 'depth_to_space'

as you can see in this image

我无法理解的是这种方法 'depth_to_space' 在 tensorflow 1.x 和 2.x 的两个版本中都有,那么为什么我的 tensorflow 版本没有得到它? 这是 1.x 版本中方法的链接:https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/depth_to_space

请帮助我了解导致此错误的原因。

谢谢, 普拉奈

【问题讨论】:

    标签: python tensorflow tensorflow1.15


    【解决方案1】:

    我尝试使用 Tensorflow 1.15。它工作正常。 看起来你的 TensorFlow 版本有点旧,

    以下示例代码使用 Tf 1.15 测试,没有任何错误。

    import tensorflow as tf
    print(tf.__version__)
    x = [[[[1, 2, 3, 4]]]]
    
    tf.nn.depth_to_space(x, 2, data_format='NHWC', name=None)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-14
      • 2023-01-03
      • 2021-10-15
      • 2021-08-14
      • 1970-01-01
      • 2018-04-14
      相关资源
      最近更新 更多