Search code examples
pythontensorflowkerasgoogle-colaboratory

How to load TensorFlow Keras model from a saved checkpoint in Colaboratory?


I've built and trained an RNN model in Colaboratory, and saved it using the checkpoint callback:

tf.keras.callbacks.ModelCheckpoint( filepath=chkpt_p, save_weights_only=False)

And the saved data looks like this:

enter image description here

If I understand correctly, this directory includes both the model and the weights. Which function should I use to restore it (in another runtime)?


Solution

  • This worked for me:

    model = tf.keras.models.load_model(save_dir,compile=False)
    

    I had one issue with using tf.saved_model.load, which doesn't produce a keras object, and one TF not finding the loss function with compile=True.