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

See original GitHub issue

Hi,

I’m trying to run multiclass segmentation (camvid).ipynb example and get an error after running the following block:

import segmentation_models as sm

Here is the error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-28-93aee672c619> in <module>
----> 1 import segmentation_models as sm
      2 
      3 # segmentation_models could also use `tf.keras` if you do not have Keras installed
      4 # or you could switch to other framework using `sm.set_framework('tf.keras')`

E:\PycharmProjects\Autometrics\Spattering_segmentation\segmentation_models\__init__.py in <module>
----> 1 from .segmentation_models import *

E:\PycharmProjects\Autometrics\Spattering_segmentation\segmentation_models\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

E:\PycharmProjects\Autometrics\Spattering_segmentation\segmentation_models\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

~\AppData\Roaming\Python\Python37\site-packages\efficientnet\keras.py in <module>
     15 preprocess_input = inject_keras_modules(model.preprocess_input)
     16 
---> 17 init_keras_custom_objects()

~\AppData\Roaming\Python\Python37\site-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'

Can anyone help me to solve this?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:34 (1 by maintainers)

github_iconTop GitHub Comments

88reactions
sezazqureshicommented, Aug 12, 2020

%env SM_FRAMEWORK=tf.keras

try this before importing segmentation models , it solved my problem.

33reactions
AbtinDjavadifarcommented, Jul 22, 2020

same here

  File "/home/nvidia/pellame-g4f/lam/backend/lambackend/services/analysis_svc.py", line 6, in <module>
    import segmentation_models as sm
  File "/home/nvidia/virtualenvs/venv_lam/lib/python3.6/site-packages/segmentation_models/__init__.py", line 98, in <module>
    set_framework(_framework)
  File "/home/nvidia/virtualenvs/venv_lam/lib/python3.6/site-packages/segmentation_models/__init__.py", line 68, in set_framework
    import efficientnet.keras  # init custom objects
  File "/home/nvidia/virtualenvs/venv_lam/lib/python3.6/site-packages/efficientnet/keras.py", line 17, in <module>
    init_keras_custom_objects()
  File "/home/nvidia/virtualenvs/venv_lam/lib/python3.6/site-packages/efficientnet/__init__.py", line 71, in init_keras_custom_objects
    keras.utils.generic_utils.get_custom_objects().update(custom_objects)
AttributeError: module 'keras.utils' has no attribute 'generic_utils'

Installed versions (inside a v.env. on Jetson TX2):

  • Keras 2.4.3
  • Keras-Applications 1.0.8
  • segmentation-models 1.0.1
  • tensorflow 2.2.0+nv20.6

I changed keras.utils.generic_utils.get_custom_objects().update(custom_objects) to keras.utils.get_custom_objects().update(custom_objects) in .../lib/python3.6/site-packages/efficientnet/__init__.py and it solved the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

module 'tensorflow.python.keras.utils.generic_utils' has no ...
I encountered the same problem using Python 3.9 and Tensorflow 2.5. The problem for me was that those two are not yet compatible,...
Read more >
[PY 4] module 'keras.utils.generic_utils' has no attribute ...
Remove the errors: AttributeError: module ' keras. utils. generic_utils ' has no attribute 'populate_dict_with_module_objects'Replace from ...
Read more >
Module: tf.keras.utils | TensorFlow v2.11.0
class CustomObjectScope : Exposes custom classes/functions to Keras deserialization internals. class GeneratorEnqueuer : Builds a queue out ...
Read more >
I'm getting this error in Python AttributeError: module 'keras. ...
I'm getting this error in Python. AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'. Please help.
Read more >
解决AttributeError: module 'keras.utils.generic_utils' has no ...
问题:使用keras 2.2.4和tensorflow2.5组合时,import keras出现错误AttributeError: module 'keras.utils.generic_utils' has no attribute ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found