简体   繁体   English

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

[英]AttributeError: module 'tensorflow.compat.v2' has no attribute 'depth_to_space'

I am trying to run a code, which was written with tensorflow version 1.4.0 I am running my code on google colab which gives in tensorflow version 2.x with it.我正在尝试运行一个代码,它是用 tensorflow 版本 1.4.0 编写的我在 google colab 上运行我的代码,它给出了 tensorflow 版本 2.x。

To run my code, I am using backward compatibility like: replacing import tensorflow as tf with为了运行我的代码,我使用了向后兼容性,例如:将import tensorflow as tf替换为

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

which works for certain things, but at a point it comes down to this error它适用于某些事情,但在某种程度上它归结为这个错误

AttributeError: module 'tensorflow.compat.v2' has no attribute 'depth_to_space' AttributeError:模块“tensorflow.compat.v2”没有属性“depth_to_space”

as you can see in this image正如你在这张图片中看到的

What I am not able to understand is this method 'depth_to_space' is in both versions of tensorflow 1.x and 2.x, then why is my version of tensorflow not getting it?我无法理解的是这个方法 'depth_to_space' 在 tensorflow 1.x 和 2.x 的两个版本中都有,那么为什么我的 tensorflow 版本没有得到它? Here's the link to the method in version 1.x: https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/depth_to_space这是 1.x 版方法的链接: https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/depth_to_space

Please help me understand what's the cause of this error.请帮助我了解此错误的原因。

Thanks, Pranay谢谢,普拉奈

I tried with Tensorflow 1.15 .Its working fine.我试过Tensorflow 1.15 。它工作正常。 Looks like your Tensorflow version bit old,看起来你的 Tensorflow 版本有点旧,

Below sample code tested with Tf 1.15 without any error.下面的示例代码使用 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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:模块 'tensorflow.compat.v2' 没有属性 'logging' - AttributeError: module 'tensorflow.compat.v2' has no attribute 'logging' 属性 AttributeError:模块“tensorflow.compat.v2”没有属性“_internal_” - Attribute AttributeError: module 'tensorflow.compat.v2' has no attribute '_internal_' AttributeError: 模块 'tensorflow.compat.v2.__internal__' 没有属性 'dispatch' - AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'dispatch' AttributeError: 模块“tensorflow_core.compat.v1”没有属性“contrib” - AttributeError: module 'tensorflow_core.compat.v1' has no attribute 'contrib' AttributeError:加载 tf.compat.v1.train.SessionRunHook 时模块“tensorflow”没有属性“compat” - AttributeError: module 'tensorflow' has no attribute 'compat' when loading tf.compat.v1.train.SessionRunHook Mask RCNN:没有名为“tensorflow.compat.v2”的模块 - Mask RCNN: No module named 'tensorflow.compat.v2' AttributeError: 模块“tensorflow._api.v1.compat”没有用于 Tensorflow 对象检测 API 的属性“v2” - AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v2' For Tensorflow Object Detection API AttributeError: 模块 'tensorflow.compat' 没有属性 'v1' Tensorflow v: 1.10.0 - AttributeError: module 'tensorflow.compat' has no attribute 'v1' Tensorflow v: 1.10.0 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