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

MCDropout incompatibility with latest versions of Tensorflow #26

Open
igomezv opened this issue Apr 16, 2024 · 1 comment
Open

MCDropout incompatibility with latest versions of Tensorflow #26

igomezv opened this issue Apr 16, 2024 · 1 comment

Comments

@igomezv
Copy link

igomezv commented Apr 16, 2024

Your MCDropout layers (or variants) work very well when designing a tensorflow.keras model, for example:

x = Dense(100, activation='relu', input_shape=(n_input,))(input_z)
x = MCDropout(0.2)(x)
x = Dense(100, activation='relu')(x)
x = MCDropout(0.2)(x)

Now it still works fine during training, but the problem is when I want to load a model previously saved in an h5 file via something like tf.keras.models.save_model(neural_model, 'mymodel.h5' ). For earlier versions of Tensorflow, the following worked:

model = tf.keras.models.load_model('mymodel.h5', custom_objects={'MCDropout': MCDropout})

However, the newer versions of tensorflow do not work, and the following error is thrown:


deserialize_keras_object
obj = module_objects.get(object_name)
AttributeError: 'NoneType' object has no attribute 'get'


I think maybe using MCDropout after training, might work better, or redefine the method according to the new tensorflow version.

@igomezv igomezv changed the title MCDrropout incompatibility for latest Tensorflow versions MCDropout incompatibility with latest versions of Tensorflow Apr 16, 2024
@henrysky
Copy link
Owner

I need a few more information:

  • Latest version of Tensorflow, are you referring to Tensorflow 2.16.x or 2.15.x?
  • Did you import Dense from tensorflow.keras or Keras directly?
  • If you are using Keras too, which version are you using?

Tensorflow is separating Keras (they use to be separate packages long time ago but then merged Keras under Tensorflow but now separating again...) and Keras 3.x are causing various issues for me too.

There is a git branch I've created to fix some of those issues at https://github.com/henrysky/astroNN/tree/keras3_torch. You might want to try to see if it fixes your issue. But this is an ongoing issue so I am waiting a bit to see how the situation is evolving on the Tensorflow/Keras 3.0 side.

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

2 participants