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

fix load of models with Add and Concat layers #626

Merged

Conversation

freedomtan
Copy link
Contributor

some of models I saved with Model.save() didn't load keras_core.saving.load_model(). e.g., with

import keras_core
import numpy as np

x = keras_core.Input(shape=(10, 3))
y = keras_core.Input(shape=(10, 3))
result = keras_core.layers.Add()([x, y])
model = keras_core.Model([x, y], result)

model.save("model.keras")
loaded_model = keras_core.saving.load_model("model.keras")

I got

Traceback (most recent call last):
  File "/private/tmp/b.py", line 10, in <module>
    loaded_model = keras_core.saving.load_model("model.keras")
  File "/Users/freedom/work/keras-core/keras_core/saving/saving_api.py", line 161, in load_model
    return saving_lib.load_model(
  File "/Users/freedom/work/keras-core/keras_core/saving/saving_lib.py", line 155, in load_model
    model = deserialize_keras_object(
  File "/Users/freedom/work/keras-core/keras_core/saving/serialization_lib.py", line 677, in deserialize_keras_object
    instance = cls.from_config(inner_config)
  File "/Users/freedom/work/keras-core/keras_core/models/model.py", line 484, in from_config
    return cls._from_config(config, custom_objects=custom_objects)
  File "/Users/freedom/work/keras-core/keras_core/models/functional.py", line 492, in _from_config
    process_layer(layer_data)
  File "/Users/freedom/work/keras-core/keras_core/models/functional.py", line 476, in process_layer
    layer = serialization_lib.deserialize_keras_object(
  File "/Users/freedom/work/keras-core/keras_core/saving/serialization_lib.py", line 680, in deserialize_keras_object
    instance.build_from_config(build_config)
  File "/Users/freedom/work/keras-core/keras_core/layers/layer.py", line 377, in build_from_config
    self.build(config["input_shape"])
  File "/Users/freedom/work/keras-core/keras_core/layers/merging/base_merge.py", line 67, in build
    raise ValueError(
ValueError: A merge layer should be called on a list of inputs. Received: input_shape=[[None, 10, 3], [None, 10, 3]] (not a list of shapes)

some of models I saved with Model.save() didn't load
`keras_core.saving.load_model()`
Copy link
Contributor

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fchollet fchollet merged commit 0c6c312 into keras-team:main Jul 27, 2023
@freedomtan freedomtan deleted the fix_model_load_of_add_and_concat_layers branch July 27, 2023 21:59
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

Successfully merging this pull request may close these issues.

2 participants