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

后端 未结 3 1587
执念已碎
执念已碎 2021-01-31 10:12

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())
         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 10:48

    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')
    

提交回复
热议问题