【问题标题】:How to upload and save large data to Google Colaboratory from local drive?如何将大数据从本地驱动器上传并保存到 Google Colaboratory?
【发布时间】:2018-07-29 08:36:36
【问题描述】:

我已经从这个 Kaggle 链接下载了大图像训练数据作为 zip

https://www.kaggle.com/c/yelp-restaurant-photo-classification/data

我如何有效地实现以下目标?

  1. 在 Google Colaboratory 中创建项目文件夹
  2. 将 zip 文件上传到项目文件夹
  3. 解压文件

谢谢

编辑:我尝试了下面的代码,但是对于我的大 zip 文件它崩溃了。有没有更好/更有效的方法来做到这一点,我可以在本地驱动器中指定文件的位置?

from google.colab import files
uploaded = files.upload()

for fn in uploaded.keys():
  print('User uploaded file "{name}" with length {length} bytes'.format(
      name=fn, length=len(uploaded[fn])))

【问题讨论】:

    标签: python google-drive-api deep-learning jupyter-notebook google-colaboratory


    【解决方案1】:

    您可以参考以下主题:

    还可以查看I/O example notebook。例如,要访问 xls 文件,您需要将文件上传到 Google 表格。然后,您可以在同一 I/O 示例笔记本中使用 gspread 配方。

    【讨论】:

      【解决方案2】:

      您可能需要使用kaggle-cli 模块来帮助下载。

      this fast.ai thread 讨论过。

      【讨论】:

      • +! topcoder.com 有类似的东西吗?
      【解决方案3】:

      我刚刚编写了这个脚本,用于从 Kaggle API 下载数据并将其提取到 Colab 笔记本中。您只需粘贴您的用户名、API 密钥和竞赛名称。

      https://gist.github.com/jayspeidell/d10b84b8d3da52df723beacc5b15cb27

      Colab 中的手动上传功能现在有点问题,最好还是通过 wget 或 API 服务下载文件,因为每次打开笔记本时都会从新的虚拟机开始。这样数据将自动下载。

      【讨论】:

        【解决方案4】:
        !pip install kaggle
        api_token = {"username":"USERNAME","key":"API_KEY"}
        import json
        import zipfile
        import os
        with open('/content/.kaggle/kaggle.json', 'w') as file:
            json.dump(api_token, file)
        !chmod 600 /content/.kaggle/kaggle.json
        !kaggle config set -n path -v /content
        !kaggle competitions download -c jigsaw-toxic-comment-classification-challenge
        os.chdir('/content/competitions/jigsaw-toxic-comment-classification-challenge')
        for file in os.listdir():
            zip_ref = zipfile.ZipFile(file, 'r')
            zip_ref.extractall()
            zip_ref.close()
        

        第 9 行 有微小的变化,否则会出现错误。 来源:https://gist.github.com/jayspeidell/d10b84b8d3da52df723beacc5b15cb27 无法添加为评论原因代表。

        【讨论】:

          【解决方案5】:

          另一种选择是将数据上传到保管箱(如果可以的话),获取下载链接。然后在笔记本上做

          !wget link -0 new-name && ls
          

          【讨论】:

            猜你喜欢
            • 2014-06-25
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多