Reputation: 314
I'm using tensor flow in google colab and I want to save my model on google drive for future use , could anyone guide me on how to do this?
Upvotes: 6
Views: 11761
Reputation: 314
First connect to google drive:
from google.colab import drive
drive.mount('/gdrive')
Next save your model on colab
model.save('modelname')
Edit: We can also specify the path to where the model should be saved (works well for me in google drive path) something like the following. The code also saves the model in h5 format to avoid the warning and the model be reusable to full on load:
model.save('/content/drive/MyDrive/MyFolder/myModel', save_format="h5")
Saved model will now appear in the 'content' folder. Now create the same folder along with the sub folders in the 'gdrive' folder of colab. You can copy the relevant files to these folders using shutil.
import shutil
shutil.copy('source','destination')
You can use 'copy path' option , to get the exact address of the files. Finally to load your model , you have to connect to drive and load the model.
model = tf.keras.models.load_model('modeladdress')
Upvotes: 9