Google Research’s Colaboratory at colab.research.google.com is a Jupyter Notebook environment that runs in a browser. It comes with many of the machine learning libraries you’ll need, already installed. Its best feature is, you can set the runtime type of a notebook to GPU to use Google’s GPU for free. It even lets you use Google’s TPUs (tensor processing units).
In this tutorial, you'll go over how to get started with Google Colab. By the end of the tutorial, you should know how to:
- Add Google Colab as an app to Google Drive
- Set the runtime type to GPU
- Access dataset files in your Google Drive
If you don’t have access to a machine learning capable computer, Colab is a great alternative. If you choose to use Colab, you’ll have to perform the following set up. Of course, you will need a Google account to in order to continue.
Access your Google Drive drive.google.com and from the side menu, create a new Folder named machine-learning.
Double click the folder, and drag and drop the unzipped snacks dataset into it. This may take a while. While you wait, you’ll need to add Colab as an "app" to Google Drive. Right-click anywhere in the machine-learning folder, select More from the dialog, and select + Select Connect more apps.
From the Connect apps to Drive window that opens up, search for colab in the search field, and select + Connect.
Once it’s been successfully installed, close the window, and Right-click anywhere again, and from the More dialog, select Colaboratory. This will open a new tab or window with something that should look a lot like a Jupyter notebook.
Rename the file to getting-started.ipynb by clicking the ttile and renaming it inline.
From the toolbar, select Runtime > Change Runtime type.
From the Notebook settings dialog that open, change the Hardware accelerator from None to GPU. Save the changes.
In first code cell of the notebook, paste the following code:
from google.colab import drive drive.mount('/content/drive/')
These two lines will walk your through mounting your google drive folders into the notebook. This requires giving Colab access to your Google Drive folders. Click the tiny play button beside the code cell. Follow the instructions in the output window by opening the link to give Colab the authority to access your Drive. You’ll be given an access code to paste into your notebook.
Once the mounting is complete, add a new code cell, and run the following piece of code:
!ls "/content/drive/My Drive/machine-learning/snacks"
You may notice that the code starts off with an exclamation. This is Juypter-specific syntax that allows you to run system level commands. In this case, you’re trying to list the contents of the directory in which you uploaded the snacks dataset. If all goes well, you should now be able to set this path as your root directory to the snacks dataset.
You’ve completed setting up a Google Colab notebook environment, configured to use the GPU, and gave it access to a dataset in Google Drive. Colab offers a compelling alternative for developers looking to do machine learning, but don’t have access to a machine powerful enough to run machine learning algorithms.