qubvel / segmentation_models

Segmentation models with pretrained backbones. Keras and TensorFlow Keras.
MIT License
4.66k stars 1.03k forks source link

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

Closed Raito03 closed 1 month ago

Raito03 commented 1 month ago

While importing segmentation models im getting this error:

AttributeError                            Traceback (most recent call last)
Cell In[11], line 1
----> 1 from segmentation_models import Unet

File /opt/conda/lib/python3.10/site-packages/segmentation_models/__init__.py:98
     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

File /opt/conda/lib/python3.10/site-packages/segmentation_models/__init__.py:68, 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

File /opt/conda/lib/python3.10/site-packages/efficientnet/keras.py:17
     13 EfficientNetB7 = inject_keras_modules(model.EfficientNetB7)
     15 preprocess_input = inject_keras_modules(model.preprocess_input)
---> 17 init_keras_custom_objects()

File /opt/conda/lib/python3.10/site-packages/efficientnet/__init__.py:71, in init_keras_custom_objects()
     64 from . import model
     66 custom_objects = {
     67     'swish': inject_keras_modules(model.get_swish)(),
     68     'FixedDropout': inject_keras_modules(model.get_dropout)()
     69 }
---> 71 keras.utils.generic_utils.get_custom_objects().update(custom_objects)

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

please let me know how to solve this problem

Raito03 commented 1 month ago

nevermind found this as answer:

import os
os.environ['SM_FRAMEWORK'] = 'tf.keras'

and also from here: here