python - 如何从本地驱动器上传和保存大数据到Google Colaboratory?

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

我已经从这个 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])))

最佳答案

!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 无法添加为评论原因代表。

关于python - 如何从本地驱动器上传和保存大数据到Google Colaboratory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48860586/

相关文章:

Python 正则表达式语法

google-apps-script - 使用 Google Apps 脚本覆盖图像文件

ios - 从 IOS 应用程序将图像上传到 Google Drive

tensorflow - 在 Tensorflow 的 DNNClassifier 估计器中记录设备信息

machine-learning - Caffe 在打印数据 -> 标签后挂起

python - 反转字符串中标记的子字符串

python - python opencv cv2 中的掩码不起作用?

python - 如何在一列上执行 pandas groupby 操作,但将另一列保留在生成的数据框中

image-processing - 如果整个地面实况是黑色的,则医学图像分割

google-drive-api - Google 云端硬盘 - 更改 :list API - Detect changes at folder level