使用Colab的Kaggle数据集的最佳实践

时间:2020-05-18 17:56:38

标签: google-colaboratory kaggle

我想知道是否有人可以确认将kaggle数据集下载到我们的colab笔记本的最佳做法?

我看过下面的代码示例,我们将其下载API令牌文件并将其上传到环境中,这是最佳实践,还是有其他/简单/更好的方法?

提前谢谢! 雅各布

from google.colab import files
!pip install -q kaggle
files.upload()
!mkdir -p ~/.kaggle
!cp kaggle.json ~/.kaggle/
!chmod 600 /root/.kaggle/kaggle.json
!kaggle datasets download -d alxmamaev/flowers-recognition

1 个答案:

答案 0 :(得分:0)

有两种方便的方法:

1)将kaggle.json保存在GDrive中。然后通过单击(在左窗格中)进行安装。然后,将其复制到此处。

!mkdir -p ~/.kaggle
!cp "drive/My Drive/kaggle.json" ~/.kaggle/
# the rest is the same

2)将kaggle.json嵌入Colab本身。

!mkdir ~/.kaggle
!echo '{"username":"korakot","key":"8db2xxx"}' > ~/.kaggle/kaggle.json
# the rest is the same

如果您担心,请使用更安全的第一个。

如果您很懒,请使用第二个。