Search code examples
pythontensorflowkeras

Tensorflow unable to load model


I trained some models in a docker. I am trying to load the models on my host machine but I am unable to do so.

At first I saved the models as .keras files as mentionned on the documentation. When trying to load the model using tf.keras.models.load_model("model.keras"), I get the following error:

  • OSError: Unable to open file (file signature not found)

I trained the models again and saved them as .h5 files this time, which led to two different errors depending on the model I was trying to load:

  • TypeError: init() got an unexpected keyword argument 'fn'
  • ValueError: The last dimension of the inputs to a Dense layer should be defined. Found None. Full input shape received: (None, None)

I could not find any information on how to fix these errors, I would love some help!


Solution

  • As pointed out by @Dr.Snoopy in the comments, loading the models with the same tensorflow version (here 2.11.0) solves the problem.