3

I am training a machine learning model on google's colab. I am using keras with tensorflow backend (python 3.6). I am saving my model using the model.save() function provided by keras. When I call model.save('model_name)` where is the file saved? I cannot find it in my drive anywhere.

Tanmay Bhatnagar
  • 2,330
  • 4
  • 30
  • 50

2 Answers2

6

First, mount your drive:

!mkdir -p drive
!google-drive-ocamlfuse drive

Now, append your path:

import sys
sys.path.append('drive/Project')

You should be able to see your files on your local and web-based drive using:

model.save('drive/Project/myModel.h5')
Oringa
  • 360
  • 2
  • 11
  • fuse: mountpoint is not empty fuse: if you are sure this is safe, use the 'nonempty' mount option. How do I empty the mountpoint? – Tanmay Bhatnagar Apr 22 '18 at 16:56
  • Maybe this could be of use: https://stackoverflow.com/questions/20271101/what-happens-if-you-mount-to-a-non-empty-mount-point-with-fuse – Oringa Apr 22 '18 at 17:02
  • Gave authorisation and mounted my drive. I am getting this error : Unable to create file (unable to open file: name = 'DL/Project/gen0.h5', errno = 2, error message = 'No such file or directory', flags = 13, o_flags = 242) – Tanmay Bhatnagar Apr 22 '18 at 17:31
  • from google.colab import drive drive.mount('/content/drive') – Sung Apr 28 '20 at 02:40
2

Even though it is a bit late, I was also struggling with the same question.Then i found out mounting the drive in colab and then providing the drive path,the files will get stored in the google drive

from google.colab import drive
drive.mount('/content/gdrive')
#using model.save_weights() to save the weights of the model in HDF5 format
model.save_weights("/content/gdrive/My Drive/weights.h5")

The file is saved in the drive with name "weights.h5"

mrinali
  • 140
  • 10