Write out file with google colab

我是研究僧i 提交于 2019-12-21 09:18:14

问题


Was there a way to write out files with google colab? For example, if I use

import requests
r = requests.get(url)

Where will those files be stored? Can they be found? And similarly, can I get the file I outputted via say tensorflow save function

saver=tf.Saver(....)
...
path = saver.save(sess, "./my_model.ckpt")

Thanks!


回答1:


In your first example, the data is still in r.content. So you also need to save them first with open('data.dat', 'wb').write(r.content)

Then you can download them with files.download

from google.colab import files
files.download('data.dat')

Downloading your model is the same:

files.download('my_model.ckpt')



回答2:


I found it is easier to first mount your Google drive to the non-persistent VM and then use os.chdir() to change your current working folder.

After doing this, you can do the exactly same stuff as in local machine.

I have a gist listing several ways to save and transfer files between Colab VM and Google drive, but I think mounting Google drive is the easiest approach.

For more details, please refer to mount_your_google_drive.md in this gist https://gist.github.com/Joshua1989/dc7e60aa487430ea704a8cb3f2c5d6a6



来源:https://stackoverflow.com/questions/49675374/write-out-file-with-google-colab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!