When I use Google Colaboratory, how to save image, weights in my Google Drive?

이성령 picture 이성령 · Feb 28, 2018 · Viewed 54.8k times · Source

I use Google Colaboratory then I want to save output images in my Google Drive or SSD, HHD but its directory is "/content"

import os     
print(os.getcwd())
# "/content"

so is it possible to change path (HDD, SSD, googledrive)?

Answer

Tadej Magajna picture Tadej Magajna · Oct 11, 2018

You need to mount google drive to your Colab session.

from google.colab import drive
drive.mount('/content/gdrive')

Then you can simply write to google drive as you would to a local file system like so:

with open('/content/gdrive/My Drive/file.txt', 'w') as f:
  f.write('content')