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.
Aditya Nikhil
Updated on June 11, 2022Comments
-
Aditya Nikhil almost 2 years
I'd like to load a keras model that i've trained and saved it as .pb.
Here's the code,
Am using a jupyter notebook.
The model is successfully saved as saved_model.pb under the same directory. But the code is unable to access it.
Can anybody see to it, how can i access this keras model that's saved in .pb extension.
I checked at several other places for solution but no luck.
Model is saved at model/saved_model.pb.
I've taken out the .pb file and placed it in the same directory where my code file exists. -
Aditya Nikhil over 3 yearsOh okay it works, now how to access the model, i mean, if i type model.summary(), it's not showing anything.
-
sakumoil over 3 yearsWhat if you load the model with
tf.keras.models.load_model('model')
and runmodel.summary()
after that?