Skip main navigation

Colab

An article on the basics of using Colab, and uploading data via Google Drive.

What is Colab and how does it differ from Jupyter?

In the previous article we introduced the idea of interactive Python notebooks with Jupyter. These are a combination of text and interactive code that you can run in a browser window.

In this article we’ll look briefly at a useful alternative to Jupyter, Colab.

What is Colab?

Colab, a free service from Google (though paid options exist), is like Jupyter in that you can view, produce and share notebooks with text and interactive code cells, except that rather than the code being executed locally on your machine, it is executed remotely on their computers.

For some deep learning projects this has two advantages. Firstly, convenience in that no software or specialised libraries need to be installed to run your analyses. This is particularly useful if you want to share your results and discussion with others, particularly if they are non-specialists, unlikely to have the necessary software.

The second advantage is computing power. The remote computing resources available to Colab are likely to be much greater than on any local machine, and this setup also allows for easy use of GPU acceleration. The catch to this is that you first need to upload your data to Google Drive, and computing resources are not guaranteed or unlimited at all times. There are also some restrictions on the types of code you can run, but broadly speaking most use in introductory research and education is well within these guidelines.

How do you use Colab?

The first step is to navigate to the Colab homepage (https://colab.research.google.com/), and sign in using the button (top left at time of writing), either using an existing Google account, or by creating a new one. Otherwise you won’t be able to either save your notebooks or upload data for analysis.

This will probably open a window giving you the option to create a new notebook, or to open the example welcome notebook from Colab. If you open a new notebook you can then begin writing text and running code as in JupyterLab.

To run any analysis on your data you’ll need to upload it to Google Drive, and mount Google Drive to Colab. At time of writing, to mount Google Drive you can click the folder icon to the left of the screen (highlighted orange in the screenshot below), and then click the Google Drive icon and give the necessary permissions and account details.

A screenshot indicating the location of the icon to mount Google Drive in Colab

Once mounted you should see any existing files you have in Drive listed under drive/MyDrive. To add data from your machine you can either drag and drop from a file explorer or right-click in the file browser in Colab.

A screenshot showing the file browser having mounted Google Drive in Colab

To refer to files in drive within your Colab notebook you will need to use the path drive/MyDrive/, for example:

image_name = 'drive/MyDrive/image_name.png'

directory_name = 'drive/MyDrive/data_directory'

Code cells

To run code cells in Colab you need to click on the play button that should appear when you hover over the top left of the cell.

This article is from the free online

Machine Learning for Image Data

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now