在Google Colab中找不到kaggle.json文件 [英] Can't find kaggle.json file in google colab

查看:256
本文介绍了在Google Colab中找不到kaggle.json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将kaggle imagenet对象本地化挑战数据下载到google colab中,以便可以使用它来训练我的模型.Kaggle使用API​​轻松快速地访问其数据集.( https://github.com/Kaggle/kaggle-api )但是,在调用命令时Google colab中的"kaggle竞赛下载-c imagenet-object-localization-challenge",找不到包含我的用户名和api-key的kaggle.json文件.

I'm trying to download the kaggle imagenet object localization challenge data into google colab so that I can use it to train my model. Kaggle uses an API for easy and fast access to their datasets. (https://github.com/Kaggle/kaggle-api) However, when calling the command "kaggle competitions download -c imagenet-object-localization-challenge" in google colab, it can't find the kaggle.json file which contains my username and api-key.

运行jupyter笔记本时,我的Mac上没有出现此问题,但是由于我想将google的gpu用于我的模型,因此我开始使用google colab.因为kaggle API希望用户名和api-key位于.kaggle目录中的kaggle.json文件中,所以我首先创建了目录.kaggle,然后是文件kaggle.json,我在其中写入了用户名和api-键(以下示例未显示我的用户名和api键).然后,我尝试配置我的json文件的路径,以便kaggle在调用kaggle下载命令时使用.

I haven't had this problem on my mac when running a jupyter notebook, but since I want to use google's gpu for my model, I started using google colab. Because the kaggle API expects the username and api-key to be in a kaggle.json file located in a .kaggle directory, I first created the directory .kaggle and then the file kaggle.json, into which I wrote my username and api-key (The example below doesn't display my username and api-key). I then tried to configure the path to my json file for kaggle to use when calling the kaggle download command.

!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

但是,在运行最后一条命令时,出现错误消息:

However, when running the last command, I got the error:

IOError: Could not find kaggle.json. Make sure it's located in /root/.kaggle. Or use the environment method.

我的目标是使用以下命令从kaggle获取数据集:

My goal was to use the following commands to get the dataset from 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​​?

I don't understand why the kaggle API can't find my json file. How can I use the API in google colab?

推荐答案

如错误所述,您需要将kaggle.json放在正确的位置.

As the error said, you need to put kaggle.json in the right place.

尝试:

!mv .kaggle /root/

然后再次运行您的代码.

Then run your code again.

这篇关于在Google Colab中找不到kaggle.json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆