

Google Colab — Your Python workspace on cloud
source link: https://www.tuicool.com/articles/NneAR36
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Today, I switched to a new machine for my development. While there is a learning curve attached to get aligned with the new machine, I can still continue to work on my projects and pursue my online courses through Google Colab. It’s practically as simple as logging into my Google account and I’m all set.
Thus, I decided to share my insights on why I find Google Colab so useful and the commands that have helped me use it more effectively without much effort.
What is Google Colab?
Google Colab, also know as Colaboratory, is a Jupyter environment provided and supported by Google with the option to work with CPUs, GPUs and even TPUs. It’s like any other Jupyter notebook where we can code in Python and write descriptions as markdown along with all the other Jupyter features and a lot more.
The top section includes all the controls to save notebooks, share notebooks to GitHub repositories, change runtime environments, run cells and a lot more. The bottom section is divided into a left panel which includes the table of contents and files, and has the complete functioning notebook on the right.
Why Google Colab?
While there are many reasons why one might prefer to use a service like Google Colab for their work, following are reasons it works for me:
- GitHub integration: While the notebooks are saved to our Google drive, I prefer to also share some of the notebooks as part of their own GitHub repository. Google Colab allows a direct share to any repository after linking our GitHub profile.
- Zero set up time: To get started with Google Colab, all you need to do is go to https://colab.research.google.com/ and select
NEW PYTHON 3 NOTEBOOK
from the popup menu. - Platform independence: As the Jupyter notebooks can be accessed directly from a browser, we can have any machine, Mac, Windows, Linux etc. and it’ll work exactly the same.
- Free resource availability: Training models for deep learning require a lot of power and hence, not all laptops and desktops are equipped for it. Google Colab provides free access to GPUs which we can leverage for our deep learning tasks.
Exploring Google Colab
Now that we understand what Google Colab is and how many benefits it brings to the table for everyone, let’s explore a few key important aspects. These have surely helped me in increasing my productivity and making my work more accessible.
Quick keyboard shortcuts
Moving across cells is easy. You just need to use the UP
and DOWN
arrow keys on the keyboard. To start editing a cell, simply press Enter
. To escape from editing a cell, simply press Esc
.
There are already some predefined keyboard shortcuts that you can use. Some of the most basic include Shift + Enter
to run a cell, Ctrl + M Y
to convert a cell to code cell, Ctrl + M M
to convert a cell to text cell and more. You can get the complete list by going to Tools > Keyboard shortcuts...
You can customize and change the shortcuts as you like.
Apart from the predefined ones, I customized two more shortcuts according to my need. As the shortcuts that deal with cells start with the combination of Ctrl + M
, I decided that I’d keep the same while configuring my own shortcuts. For creating a new code cell, I created the shortcut Ctrl + M C
. For creating a new text cell, I created the shortcut Ctrl + M T
.
Similar shortcuts exist and can be configured for Mac as well using the Command Key
.
Load datasets
Google Colab allows us to get access to our datasets via a number of ways.
Upload dataset
On the left panel, select theFiles
heading. Select the option
Upload
and select the dataset file.
However, the files are removed at runtime refresh so if somehow the runtime crashes without completing its task, you’ll have to upload them again.
Load dataset from Google drive
Secondly, we can import the datasets that are already saved in Google drive. This is beneficial as we do not need to upload the dataset again if the notebook crashes.To mount the Google drive, we use the following code:
On running this code, a link is provided which allows us to login into our account and presents an authorization token which needs to be entered in the space provided for it to work. This enables us to access the contents of our Google drive using the My Drive
folder inside /content/drive
.
Save to GitHub repository
One of the most fascinating and useful features for me has been the integration between Google Colab and GitHub. I prefer to work on Jupyter notebooks and save my work to specific GitHub repositories in my account. Google Colab makes the whole process hassle-free and easy to use.
From the File
menu, we select the option to Save a copy in GitHub...
. It loads up a screen to link our GitHub account, which is a one-time process after which, we are greeted with another popup. We can select the repository, the branch, the name of the file and the commit message. It’s that simple!!
We can also add a link to this notebook in the GitHub repository, so anyone viewing the notebook on GitHub can quickly jump right into working.
Changing runtime type
If you’ve ever worked with deep learning models, you would understand the role a GPU can play in increasing the speed of training many-fold. Google Colab provides the option to add a GPU/TPU for our use totally free of charge. This allows us to train our deep learning models at much higher rates.
From the Runtime
menu, select Change runtime type
. Under hardware accelerator, we can either choose None
to continue with CPU or change the runtime to GPU
or TPU
as needed.
Once you click SAVE
, the runtime will refresh and you can notice that on the top right, CONNECTING
shows up to signify that we’re now activating the new runtime type.
Sharing Colab notebooks
Another significant feature is to share our work with the world. The share option at the top right corner of Google Colab allows us to select a list email addresses to share the notebook with or simply get a shareable link.
Conclusion
Google Colab is a great way to keep up with your work and access it wherever you want. It has many features such as creating easy shortcuts, sharing and saving notebooks and more.
Recommend
-
50
Photo by
-
32
I have recently been accepted into Phase I of Bertelsmann Tech Scholarship Challenge Course — AI Track Nanodegree Program . In the lessons, Jupyter note...
-
32
Colab is phenomenal for beginning deep learning, but how does it stack up against an eGPU + Ultrabook?
-
9
软硬件环境 google colab YOLOv5 视频看这里 此处是youtube的播放链接,需要科学上网。喜欢我的视频,请记得订阅我的频道,打开旁边的小铃铛,点...
-
10
@davisdavidDavis DavidData Scientist | AI Practitioner | Software Developer. Giving talks, teaching, writing.Google Colab and VS Code are the most popular...
-
5
Use Julia on Google Colab2021 年 9 月 3 日JuliaGoogle C...
-
23
Export Google Colab Notebook as HTML WebpageExport HTML from Colab without additional tools.
-
26
PyTorch Geometric Installation · GitHub Instantly share code, notes, and snippets. ...
-
9
Deepfakes Google Has Banned the Training of Deepfakes in Colab
-
11
Google Cloud’s Colab Enterprise environment to help tune LLMs At its Cloud Next conference, the company added new features for advanced MLOps for genera...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK