Search code examples
pythontensorflowkerasdeep-learninggoogle-colaboratory

How to save full tensorflow model from google colab


I trained a computer vision model in google colab.

Now I want to get it to my computer to work with it.
If I do model.save("name.h5") and then download the .h5 file, does this save the trained model?
Or is it just the untrained structure of the model?


Solution

  • Yes, model.save("name.h5") saves the trained model. Of course, you should execute this line after you have trained/fit the model.

    However, model.save() only saves the model structure and the updated weights. And it does not store any loss function weights and information of the loss function. Therefore, you should avoid re-training your model after loading it from the saved file.

    If you are willing to further re-train your model, you should use tf.keras.models.save_model() to save a model, and tf.keras.models.load_model() to load a model. Further information can be found in the Keras documentation.