AttributeError: module '没有属性'depth_to_space'<



我正在尝试运行一个代码,这是用tensorflow版本1.4.0编写的我在谷歌colab上运行我的代码,它给出了tensorflow版本2。

要运行我的代码,我使用向后兼容性如下:

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

在某些情况下是有效的,但在某种程度上,它会导致这个错误

AttributeError: module 'tensorflow. pat.v2'没有属性'depth_to_space'

如你所见,

我无法理解的是这个方法'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

请帮助我了解这个错误的原因。

谢谢,Pranay

我尝试使用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)

最新更新