Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module 'keras.utils.generic_utils' has no attribute 'get_custom_objects' #559

Open
usher233 opened this issue Feb 10, 2023 · 9 comments
Open

Comments

@usher233
Copy link

A few days ago, I can still use it however today when I import segmentation_models this happened. I wander how can I fix this?

@rodiegeology
Copy link

The same to me:

/usr/local/lib/python3.8/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.generic_utils' has no attribute 'get_custom_objects'"

@ryuuzaki42
Copy link

Keras version 2.11.0?
Google Colab?

  • Downgrade keras to 2.10.0 and restart the environment
!pip install keras==2.10.0
import keras
print(keras.__version__)
  • Or downgrade tensorflow like to 2.6.4 and restart the environment
!pip install tensorflow==2.6.4
import tensorflow as tf
print(tf.__version__)

@tonyboston-au
Copy link

tonyboston-au commented Feb 12, 2023

!pip install tensorflow==2.9.0 also works - thanks

@rodiegeology
Copy link

It worked! Thanks!

@JPasterkampRotec
Copy link

JPasterkampRotec commented Feb 21, 2023

Installing an older TF/Keras version is just a workaround.
Can we get segmentation models to support TF 2.11?

@lucaslcode
Copy link

I am using tensorflow 2.12 and got this to work by setting the env variable SM_FRAMEWORK="tf.keras"

@hrootscraft
Copy link

hrootscraft commented Mar 28, 2023

I am using tensorflow 2.12 and got this to work by setting the env variable SM_FRAMEWORK="tf.keras"

Thanks for this @lucaslcode ! Was having trouble deploying an image segmentation model on hugging faces. I'd like to add to this. When I ran the code in Google Colab, I replaced all the instances of 'init_keras_custom_objects' in keras.py with 'init_tfkeras_custom_objects' and got it running on there and used tensorflow 2.11.0

# Open the file in write mode
with open('/usr/local/lib/python3.9/dist-packages/efficientnet/keras.py', 'r') as f:
    # Read the contents of the file
    contents = f.read()

# Replace the string
new_contents = contents.replace('init_keras_custom_objects', 'init_tfkeras_custom_objects')

# Open the file in write mode again and write the modified contents
with open('/usr/local/lib/python3.9/dist-packages/efficientnet/keras.py', 'w') as f:
    f.write(new_contents)

@ehsanro
Copy link

ehsanro commented May 24, 2023

Hi
just import this line
os.environ["SM_FRAMEWORK"] = "tf.keras"

@JPasterkampRotec
Copy link

Hi just import this line os.environ["SM_FRAMEWORK"] = "tf.keras"

Thank you, that is my current solution.
However it would be better if segmentation models would support the newest TF versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants