首页 > 解决方案 > importefficientnet.keras as efn - AttributeError: module 'keras.utils' has no attribute 'generic_utils'

问题描述

我正在尝试使用来自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'

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

标签: pythonkeraserror-handlingattributeerrorefficientnet

解决方案


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

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

推荐阅读