我已经从这个 Kaggle 链接下载了 zip 格式的大图像训练数据
https://www.kaggle.com/c/yelp-restaurant-photo-classification/data
我如何有效地实现以下目标?
- 在 Google Colaboratory 中创建项目文件夹
- 上传zip文件到项目文件夹
- 解压文件
谢谢
编辑:我尝试了下面的代码,但它因我的大 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/