Saving Variable state in Colaboratory

走远了吗. 提交于 2019-12-06 07:43:14

The outputs of Colab cells shown in your browser are stored in notebook JSON saved to Drive. Those will persist.

If you want to save your Python variable state, you'll need to use something like pickle to save to a file and then save that file somewhere outside of the VM.

Of course, that's a bit a trouble. One way to make things easier is to use a FUSE filesystem to mount some persistant storage where you can easily save regular files but have them persist beyond the lifetime of the VM.

An example of using a Drive FUSE wrapper to do this is in this example notebook: https://colab.research.google.com/notebook#fileId=1mhRDqCiFBL_Zy_LAcc9bM0Hqzd8BFQS3

This notebook shows the following:

  1. Installing a Google Drive FUSE wrapper.
  2. Authenticating and mounting a Google Drive backed filesystem.
  3. Saving local Python variables using pickle as a file on Drive.
  4. Loading the saved variables.

It'a a nope. As @Bob in this recent thread says: "VMs time out after a period of inactivity, so you'll want to structure your notebooks to install custom dependencies if needed."

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