Earlier examples were not working for me. Below my approach to download Kaggle competition data with Colab.
As an example I’ll use the Kannada-MNIST dataset.
Practically it copies this approach:
https://stackoverflow.com/questions/49310470/using-kaggle-datasets-in-google-colab.
Step 1 and 2 are required one time only.
-
Request a new API token on Kaggle (profile > account > API) and download JSON file to your computer.
-
Run the following code
Upload the JSON file
from google.colab import files
files.upload()
Install Kaggle
!pip install -q kaggle
The Kaggle API client expects this file to be in ~/.kaggle
, so move it there.
!mkdir -p ~/.kaggle
!cp kaggle.json ~/.kaggle/
This permissions change avoids a warning on Kaggle tool startup.
!chmod 600 ~/.kaggle/kaggle.json
-
Create a folder on Google drive for your competition data:
path = Path(base_dir + 'data/kannada') path.mkdir(parents=True, exist_ok=True) path
Download that sh*t
!kaggle competitions download -c Kannada-MNIST -p /content/gdrive/My\ Drive/fastai-v3/data/kannada
Unzip .zip files
! unzip -q -n '{path}/Dig-MNIST.csv.zip' -d '{path}'
! unzip -q -n '{path}/train.csv.zip' -d '{path}'
! unzip -q -n '{path}/test.csv.zip' -d '{path}'
Maybe not the smartest work around, it worked for me