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.
SavedModel is the more comprehensive save format that saves the model architecture, weights, and the traced Tensorflow subgraphs of the call functions. This enables Keras to restore both built-in layers as well as custom objects. # Create a simple model. # Train the model. # Calling `save ('my_model')` creates a SavedModel folder `my_model`.
The network weights are written to model.h5 in the local directory. The model and weight data is loaded from the saved files and a new model is created. It is important to compile the loaded model before it is used. This is so that predictions made using the model can use the appropriate efficient computation from the Keras backend.
Last Updated on August 27, 2020 Keras is a simple and powerful Python library for deep learning. Given that deep learning models can take hours, days and even weeks to train, it is important to know how to save and load them from disk.
I am using an LSTM Keras model with 2 outputs (i.e predictions) for Slot and Intent filling. When I save, then load it (in json, yaml and single file format) , it provides random results. It seems like if the model does not fit well the loaded weights: The model has 84% of accuracy before saving, 20% after loading.
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')
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With