Why Google Colab?
*** My warm welcome to all the readers! ***
1. Introduction:
Not everyone can indeed afford a powerful computing system. We have nothing but to adjust with less computing system which runs code for hours and even days. Most of us have got a system with RAM 4 GB or 8 GB and only a few have RAM beyond 8 GB with an advanced processor. What can we do if we have a less powerful computing system? Should we build-up patience and wait for the code to run for hours and even days? No, we don’t have to wait for hours or days to run certain codes. Here comes rescuer — Google Colab. Google Colab is also known as Google Colaboratory. Google Colab is a jupyter notebook environment. It is a free source provided by google wherein we can write and execute code. We can use Google Colab with ease just as we use local jupyter. Google Colab provides RAM of 12 GB with a maximum extension of 25 GB and a disk space of 358.27 GB. Wow! It is great to have a free source with such huge RAM and disk space.
FYI: If certain code takes 1 hour to run in local Jupyter or Spyder or any other environment, same code takes around 10–15 minutes to run in Google Colab. Amazing, isn’t it!
2. How to Open and/or Upload Notebooks
Well, I must admit that it is not that tough to learn to use Google Colab. We can easily learn to use it in the first attempt. Click on the Google Colab link: https://colab.research.google.com/ which navigates us to the official site. This is how it looks when we click on the above link.
In the above image, we can see a dialog box with headings ‘Examples’, ‘Recent’, ‘Google Drive’, ‘Github’, and ‘Upload’. Each heading is nothing but sections through which we can open our notebook and use it for further analysis.
2.1 Examples:
Under this section, we can explore google colab like overview, guide, etc.
2.2 Recent:
Under this section, only those notebooks will be displayed which are recently used. You can directly go to the Recent section and open a recent notebook for further analysis.
2.3 Google Drive:
Under this section, all the notebooks which are in our google drive are displayed. We can access it by click on it and use for further analysis.
2.4 Github:
Under this section, all the notebooks which are in our Github are displayed. We just need to paste the respective link and get access to notebooks.
2.5 Upload
Under this section, we can upload notebooks from our local drive and access it.
If we want to create a new notebook, then we should click on Cancel button (Bottom Right) in the dialog box. Below is the image for reference.
From the above image, we can clearly see how we can create new notebook with Python version 2 and 3; open and upload notebook; save, save a copy in drive, github; download ipynb and py notebook; and print notebook.
3 How to use Google Colab Notebook
This is how Google Colab notebook looks — similar to jupyter notebook.
3.1 Notebook Settings (None/GPU/TPU)
If we are working on models such as Machine Learning, we can keep the default notebook setting i.e ‘None’.
If we are working on models such as Deep Learning, it is advised to change the notebook settings to either GPU — Graphics Processing Unit or TPU — Tensor Processing Unit.
For difference between GPU and TPU, please refer to the quora answers:
https://www.quora.com/What-is-the-difference-between-GPUs-CPUs-and-TPUs
3.2 Mounting Colab with Drive
We can’t access folders and files like CSV, TXT, XML, images, etc unless we mount the colab with the drive. Below is the code to mount the colab with the drive.
Enter the above code and run. It will provide a URL link which we need to click. After clicking the URL, a new tab will open where we will see a dialog ‘Choose an account’. This dialog displays Email Id(s). Click on the corresponding Email ID which is linked to google drive. If Email ID is not displayed which we want to use, we can use another account by clicking on ‘Use another account’. Below is the image for reference.
After clicking on the Email ID, a new tab will open with the dialog box ‘Google Drive File Stream’. Click on the ‘Allow’ button. Below is the image for reference.
After clicking on the ‘Allow’ button, a new tab will open wherein we can see randomly generated code is provided along with the ‘Copy’ icon. Click on the ‘Copy’ icon. Get back to Google Colab Notebook and paste in the blank field displayed below the mount code. Below is the image for reference.
After copying code, paste in the blank field displayed below the mount code. Then hit on enter. Below is the image for reference.
3.3 Access Drive Folders and Files
To access drive folders and files, click on the Right Indicating arrow (top left of the notebook). After clicking on the Right Indicating arrow, it slides right which displays folders and files under the Files section. Below is the image for reference.
Right-click on the required file and access it like Download, Delete file, Rename file, Copy path, and Refresh.
3.4 Upload Drive Files
We can upload data files from drive to colab by specifying a path of it. Below is the image for reference.
And then specify the path in the code which then uploads the required file. Below is the image for reference.
We can now proceed for further analysis.
Repeating only to highlight it.
FYI: If certain code takes 1 hour to run in local Jupyter or Spyder or any other environment, same code takes around 10–15 minutes to run in Google Colab. Amazing, isn’t it!
*** Thank you all for reading this blog. Your suggestions are very much appreciated! ***