使用分段模型库时出现问题

issue while using segmentation-models library

from tensorflow import keras
from segmentation_models import PSPNet

虽然运行这个,但我面临以下错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-14-fbd9360b4944> in <module>()
      1 
      2 from tensorflow import keras
----> 3 from segmentation_models import PSPNet

3 frames
/usr/local/lib/python3.6/dist-packages/segmentation_models/__init__.py in <module>()
     96 _framework = os.environ.get('SM_FRAMEWORK', _DEFAULT_KERAS_FRAMEWORK)
     97 try:
---> 98     set_framework(_framework)
     99 except ImportError:
    100     other = _TF_KERAS_FRAMEWORK_NAME if _framework == _KERAS_FRAMEWORK_NAME else _KERAS_FRAMEWORK_NAME

/usr/local/lib/python3.6/dist-packages/segmentation_models/__init__.py in set_framework(name)
     66     if name == _KERAS_FRAMEWORK_NAME:
     67         import keras
---> 68         import efficientnet.keras  # init custom objects
     69     elif name == _TF_KERAS_FRAMEWORK_NAME:
     70         from tensorflow import keras

/usr/local/lib/python3.6/dist-packages/efficientnet/keras.py in <module>()
     15 preprocess_input = inject_keras_modules(model.preprocess_input)
     16 
---> 17 init_keras_custom_objects()

/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'

我使用 pip 作为提供的指令安装了分段模型库 (link) 如果有人可以帮助我解决问题,我将不胜感激。我只是简单地从指令中复制代码,我在网上找到的都是一样的。应该是安装有问题吧?

请指导我完成这个!:)

您遇到这个问题是因为您正在使用 Tensorflow version >= 2.2。要解决此问题,您必须使用 Tensorflow 2.1/2.0Tensorflow 1.x (i.e 1.15.2)

请按照以下步骤执行 Image segmentation 使用 Segmentation models 使用 TF 2.1

    !pip install q tensorflow==2.1
    !pip install segmentation-models
    
    import tensorflow as tf
    from segmentation_models import PSPNet
    
    #Instantiate PSPNet model
    model = PSPNet()

    #Display model summary
    model.summary()