This is a quick guide to starting Practical Deep Learning for Coders using Google Colab. Colab is a service that provides GPU-powered Notebooks for free. It's based on, but slightly different to, regular Jupyter Notebooks, so be sure to read the Colab docs to learn how it works.
NB: Colab is a free service that may not always be available, and requires extra steps to ensure your work is saved. Be sure to read the docs on the Colab web-site to ensure you understand the limitations of the system.
You can open any chapter of the book in Colab by clicking on one of these links: Introduction to Jupyter | Chapter 1, Intro | Chapter 2, Production | Chapter 3, Ethics | Chapter 4, MNIST Basics | Chapter 5, Pet Breeds | Chapter 6, Multi-Category | Chapter 7, Sizing and TTA | Chapter 8, Collab | Chapter 9, Tabular | Chapter 10, NLP | Chapter 11, Mid-Level API | Chapter 12, NLP Deep-Dive | Chapter 13, Convolutions | Chapter 14, Resnet | Chapter 15, Arch Details | Chapter 16, Optimizers and Callbacks | Chapter 17, Foundations | Chapter 18, GradCAM | Chapter 19, Learner | Chapter 20, conclusion
Alternatively, head on to the Colab Welcome Page and click on 'Github'. In the 'Enter a GitHub URL or search by organization or user' line enter 'fastai/fastbook'. You will see all the courses notebooks listed there. Click on the one you are interested in using.
NB: One section of chapter 2 uses Voila, which unfortunately is not supported by Colab. For that section, either skip it, or use a different platform such as Gradient (Colab is the only platform which doesn't support Voila).
Before running anything, you need to tell Colab that you are interested in using a GPU. You can do this by clicking on the ‘Runtime’ tab and selecting ‘Change runtime type’. A pop-up window will open up with a drop-down menu.
Select ‘GPU’ from the menu and click ‘Save’.
The first cell contains the code necessary to set up
fastai and other libraries you'll need. It looks like this:
!pip install -Uqq fastbook import fastbook fastbook.setup_book()
Click the "run" triangle on the left of that cell, or press Ctrl-Enter, to execute the cell.
When you run the first cell, you may face a pop-up saying 'Warning: This notebook was not authored by Google'; you should click on 'Run Anyway' to get rid of the warning.
Colab lets you save your work to Google Drive, so when you run the cell, it will ask you to login to Google Drive. You'll need a Google Account to do this.
After you've logged in, you can execute the next cell which imports everything you need from the library you just installed. It looks like this:
from fastbook import *
Your Google Drive will be available in a variable called
gdrive, which will point to
Path('/content/gdrive/My Drive'). When saving files and models during the lessons, you should use directories in this path.
After opening a notebook from Github, you will need to save your work to Google Drive. You can do this by clicking on 'File' and then 'Save'. You should see a pop-up with the following message:
Click on 'SAVE A COPY IN DRIVE'. This will open up a new tab with the same file, only this time located in your Drive. If you want to continue working after saving, use the file in the new tab. Your notebook will be saved in a folder called
Colab Notebooks in your Google Drive by default.
For more advanced tips on using Colab effectively, have a look at this blog post.