When loading a keras model from an hdf5 file the axis
parameter is dropped from the model config.
The code at https://github.com/keras-team/keras/blob/6c3dd68c1b2e7783d15244279959e89fe88ee346/ pops the param from the config and only puts it back if it's a list which AFAIK it never is.
Script to reproduce the issue:
from tensorflow.keras.layers import Input, Dense, Concatenate
from tensorflow.keras.models import Model
from keras.src.legacy.saving import legacy_h5_format
input1 = Input(shape=(1,4), name='input1')
input2 = Input(shape=(1,4), name='input2')
input3 = Input(shape=(2,4), name='input3')
concat1 = Concatenate(axis=1)([input1, input2])
concat2 = Concatenate(axis=-1)([concat1, input3])
output = Dense(1, activation='sigmoid')(concat2)
model = Model(inputs=[input1, input2], outputs=output)
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
legacy_h5_format.save_model_to_hdf5(model, "cat_test.h5")
legacy_h5_format.load_model_from_hdf5("cat_test.h5")
Running this script results in load_model_from_hdf5
failing with an error ValueError: A
Concatenatelayer requires inputs with matching shapes except for the concatenation axis. Received: input_shape=[(None, 1, 8), (None, 2, 4)] concatenate_1