Nested outputs are not supported in Keras 3, but are in Keras 2. There is currently no code to support loading models with this structure in Keras 3, so the loading process errors out (see PR for more details).
The PR looks to address this, however in order to be able to test this fix, a model generated in Keras 2 needs to be used to ensure that the fix works as expected.
The attached model, with deliberately overly nested outputs, is built with the following definition in Keras 2 (gist):
from keras import Input, Model
from keras.models import load_model
from keras.layers import Dense
inputs = Input((2, ))
dense1 = Dense(2, name="dense1")(inputs)
dense2 = Dense(2, name="dense2")(dense1)
dense3 = Dense(2, name="dense3")(dense2)
dense4 = Dense(2, name="dense4")(dense3)
dense5 = Dense(2, name="dense5")(dense4)
model = Model(inputs, outputs = [[dense1, [dense2], [dense3, dense4]], dense5])
print(model.summary())
model.save("keras2_nested_outputs.h5")
This issue relates to #19669
Nested outputs are not supported in Keras 3, but are in Keras 2. There is currently no code to support loading models with this structure in Keras 3, so the loading process errors out (see PR for more details).
The PR looks to address this, however in order to be able to test this fix, a model generated in Keras 2 needs to be used to ensure that the fix works as expected.
The attached model, with deliberately overly nested outputs, is built with the following definition in Keras 2 (gist):
*Note, this model will not build in Keras 3
keras2_nested_outputs.zip
The following gist will load this saved model into Keras 3, then error when processing the model outputs: