Google colaboratory, Keras : Save model in HDF5 file format and download it to Laptop

google-colaboratoryh5pyhdf5keras

I am training small RNN model in Google Collab using GPU.I usually save my model and weights in HDF5 file format.

In local machine(laptop), I do it in following procedure

sudo pip install h5py
model.fit(....)
model.save('model1.h5')

I load back trained model to make prediction using,

from keras.models import load_model
model = load_model('model1.h5')

I now want to

  1. save model in Google Collab, similar format as in above
  2. download .h5 file to local machine(PC)
  3. make predictions in PC and train it in PC
  4. save trained model, load .h5 file back to google collab
  5. resume training in Google collab

Best Answer

A bit late but, for the sake of upcoming developers I'll try to solve the question.

The procedure is the same as in your local computer, with just two differences:

To download the model from Google Collab:

from google.colab import files
files.download("model1.h5")

To upload the model to Google Collab:

from google.colab import files
files.upload()

You can check this notebook for more i/o options: https://colab.research.google.com/notebooks/io.ipynb

All the other steps are performed the same way yo do in your local computer. Hope this can help you.

Related Topic