01、安装Kaggle API
将下面语句在Jupyter notebook或者Terminal中运行;
在Terminal中运行时需要根据平台进行调整;(depending on your platform you may need to modify this slightly to either add source activate fastai
or similar, or prefix pip
with a path. Have a look at how conda install
is called for your platform in the appropriate Returning to work section of https://course.fast.ai/. (Depending on your environment, you may also need to append “–user” to the command.)
! {sys.executable} -m pip install kaggle --upgrade
02、下载Kaggle的授权
登录你的Kaggle账户,点击My Account
,下拉找到Create New API Token
,点击下载kaggle.json文件
03、上传Kaggle.json文件
点击upload上传Kaggle.json文件至当前Jupyter notebook所在的地方,并运行下面两行命令;(如果是Windows,则运行后两行)
! mkdir -p ~/.kaggle/
! mv kaggle.json ~/.kaggle/
# For Windows, uncomment these two commands
# ! mkdir %userprofile%\.kaggle
# ! move kaggle.json %userprofile%\.kaggle
04、接受竞赛规则
在Kaggle中,进入你要下载数据的比赛,点击接受竞赛规则;(否则下载不成功)
05、创建保存数据的路径 并 下载
path = Config.data_path()/'planet'
path.mkdir(parents=True, exist_ok=True)
path
本命令以planet competition为例
! kaggle competitions download -c planet-understanding-the-amazon-from-space -f train-jpg.tar.7z -p {path}
! kaggle competitions download -c planet-understanding-the-amazon-from-space -f train_v2.csv -p {path}
! unzip -q -n {path}/train_v2.csv.zip -d {path}
命令结合具体比赛进行修改;其中 “kaggle competitions download -c planet-understanding-the-amazon-from-space“可以在对应竞赛页面data的API中找到,具体文件也有列表;
06. 解压文件
! 7za -bd -y -so x {path}/train-jpg.tar.7z | tar xf - -C {path.as_posix()}
如果没有安装对应的解压程序,记得先安装,此数据是7zip压缩的
! install --yes --prefix {sys.prefix} -c haasad eidl7zip