【问题标题】:import efficientnet.keras as efn - AttributeError: module 'keras.utils' has no attribute 'generic_utils'importefficientnet.keras as efn - AttributeError: module 'keras.utils' has no attribute 'generic_utils'
【发布时间】:2020-11-23 20:26:54
【问题描述】:

我正在尝试使用来自https://github.com/qubvel/segmentation_models 的 EfficientNet。

所以,我通过 pip 安装了这个:

!pip install git+https://github.com/qubvel/segmentation_models

然后我尝试导入efficientnet.keras

import efficientnet.keras as efn

得到了这个错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-57-61d736540c72> in <module>()
----> 1 import efficientnet.keras as efn

1 frames
/usr/local/lib/python3.6/dist-packages/efficientnet/__init__.py in init_keras_custom_objects()
     69     }
     70 
---> 71     keras.utils.generic_utils.get_custom_objects().update(custom_objects)
     72 
     73 

AttributeError: module 'keras.utils' has no attribute 'generic_utils'

这很奇怪,因为它昨天工作没有任何问题,今天在一个笔记本上也是如此,但在其他笔记本上我得到了这个错误。有谁知道该怎么做?

【问题讨论】:

    标签: python keras error-handling attributeerror efficientnet


    【解决方案1】:
    !pip install tensorflow==2.1.0
    !pip install keras==2.3.1
    !pip install segmentation-models
    

    试试这个,它在谷歌 colab 上对我有用

    【讨论】:

      【解决方案2】:

      您仍然可以将 tensorflow 2.4.1 与分段模型 v. 1.0.1 一起使用。

      get_custom_objects() 已从 keras.utils.generic_utils 移至 keras.utils

      你可以:

      keras.utils.generic_utils = keras.utils
      

      只有在那之后你才能导入segmentation models

      这不是 100% 安全的解决方案,但在我的情况下它可以完美运行。

      【讨论】:

        【解决方案3】:

        在我看来,您使用的是 Colab,他们今天可能升级了一些软件包,所以我们遇到了同样的错误。我通过以下方式将 Keras 和 Tenserflow 包降级到以前的包(我只猜到了版本号)解决了这个问题:

        !pip install q tensorflow==2.1
        !pip install q keras==2.3.1
        

        【讨论】:

          猜你喜欢
          • 2022-12-01
          • 1970-01-01
          • 2022-08-04
          • 2018-11-16
          • 2015-09-26
          • 2022-08-24
          • 2019-06-25
          • 2014-12-20
          • 2021-12-12
          相关资源
          最近更新 更多