【问题标题】:ImportError: cannot import name 'convert_kernel' from partially initialized module 'keras.utils.conv_utils'ImportError:无法从部分初始化的模块“keras.utils.conv_utils”导入名称“convert_kernel”
【发布时间】:2021-05-28 15:23:06
【问题描述】:

所以,我用许多包编写了 python ML 代码,其中一些是 tensorflow、keras 和类似的东西。该代码没有任何问题,它正在运行,直到 2 天前解释器显示此错误:

ImportError: cannot import name 'convert_kernel' from partially initialized module 'keras.utils.conv_utils' (most likely due to a circular import) (/home/UbuntuUser/.local/lib/python3.8/site-packages/keras/utils/conv_utils.py)

我从昨天开始就在尝试修复它。我找到了这个建议的解决方案: AttributeError: keras.backend ,no attribute 'eager' 但这没有任何区别。还是同样的错误。我将 tensorflow 更新到 2.2 -> 什么都没有,我安装了 2.2.5 之前的以前的 Keras 版本,正如我从上面的链接 + tensorflow 2.0 -> 没有...

这也对我不起作用:ImportError: cannot import name 'convert_kernel'

我不知道如何解决它。我正在搜索 google、github、stackoverflow 链接以找到解决方案,但没有任何成功。我无法理解这是怎么发生的,我的意思是我是怎么得到这个错误的,因为我的程序运行没有任何问题,而且我最近没有进行任何更新。

我还将keras 更改为tensorflow.keras 命令(正如这篇文章所建议的那样:How to fix ' module 'keras.backend.tensorflow_backend' has no attribute '_is_tf_1''),我得到了类似的东西:

ImportError: cannot import name 'constant' from partially initialized module 'tensorflow.python.framework.constant_op' (most likely due to a circular import) (/home/UbuntuUser/.local/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py)

我还更改了文件名,正如这篇文章所暗示的:ImportError: cannot import name '...' from partially initialized module '...' (most likely due to a circular import) 没有任何改进。类似的错误。

我正在使用最新的 Kubuntu 20.04.2 LTS 操作系统。有没有人遇到过类似的情况以及他是如何解决的?

【问题讨论】:

  • 好的,我明白了一些事情,但是在这种情况下我会做什么:“从 PyQt5 导入 Qt 作为 qt”。我相信我不能只写:“import Qt”或“import PyQt5”

标签: python tensorflow


【解决方案1】:

要使用 Keras 的 convert_kernel 函数,请使用带有以下导入语句的 Tensorflow 2.3

from tensorflow.compat.v1.keras.utils import convert_all_kernels_in_model

由于 tf.compat.v1.keras.utils.convert_all_kernels_in_model 在 2020-06-23 之后被弃用,请使用 Tf 2.3。

【讨论】:

    猜你喜欢
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-27
    • 2019-04-26
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多