【问题标题】:Tensorflow 2.0: Cannot Import tf.keras.utils.conv_utilsTensorflow 2.0:无法导入 tf.keras.utils.conv_utils
【发布时间】:2020-07-18 21:16:45
【问题描述】:

我正在使用从源代码编译的 Tensorflow v2.1.0。如何从conv_utils 模块导入任何函数?例如。 convert_data_format()conv_output_length()normalize_tuple()

我想创建自己的卷积/池化层。当我想从 import keras 迁移到 from tensorflow import keras 时,“一切”看起来几乎不同。

这就是我所做的

> python -c "from tensorflow.keras.utils import conv_utils"                          
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'conv_utils' from 'tensorflow.keras.utils' ...

谢谢。

【问题讨论】:

  • 您应该考虑接受答案!第二个答案虽然投票较少,但更新较多。
  • 当我有机会时可能会测试它。当时并没有解决我的问题。如果有人可以为我确认解决方案,我会立即接受。因此,人们可以从中受益。

标签: python keras tensorflow2.0


【解决方案1】:

试试这个:

from tensorflow.python.keras.utils import conv_utils

【讨论】:

  • 我很高兴知道您对我的问题感兴趣......但我很抱歉说我以前做过。奇怪的是我只能在 python 交互式 shell 中以这种方式导入它,但是如果我运行我的 .py 文件,则会收到错误 AttributeError: module 'tensorflow' has no attribute 'python'。那你知道问题出在哪里吗?
  • 看看下面的答案。新方法是import tensorflow.keras.utils as conv_utils
【解决方案2】:

这是在 Tensorflow 2.1.0 中导入 conv_utils 的新方法:

import tensorflow.keras.utils as conv_utils

【讨论】:

  • 对不起,但是这种方式给了我AttributeError: module 'tensorflow_core.keras.utils' has no attribute 'conv_output_length'
猜你喜欢
  • 2020-01-30
  • 1970-01-01
  • 1970-01-01
  • 2019-05-17
  • 2018-06-12
  • 2019-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多