Can't load model with tf v2.14 if the model was saved with previous tf versions
Hi **@ofirgo**,
Could you please check with the latest stable version. I checked with versions Tf=2.13, 2.14 and tf-nightly too. It is working fine for me for both the models. It is recommended to save and load the models in the same TF version which will not conflict in the outcome. I attached a [gist ](https://colab.research.google.com/gist/Venkat6871/ec236a020b77af3f13e5bffb43348869/62363_2-13-2-14-nightly.ipynb)for your reference.

Thank you! Hi @Venkat6871, 
Thank you for your response.

Saving and loading with the same TF version works fine for me (in all 3 aforementioned versions).

My issue is when trying to load with TF 2.14 a model that was originally saved in TF 2.13 (I have a large database of saved models that I wish to not be needing to recreate when upgrading a TF version).

Is there a way to solve this issue to preserve backward compatibility? Have you tried "fitting" this model instead of loading previous weights?

I ask this because I get input_shape errors on fit() even though they are correctly specified in a keras.layer. I can "build" the model and display its summary(). However, when I use fit(), whether designed through subclassing or functional API, the model seems to _forget_ that I specified input_shape.

I don't get this issue when I downgrade TF to v2.12.0 (i.e. the last time I ran it).

I wonder if this is related???

Of note, I've been running this in Colab, if that's of any importance. Hi @ofirgo ,

The issue addressed in Keras #[18830](https://github.com/keras-team/keras/issues/18830) already. Could you please close the issue if resolved.If not please track it at keras repo itself. Thanks! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62363">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62363">No</a>

### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

binary

### TensorFlow version

tf 2.14

### Custom code

Yes

### OS platform and distribution

_No response_

### Mobile device

_No response_

### Python version

3.10

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

Trying to load a Keras model that was saved using tf version < 2.14 (e.g., 2.13), with tf 2.14, gives the following error:

> File "/data/projects/swat/envs/eladc/mct_tf_python310/lib/python3.10/site-packages/keras/src/saving/saving_api.py", line 254, in load_model
    return saving_lib.load_model(
  File "/data/projects/swat/envs/eladc/mct_tf_python310/lib/python3.10/site-packages/keras/src/saving/saving_lib.py", line 281, in load_model
    raise e
  File "/data/projects/swat/envs/eladc/mct_tf_python310/lib/python3.10/site-packages/keras/src/saving/saving_lib.py", line 269, in load_model
    _load_state(
  File "/data/projects/swat/envs/eladc/mct_tf_python310/lib/python3.10/site-packages/keras/src/saving/saving_lib.py", line 466, in _load_state
    _load_container_state(
  File "/data/projects/swat/envs/eladc/mct_tf_python310/lib/python3.10/site-packages/keras/src/saving/saving_lib.py", line 534, in _load_container_state
    _load_state(
  File "/data/projects/swat/envs/eladc/mct_tf_python310/lib/python3.10/site-packages/keras/src/saving/saving_lib.py", line 435, in _load_state
    trackable.load_own_variables(weights_store.get(inner_path))
  File "/data/projects/swat/envs/eladc/mct_tf_python310/lib/python3.10/site-packages/keras/src/engine/base_layer.py", line 3531, in load_own_variables
    raise ValueError(
ValueError: Layer 'conv2d_1' expected 2 variables, but received 0 variables during loading. Expected: ['conv2d_1/kernel:0', 'conv2d_1/bias:0']

Trying to load the same model with tf-nightly gives a different error:

> TypeError: Could not deserialize class 'Functional' because its parent module keras.src.engine.functional cannot be imported. Full object config: {'module': 'keras.src.engine.functional', 'class_name': 'Functional', 'config': {'name': 'tf213', 'trainable': True, 'layers': [{'module': 'keras.layers', 'class_name': 'InputLayer', 'config': {'batch_input_shape': [None, 8, 8, 3], 'dtype': 'float32', 'sparse': False, 'ragged': False, 'name': 'input_1'}, 'registered_name': None, 'name': 'input_1', 'inbound_nodes': []}, {'module': 'keras.layers', 'class_name': 'Conv2D', 'config': {'name': 'conv2d', 'trainable': True, 'dtype': 'float32', 'filters': 3, 'kernel_size': [3, 3], 'strides': [1, 1], 'padding': 'valid', 'data_format': 'channels_last', 'dilation_rate': [1, 1], 'groups': 1, 'activation': 'linear', 'use_bias': True, 'kernel_initializer': {'module': 'keras.initializers', 'class_name': 'GlorotUniform', 'config': {'seed': None}, 'registered_name': None}, 'bias_initializer': {'module': 'keras.initializers', 'class_name': 'Zeros', 'config': {}, 'registered_name': None}, 'kernel_regularizer': None, 'bias_regularizer': None, 'activity_regularizer': None, 'kernel_constraint': None, 'bias_constraint': None}, 'registered_name': None, 'build_config': {'input_shape': [None, 8, 8, 3]}, 'name': 'conv2d', 'inbound_nodes': [[['input_1', 0, 0, {}]]]}, {'module': 'keras.layers', 'class_name': 'Conv2D', 'config': {'name': 'conv2d_1', 'trainable': True, 'dtype': 'float32', 'filters': 3, 'kernel_size': [3, 3], 'strides': [1, 1], 'padding': 'valid', 'data_format': 'channels_last', 'dilation_rate': [1, 1], 'groups': 1, 'activation': 'linear', 'use_bias': True, 'kernel_initializer': {'module': 'keras.initializers', 'class_name': 'GlorotUniform', 'config': {'seed': None}, 'registered_name': None}, 'bias_initializer': {'module': 'keras.initializers', 'class_name': 'Zeros', 'config': {}, 'registered_name': None}, 'kernel_regularizer': None, 'bias_regularizer': None, 'activity_regularizer': None, 'kernel_constraint': None, 'bias_constraint': None}, 'registered_name': None, 'build_config': {'input_shape': [None, 6, 6, 3]}, 'name': 'conv2d_1', 'inbound_nodes': [[['conv2d', 0, 0, {}]]]}], 'input_layers': [['input_1', 0, 0]], 'output_layers': [['conv2d_1', 0, 0]]}, 'registered_name': 'Functional', 'build_config': {'input_shape': [None, 8, 8, 3]}}

The issue is also reproduced when saving and loading models (MobileNetV2) from keras.applications.

This only happens if the model has at least two layers of the same type.

### Standalone code to reproduce the issue

```shell
Run this code with tf v2.13:
`
import tensorflow as tf


_in = tf.keras.layers.Input(shape=(8, 8, 3))
x = _in
x = tf.keras.layers.Conv2D(3, 3)(x)
x = tf.keras.layers.Conv2D(3, 3)(x)
_out = x
model = tf.keras.Model(inputs=_in, outputs=_out)

model.save('model_213.keras')
`

Run this code with tf v2.14:
`
loaded_model = tf.keras.models.load_model('model_213.keras')
`
```


### Relevant log output

_No response_