{"cells":[{"metadata":{},"cell_type":"markdown","source":"Thanks to user [Andy](https://www.kaggle.com/andy1010) for [this discussion](https://www.kaggle.com/c/ranzcr-clip-catheter-line-classification/discussion/209846), which this notebook is based on."},{"metadata":{},"cell_type":"markdown","source":"# Install Kaggle API\n\nOpen a new Colab notebook and begin by installing the Kaggle API."},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-output":true},"cell_type":"code","source":"! pip install kaggle\n! pip install --upgrade --force-reinstall --no-deps kaggle # force install the latest version","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Then get your 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":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","collapsed":true,"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":false,"_kg_hide-output":true},"cell_type":"code","source":"from google.colab import drive\ndrive.mount('/content/gdrive', force_remount=True)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Make the appropriate directory for your kaggle.json, and shift the file there."},{"metadata":{"trusted":true,"_kg_hide-output":true},"cell_type":"code","source":"! mkdir ~/.kaggle\n! cp /content/gdrive/MyDrive/kaggle.json ~/.kaggle/\n! chmod 600 ~/.kaggle/kaggle.json","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Download the competition data."},{"metadata":{"trusted":true,"_kg_hide-output":true},"cell_type":"code","source":"# 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 ranzcr-clip-catheter-line-classification\n! unzip /content/ranzcr-clip-catheter-line-classification.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 /content/gdrive/MyDrive/ranzcr\n! kaggle competitions download -c ranzcr-clip-catheter-line-classification -p /content/gdrive/MyDrive/ranzcr\n! unzip /content/gdrive/MyDrive/ranzcr/ranzcr-clip-catheter-line-classification.zip\n\n# For file paths, you'll now be using, for example:\nTRAIN_DIR = '/content/train' # or '//content/gdrive/MyDrive/ranzcr/train' if you decide to go with Drive.","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-output":true},"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')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Lastly, for the TPU's GCS_PATH, just use the file paths returned by:"},{"metadata":{"trusted":true,"_kg_hide-output":true},"cell_type":"code","source":"gcs_paths = KaggleDatasets().get_gcs_path(ranzcr-clip-catheter-line-classification)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Thanks again to Andy for starting this topic. If you have any suggestions for further tips to add, feel free to comment below."}],"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":4,"nbformat_minor":4}