首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Google Colaboratory中保存文件/图片

在Google Colaboratory中保存文件/图片
EN

Stack Overflow用户
提问于 2018-10-09 17:02:25
回答 2查看 6.4K关注 0票数 1

目前,我正在处理400+图像,并使用

代码语言:javascript
运行
复制
from google.colab import files
uploaded = files.upload()

这个运行得很好,但是每次我离开我的合作者的时候,我都要重新上传所有的图片。非常烦人,因为上传需要5-10分钟。

有没有可能防止这种情况发生?看起来Colaboratory只是暂时保存文件。

我必须使用谷歌协作,因为我需要他们的GPU。

提前感谢:)

EN

回答 2

Stack Overflow用户

发布于 2018-10-09 18:55:15

据我所知,没有办法将数据永久存储在Google Colab VM上,但有比files.upload()更快的方法将数据上传到Colab上。

例如,您可以将您的镜像上传到Google Drive上一次,然后1)将Google Drive直接挂载到您的VM中,或者2)使用PyDrive将您的镜像下载到VM上。这两个选项都应该比从本地驱动器上传图像快得多。

VM中的挂载驱动器

  1. 挂载谷歌硬盘:

从google.colab导入驱动器drive.mount('/gdrive')

  • Print位于驱动器根目录下的foo.txt的内容:

使用open('/gdrive/foo.txt')作为f: for line in f: print(line)

使用PyDrive

看一下这个question的第一个答案。

票数 6
EN

Stack Overflow用户

发布于 2020-04-06 18:18:15

首先,挂载你的Google Drive:

代码语言:javascript
运行
复制
# Load the Drive helper and mount
from google.colab import drive

# This will prompt for authorization.
drive.mount('/content/drive')

结果是:

代码语言:javascript
运行
复制
Mounted at /content/drive

要检查已装载的目录,请运行以下命令:

代码语言:javascript
运行
复制
# After executing the cell above, Drive
# files will be present in "/content/drive/My Drive".
!ls "/content/drive/My Drive"

结果如下所示:

代码语言:javascript
运行
复制
07_structured_data.ipynb       Sample Excel file.xlsx
BigQuery recipes           script.ipynb
Colab Notebooks            TFGan tutorial in Colab.txt
Copy of nima colab.ipynb       to_upload (1).ipynb
created.txt            to_upload (2).ipynb
Exported DataFrame sheet.gsheet    to_upload (3).ipynb
foo.txt                to_upload.ipynb
Pickle + Drive FUSE example.ipynb  variables.pickle
Sample Excel file.gsheet
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52717164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档