python - AttributeError:模块“tensorflow.compat.v2”没有属性“depth_to_space”
问题描述
我正在尝试运行一个使用 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”
我无法理解的是这种方法 '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
请帮助我了解导致此错误的原因。
谢谢, 普拉内
解决方案
我尝试使用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)
推荐阅读
- .net-core - 如何编写可以从 appsettings.json 查找值的自定义 NLog 目标
- c++ - 尝试使用 OpenCV 从图像写入图像时出现 CL_INVALID_KERNEL_ARGS
- c# - Braintree - 在 Xamarin 表单 C# 中检索付款方式 Nonce
- c# - 在 azure blob 存储中上传文件
- java - Java 休息 API | Linux | HTTPS 443 连接被拒绝 | 代码在本地工作正常,但在服务器上不工作 | Ping 返回正常
- javascript - expressjs http post 无法从 javascript post fetch 获取数据
- python - Python POST 请求设置格式
- javascript - 如何在 Blogger 博客主页中制作条纹帖子背景颜色?
- php - 如何在 PHP 7.4 (xampp 3.2.2) 中安装扩展?
- delphi - 使用 Delphi 10.2 实施 ADFS SSO