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
When loading a model with 2 inputs and 3 sub-models (1 shared between 2 inputs, then 2 separate models to process each output from the shared model),, an IndexError is raised.
The model compiles, trains and saves fine, but the issue comes when trying to load the model back in.
The error occurs with both legacy .h5 format and new .keras format.
fromkerasimportInput, Modelfromkeras.modelsimportload_modelfromkeras.layersimportDensedefshared():
""" Shared model """inputs=Input(shape=(64, ))
outputs=Dense(32)((inputs))
returnModel(inputs, outputs=outputs)
defsplit():
""" Seperate models """inputs=Input(shape=(32, ))
outputs=Dense(32)(inputs)
returnModel(inputs, outputs=outputs)
# Bring them togetherinputs= [Input((64, )), Input((64, ))]
shared_model=shared() # Single instance of the shared modelshared_a=shared_model(inputs[0])
shared_b=shared_model(inputs[1])
out_a=split()(shared_a) # instance 1 of the split modelout_b=split()(shared_b) # instance 2 of the split model# Full modelmodel=Model(inputs, outputs=[out_a, out_b])
print(model.summary())
model.save("test.keras")
test=load_model("test.keras") # Fails with index out of range error
Traceback (most recent call last):
File "/project/model_bug.py", line 34, in <module>
test = load_model("test.keras") # Fails with index out of range error
File "/env/lib/python3.10/site-packages/keras/src/saving/saving_api.py", line 176, in load_model
return saving_lib.load_model(
File "/env/lib/python3.10/site-packages/keras/src/saving/saving_lib.py", line 155, in load_model
model = deserialize_keras_object(
File "/env/lib/python3.10/site-packages/keras/src/saving/serialization_lib.py", line 711, in deserialize_keras_object
instance = cls.from_config(inner_config)
File "/env/lib/python3.10/site-packages/keras/src/models/model.py", line 492, in from_config
return functional_from_config(
File "/env/lib/python3.10/site-packages/keras/src/models/functional.py", line 555, in functional_from_config
output_tensors = map_tensors(config["output_layers"])
File "/env/lib/python3.10/site-packages/keras/src/models/functional.py", line 552, in map_tensors
return [get_tensor(*v) for v in tensors]
File "/env/lib/python3.10/site-packages/keras/src/models/functional.py", line 552, in <listcomp>
return [get_tensor(*v) for v in tensors]
File "/env/lib/python3.10/site-packages/keras/src/models/functional.py", line 545, in get_tensor
layer_output_tensors = layer._inbound_nodes[node_index].output_tensors
IndexError: list index out of range
The text was updated successfully, but these errors were encountered:
Keras Version: 3.0.5 (PyPi latest)
When loading a model with 2 inputs and 3 sub-models (1 shared between 2 inputs, then 2 separate models to process each output from the shared model),, an IndexError is raised.
The model compiles, trains and saves fine, but the issue comes when trying to load the model back in.
The error occurs with both legacy
.h5
format and new.keras
format.This kind of structure works in Keras 2.
Reproducible example (and gist):
Model summary:
Error output:
The text was updated successfully, but these errors were encountered: