【发布时间】:2019-11-10 23:32:27
【问题描述】:
我正在尝试将 kaggle imagenet 对象定位挑战数据下载到 google colab 中,以便我可以使用它来训练我的模型。 Kaggle 使用 API 轻松快速地访问他们的数据集。 (https://github.com/Kaggle/kaggle-api) 但是,当在 google colab 中调用命令“kaggle Competitions download -c imagenet-object-localization-challenge”时,找不到包含我的用户名和 api-key 的 kaggle.json 文件。
在我的 mac 上运行 jupyter notebook 时没有遇到这个问题,但是由于我想将 google 的 gpu 用于我的模型,所以我开始使用 google colab。因为 kaggle API 要求用户名和 api-key 位于 .kaggle 目录中的 kaggle.json 文件中,所以我首先创建了目录 .kaggle,然后创建了文件 kaggle.json,我在其中写入了我的用户名和 api-密钥(下面的示例不显示我的用户名和 api 密钥)。然后我尝试配置我的 json 文件的路径,以供 kaggle 在调用 kaggle 下载命令时使用。
!pip install kaggle
!mkdir .kaggle
!touch .kaggle/kaggle.json
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 path -p /content
但是,在运行最后一个命令时,我得到了错误:
IOError: Could not find kaggle.json. Make sure it's located in /root/.kaggle. Or use the environment method.
我的目标是使用以下命令从 kaggle 获取数据集:
!kaggle competitions download -c imagenet-object-localization-challenge
os.chdir('/content/competitions/imagenet-object-localization-challenge')
for file in os.listdir():
zip_ref = zipfile.ZipFile(file, 'r')
zip_ref.extractall()
zip_ref.close()
我不明白为什么 kaggle API 找不到我的 json 文件。如何在 google colab 中使用 API?
【问题讨论】:
标签: python google-colaboratory kaggle