omarmnbm
omarmnbm

Reputation: 41

How can I fix the problem of loading the model to get new predictions?

I trained a model and save it as import os model.save('') , I want to use my model to make prediction on new test set so I load it by model = tf.keras.models.load_model('') .. it shows me this waring (WARNING:tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), NOT tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.)

The problem is now when I make prediction , it gives me inaccurate results.. it seems as the same prediction of the training/testing set not for the new one

Also , I notice that the tensoerflow type is 2.6 but when I saved the model it was 2.5 .. is this a problem ? Please I need a help as soon as possible.

Upvotes: 4

Views: 5557

Answers (1)

user11530462
user11530462

Reputation:

This warning was added to encourage users to save keras models using model.save instead of tf.saved_model.save.

Saving keras models with tf.saved_model.save saves only base level data (like the graphdef / checkpoint) where as model.save saves the layer configs / trainable status / name / other python attributes along with graphdef / checkpoint.

This warning will not affect the model training or inference. I have used a simple mnist model to demonstrate that the warning is not going to affect the trained model. I have trained this mnist model with TF2.5 and loaded with tf-nightly. After loading the model, I retrained the model and noticed there was no loss in the performance of the model.

For reference, Here is a gist with mnist model that I mentioned above.

Upvotes: 3

Related Questions