You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, this issue is observed on Tensorflow version 2.16 (it works as expected on version 2.15 and earlier).
Problem Description:
The following sequence causes a load_model error:
Create a Sequential model, and save it
Load the Sequential model
Convert the sequential model to a functional model
Save the functional model
Load the function model ---> error
Reproducible example
`
code
seq = keras.Sequential(
[
keras.Input(shape=(3,)),
keras.layers.Dense(5),
keras.layers.Softmax(),
],
)
seq.save("keras_model.keras")
# Load sequential model
seq = keras.models.load_model("keras_model.keras")
# Create functional model
func = keras.Model(inputs=seq.inputs, outputs=seq.outputs)
# Save functional model
func.save("functional_model.keras")
# Load functional model
func = keras.models.load_model("functional_model.keras")`
Error output
func = keras.models.load_model("functional_model.keras") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/keras/src/saving/saving_api.py", line 176, in load_model return saving_lib.load_model( ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/keras/src/saving/saving_lib.py", line 155, in load_model model = deserialize_keras_object( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/keras/src/saving/serialization_lib.py", line 711, in deserialize_keras_object instance = cls.from_config(inner_config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/keras/src/models/model.py", line 492, in from_config return functional_from_config( ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/keras/src/models/functional.py", line 522, in functional_from_config process_node(layer, node_data) File "/usr/local/lib/python3.11/dist-packages/keras/src/models/functional.py", line 466, in process_node args, kwargs = deserialize_node(node_data, created_layers) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/keras/src/models/functional.py", line 666, in deserialize_node args = tree.map_structure(convert_revived_tensor, args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/tree/__init__.py", line 435, in map_structure [func(*args) for args in zip(*map(flatten, structures))]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/tree/__init__.py", line 435, in <listcomp> [func(*args) for args in zip(*map(flatten, structures))]) ^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/keras/src/models/functional.py", line 656, in convert_revived_tensor raise ValueError( ValueError: Layer node index out of bounds. inbound_layer = <Dense name=dense, built=True> inbound_layer._inbound_nodes = [<Node operation=<Dense name=dense, built=True>, id=140157363310928>] inbound_node_index = 1
Useful (?) observation
If when I create the functional model i pass all the outputs of the sequential model instead of just model.outputs then I get no errors (however I end up with a model that outputs the result of every layer).
outputs=[layer.output for layer in seq.outputs]
Please note that it doesn't matter whether the models are built/compiled/trained/ we still experience the error as described above.
The text was updated successfully, but these errors were encountered:
Hi, this issue is observed on Tensorflow version 2.16 (it works as expected on version 2.15 and earlier).
Problem Description:
The following sequence causes a load_model error:
Reproducible example
`
code
Error output
func = keras.models.load_model("functional_model.keras") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/keras/src/saving/saving_api.py", line 176, in load_model return saving_lib.load_model( ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/keras/src/saving/saving_lib.py", line 155, in load_model model = deserialize_keras_object( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/keras/src/saving/serialization_lib.py", line 711, in deserialize_keras_object instance = cls.from_config(inner_config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/keras/src/models/model.py", line 492, in from_config return functional_from_config( ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/keras/src/models/functional.py", line 522, in functional_from_config process_node(layer, node_data) File "/usr/local/lib/python3.11/dist-packages/keras/src/models/functional.py", line 466, in process_node args, kwargs = deserialize_node(node_data, created_layers) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/keras/src/models/functional.py", line 666, in deserialize_node args = tree.map_structure(convert_revived_tensor, args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/tree/__init__.py", line 435, in map_structure [func(*args) for args in zip(*map(flatten, structures))]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/tree/__init__.py", line 435, in <listcomp> [func(*args) for args in zip(*map(flatten, structures))]) ^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/keras/src/models/functional.py", line 656, in convert_revived_tensor raise ValueError( ValueError: Layer node index out of bounds. inbound_layer = <Dense name=dense, built=True> inbound_layer._inbound_nodes = [<Node operation=<Dense name=dense, built=True>, id=140157363310928>] inbound_node_index = 1
Useful (?) observation
If when I create the functional model i pass all the outputs of the sequential model instead of just model.outputs then I get no errors (however I end up with a model that outputs the result of every layer).
outputs=[layer.output for layer in seq.outputs]
Please note that it doesn't matter whether the models are built/compiled/trained/ we still experience the error as described above.
The text was updated successfully, but these errors were encountered: