Downloading from Kaggle — Google Colab + fast.ai Deep Learning Course Lesson 2 (Part 1)

Bhuvana Kundumani
2 min readSep 27, 2018

--

Lesson 2 : Dog Breed Identification

  1. I created a Kaggle account.
  2. To download the datasets from Kaggle, i followed the following steps
  • Go to your Kaggle account. Click on My Account ( Drop down on the right corner). Scroll down to API section and click on ‘Create New API Token’. A file name ‘Kaggle.json’ will get downloaded to your computer. It should be of the format:
{“username”:”YOUR-USER-NAME”,”key”:”SOMETHING-VERY-LONG”}
  • Go to Google Colab and sign in to your account. Open a New Python3 Notebook. Click Runtime . Click on Change runtime type and then Choose Python3 for Runtime type and GPU for Hardware accelerator. Then Click Save.
  • Install Kaggle with the command — !pip install kaggle
  • Create a directory called .kaggle using the command !mkdir .kaggle.
  • Type the following commands —

(Copy the token from the kaggle.json file that you had downloaded from Kaggle and assign it to api_token.)

 import os
import json
api_token = {“username”:”YOUR-USER-NAME”,”key”:”SOMETHING-VERY-LONG”}
with open(‘/content/.kaggle/kaggle.json’, ‘w’) as file:
json.dump(api_token, file)
  • Type — !chmod 600 /content/.kaggle/kaggle.json Then type — !cp /content/.kaggle/kaggle.json ~/.kaggle/kaggle.json
  • Create a directory called dogsbreed using the command - !mkdir dogsbreed
  • To download the dogsbreed dataset in the folder /dogsbreed type the command — !kaggle competitions download -c dog-breed-identification -p /dogsbreed/
  • The dogsbreed dataset has 4 zip files : train.zip ,labels.csv.zip, test.zip and
    sample_submission.csv.zip. These files should be there in the dogsbreed folder. To check run the following commands —os.chdir(‘/dogsbreed/’) and !ls. You should see these files under the dogsbreed folder. Now we need to unzip these files.
  • Type the command — !unzip -q \*.zip to unzip all the files under the dogsbreed folder. It is always better to check if all files have got unzipped. To check use the command — !ls . You should see the following files : train.zip ,labels.csv.zip, test.zip,
    sample_submission.csv.zip, test,train, sample_submission.csv and labels.csv .
  • Great !! You have successfully downloaded the required datasets from Kaggle.
  • Download the pytorch and torchvision using the commands — !pip3 install http://download.pytorch.org/whl/cu80/torch-0.3.0.post4-cp36-cp36m-linux_x86_64.whl
    !pip3 install torchvision
  • Download fastai using the command — !pip3 install fastai
  • The rest of the code for the dogsbreed lesson is available -https://github.com/bhuvanakundumani/fastai_dogsbreed.git

--

--

Bhuvana Kundumani
Bhuvana Kundumani

No responses yet