{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"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 :)\n\n","metadata":{}},{"cell_type":"markdown","source":"### 1. Install Kaggle API\n\nOpen a new Colab notebook and begin by installing the Kaggle API.","metadata":{}},{"cell_type":"code","source":"! pip install kaggle\n! pip install --upgrade --force-reinstall --no-deps kaggle # force install the latest version","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2. Mount Google Drive\n\nFirst get your Kaggle API key. Head to Profile -> Account tab to find the following:\n\n![](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)\n\nUpload 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.","metadata":{}},{"cell_type":"code","source":"from google.colab import drive\ndrive.mount('/gdrive', force_remount=True)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Make the appropriate directory for your kaggle.json, and shift the file there.","metadata":{}},{"cell_type":"code","source":"! mkdir ~/.kaggle\n! cp /content/gdrive/MyDrive/kaggle.json ~/.kaggle/\n! chmod 600 ~/.kaggle/kaggle.json","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 3. Download competition data\n\nAnd enjoy speeds of around 100Mb/s while you do so!","metadata":{}},{"cell_type":"code","source":"comp = 'rsna-miccai-brain-tumor-radiogenomic-classification'\ncomp_dir = 'rsna-miccai'\n\n# This will download to the working directory of your Colab instance. \n# Faster to work with, but you have to repeat the process every time you instantiate the runtime.\n! kaggle competitions download -c {comp}\n! unzip /content/{comp}.zip\n\n# Alternatively, you can download to your Drive, and then access accordingly.\n# 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)\n! mkdir /gdrive/MyDrive/{comp_dir}\n! kaggle competitions download -c {comp} -p /gdrive/MyDrive/{comp_dir}\n! unzip /gdrive/MyDrive/ranzcr/{comp}.zip\n\n# For file paths, you'll now be using, for example:\nTRAIN_DIR = '/content/train' # or '/gdrive/MyDrive/rsna-miccai/train' if you decide to go with Drive.","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! mkdir /content/gdrive/MyDrive/ranzcr/checkpoints\ncheckpoint_path = '/content/gdrive/MyDrive/ranzcr/checkpoints'\n\n# Saving your checkpoints is as easy as:\ntorch.save({'model': model.state_dict()}, checkpoint_path+f'/{model_name}_{fold}_best.pth')","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Lastly, for the TPU's GCS_PATH, just use the file paths returned by:","metadata":{}},{"cell_type":"code","source":"gcs_paths = KaggleDatasets().get_gcs_path({comp})","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Thanks for reading this far. If you have any suggestions for further tips to add, feel free to comment below.","metadata":{}}]}