How to load a keras model saved as .pb

Written by- Aionlinecourse2477 times views

How to load a keras model saved as .pb

To load the saved model, you will need to define a function that loads the model and returns it.

How to load a keras model saved as .pb

Solution 1:

The function tf.keras.models.load_model load a SavedModel into a tf.keras -model. The argument of the function is path to a saved model.

So try model = tf.keras.models.load_model('model')

Solution 2:

You should load all model folder instead of loading .pb file. If you save model to './_models/vgg50_finetune' (I used this path in my project), you get folder vgg50_finetune with two .pb files (keras_metadata.pb and saved_model.pb) and two subfolders (assets and variables). The only thing you should do is use this code: model = tf.keras.models.load_model('./_models/vgg50_finetune') And you can both train model or use it for prediction.

Thank you for reading the article.