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

[keras 3.4.1, tf 2.16.2] loading & saving models impossible #172

Open
tobwen opened this issue Jul 11, 2024 · 0 comments
Open

[keras 3.4.1, tf 2.16.2] loading & saving models impossible #172

tobwen opened this issue Jul 11, 2024 · 0 comments

Comments

@tobwen
Copy link

tobwen commented Jul 11, 2024

issues

There are issues with loading and saving models, which are obviously related to deprecated APIs of Tensorflow and Keras.

examples

saving

model.save('test.keras')

This assert pops up and asks me to save as ".keras" (setting a save-format is deprecated).

assert (
not filepath.lower().endswith("h5")
and not filepath.lower().endswith("hdf5")
and not filepath.lower().endswith(".keras")
and (save_format is None or not save_format.lower() == "h5")
), (
"Uncertainty Wizard does not support the deprecated h5 format to save models."
"Change the file ending or the save_format parameter to save using the better tf `SavedModel` format."
)

When removing this, I'm getting

ValueError: The following argument(s) are not supported: ['signatures', 'options']

signatures=signatures,
options=options,

When removing these parameters, saving works... but I can't reload the model (JSON is shortened)

{"module": "keras", "class_name": "Sequential", "config": {"name": "sequential", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null, "shared_object_id": 140376256590384}, "layers": [{"module": "keras.layers", "class_name": "InputLayer", 

loading

Although I'm on tf v2.16.2, Load-Options don't seem to be supported, so neither uwiz.models.load_model() nor StochasticSequential.load_model() nor native models.load_model() work:

path, custom_objects=custom_objects, compile=compile, options=options

Gets me:

Exception encountered: <class 'uncertainty_wizard.models.stochastic_utils.layers.UwizBernoulliDropout'> could not be deserialized properly. Please ensure that components that are Python object instances (layers, models, etc.) returned by `get_config()` are explicitly deserialized in the model's `from_config()` method.

config={'module': 'uncertainty_wizard.models.stochastic_utils.layers', 'class_name': 'UwizBernoulliDropout', 'config': {'name': 'UwBernoulliDropout', 'trainable': True, 'dtype': {'module': 'keras', 'class_name': 'DTypePolicy', 'config': {'name': 'float32'}, 'registered_name': None, 'shared_object_id': 140376256590384}, 'rate': 0.5, 'seed': None, 'noise_shape': None}, 'registered_name': 'Custom>UwizBernoulliDropout', 'build_config': {'input_shape': [None, 24, 24, 64]}}.

Exception encountered: Error when deserializing class 'UwizBernoulliDropout' using config={'name': 'UwBernoulliDropout', 'trainable': True, 'dtype': 'float32', 'rate': 0.5, 'seed': None, 'noise_shape': None}.

Exception encountered: UwizBernoulliDropout.__init__() missing 1 required positional argument: 'stochastic_mode'

Actually, this is lacking stochastic_mode:

# docstr-coverage:inherited
def get_config(self):
config = super(UwizBernoulliDropout, self).get_config()
config["name"] = "UwBernoulliDropout"
return config

Let's try:

    def get_config(self):
        config = super(UwizBernoulliDropout, self).get_config()
        config["name"] = "UwBernoulliDropout"
        config["stochastic_mode"] = self.stochastic_mode # new
        return config

Nope, didn't fix it. Sorry, I'm stuck.

environment

  • keras: v3.4.1
  • tensorflow: v2.16.2
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

1 participant