"""
In this notebook I'm going to run through how to get started with this competition in Google Colab. Copy and paste all the code in this notebook, into a Google Colab instance. Feel free to upvote if you found it useful :)


"""
"""
### 1. Install Kaggle API

Open a new Colab notebook and begin by installing the Kaggle API.
"""
! pip install kaggle
! pip install --upgrade --force-reinstall --no-deps kaggle # force install the latest version
"""
### 2. Mount Google Drive

First get your Kaggle API key. Head to Profile -> Account tab to find the following:

![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4271956%2F78ba4ffb3cd87cd8dad4af4644327e4c%2FScreen%20Shot%202021-01-09%20at%203.04.35%20pm.png?generation=1610165267080465&alt=media)

Upload the json file somewhere convenient in your Google Drive. The next cell mounts your Drive and makes it accessible within Colab. You'll have to go through a brief authorisation dance after running the cell.
"""
from google.colab import drive
drive.mount('/gdrive', force_remount=True)
"""
Make the appropriate directory for your kaggle.json, and shift the file there.
"""
! mkdir ~/.kaggle
! cp /content/gdrive/MyDrive/kaggle.json ~/.kaggle/
! chmod 600 ~/.kaggle/kaggle.json
"""
### 3. Download competition data

And enjoy speeds of around 100Mb/s while you do so!
"""
comp = 'rsna-miccai-brain-tumor-radiogenomic-classification'
comp_dir = 'rsna-miccai'

# This will download to the working directory of your Colab instance. 
# Faster to work with, but you have to repeat the process every time you instantiate the runtime.
! kaggle competitions download -c {comp}
! unzip /content/{comp}.zip

# Alternatively, you can download to your Drive, and then access accordingly.
# This can cause issues as Drive is notoriously slow / poor at indexing large directories (https://stackoverflow.com/questions/54294532/time-out-on-drive-mount-content-drive-in-google-colab)
! mkdir /gdrive/MyDrive/{comp_dir}
! kaggle competitions download -c {comp} -p /gdrive/MyDrive/{comp_dir}
! unzip /gdrive/MyDrive/ranzcr/{comp}.zip

# For file paths, you'll now be using, for example:
TRAIN_DIR = '/content/train' # or '/gdrive/MyDrive/rsna-miccai/train' if you decide to go with Drive.
! mkdir /content/gdrive/MyDrive/ranzcr/checkpoints
checkpoint_path = '/content/gdrive/MyDrive/ranzcr/checkpoints'

# Saving your checkpoints is as easy as:
torch.save({'model': model.state_dict()}, checkpoint_path+f'/{model_name}_{fold}_best.pth')
"""
Lastly, for the TPU's GCS_PATH, just use the file paths returned by:
"""
gcs_paths = KaggleDatasets().get_gcs_path({comp})
"""
Thanks for reading this far. If you have any suggestions for further tips to add, feel free to comment below.
"""