Google Colab

Introduction to Google Colab

Google Colab is a product of Google, from the name itself you can understand. It is basically a free notebook environment that runs fully in the cloud. It has features that help you to edit documents like the same way you work with Google Docs. Colab supports many popular and high-level machine learning libraries which can be easily loaded in your notebook.

Why do you need Google Colab?

Google is quite involved in the Artificial Intelligence research and development part. One of the most popular AI frameworks was made by Google called TensorFlow and also a development tool called Collaboratory. Now in recent days, TensorFlow is one of the most used open-sourced tools since 2017. Google Collaboratory was made free for public use by Google to courage the AI enthusiast and the community well. Colaboratory is now publicly known as Google Colab or Colab.

A very attractive feature that Google offers to the developers is the use of GPU. Google Colab is popular because of the support of GPU and that is also totally free. The main aim behind the free Google colaboraty for the public to make the software a standard in the academics for teaching machine learning and data science purpose. It may also have hidden long term perspective of building a customer base for Google Cloud APIs which are sold per-use basis.

Irrespective of all the hidden reasons, the introduction of Colab has really made AI researchers and developers’ life easy for the development of machine learning applications.

What is Google Colab?

If you are quite familiar with Jupyter notebook, then it almost similar to that and you can quickly learn to use Google Colab. To be more precise or in short, you can claim that Google Colab is a free version of the Jupyter notebook environment that entirely build in the cloud. The most important feature of Google collab is, it does not require setup and the notebooks that you create can be simultaneously edited by your team members – just the way you edit documents in Google Docs. Colab supports many popular machine learning libraries which can be easily loaded in your notebook.

Features of Google Colab

  • Write and execute code in Python
  • Document the code which supports the mathematical equations
  • Create new notebooks
  • Upload the existing notebooks
  • Share the notebooks with the google link
  • Import data from Google Drive
  • Save notebooks from/to Google Drive
  • Import/Publish notebooks from GitHub
  • Import external datasets e.g. from Kaggle
  • Integrate PyTorch, TensorFlow, Keras, OpenCV
  • Free Cloud service with free GPU and TPU

What is GPU and why do we need this for Artificial Intelligence?

GPUs are basically optimized to train artificial intelligence and deep learning models. GPU can process multiple computations simultaneously.

They have a large number of cores that allow for the better computation of multiple parallel processes and also additionally, computations in deep learning need to handle huge amounts of data which makes a GPU’s memory bandwidth most suitable.

GPU and TPU facility on Google Colab

  • The availability of free GPUs and TPUs is really the best thing about Google collab.
  • Train the models, especially the deep learning complicated models with the huge datasets it takes numerous hours on a CPU to get trained.
  • Everyone faced this same issue to train those models in the CPU.
  • GPUs and TPUs have the ability to train these models in a matter of minutes or seconds
  • Any AI researchers or enthusiasts prefer to go for using GPU over any other CPU because of the sheer computational power and speed of execution.
  • But as GPU is expensive, so not everyone can afford a GPU.
  • And this is where Google Collab plays a major role to provide GPU service for free of cost
  • It gives you a good GPU for free which you can use continuously for 12 hours.

Types of runtime in Google Colab

Google Colab gives us three types of runtime for our notebooks:

  • Total Three types of runtime we have in Google colab
  • CPUs,
  • GPUs, and
  • TPUs

Colab provides us with a total of 12 hours of continuous execution time. After that, all the virtual machine is cleared and we need to start from the scratch 

We can execute multiple CPU, GPU, and TPU instances simultaneously in Google collab, but the resources are shared between these instances.

Let’s have a look at the specifications of different runtimes given by Google Colab:

  • CPU: Model name: Intel(R) Xeon(R) CPU @ 2.30GHz
  • Address sizes: 46 bits physical, 48 bits virtual
  • Cache size: 46080 KB
  • GPU: single 12GB NVIDIA Tesla K80 GPU
  • It can be used up to 12 hours continuously
  • 13 GB RAM
  • Cloud TPU with 180 teraflops of computation, Intel Xeon processor with two core @ 2.30 GHz
  • !3 GB RAM

How to make the first Colab notebook?

  • To start with Google colab you need to follow a few steps:

Step 1: Log in to your Gmail

Step 2: Search for google colab

Step 3: Click on the link

  • Set up the name for your notebook
  • By default, the notebook naming convention is UntitledXX.ipynb.
  • To change the notebook name, click on this name and type in the desired name in the edit box −
  • Change the runtime and also check the runtime

Step 1: Go to Runtime

Step 2: Change runtime

Step 3: Choose between CPU, GPU, TPU

Step 4: and save

Start with coding

import time
print(time.ctime())

After writing down the code just play the execute button

Remove output:

Anytime the output can be cleared by clicking the icon on the left side of the output display

Add a new code block:

To add more code to the notebook, select the following options −

Insert / Code Cell

And there is one more alternative to add the code block, just hover the mouse at the bottom centre of the Code cell. When the CODE and TEXT buttons come, click on the CODE to add a new cell.

RUN all the code block at a time

  • To do the same you need to follow few steps:
  • Go to Runtime
  • Run all

Change the Cell Order

When you have a number of code cells in the notebook, you may face situations where you need to change the order of execution of these cells. So You can do that by selecting the cell that you want to move and clicking the UP CELL or DOWN CELL buttons

Delete a particular code block

Maybe you have few now-unwanted cells in your notebook and if You can remove such code blocks from your project with just a single click. Then you need to follow a few steps.

  • Click on the vertical-dotted icon at the top right corner of your code cell.
  • Click on the Delete cell option and the current cell will be deleted.

Upload dataset in Google colab

If you want to upload a dataset for your particular code you can do that by using the upload dataset option.

  • Follow the steps to do the same
  • Click on the left side box option
  • There you will get an option for upload file sign
  • Then choose your file from the system

Terminal Commands on Google Colab

Using the Colab code block for executing terminal commands.

Most of the popular libraries come installed by default on Google Colab.

  • Numpy
  • Pandas
  • Matplotlib
  • Scikit-learn
  • Seaborn
!pip install library_name

0

LEAVE A REPLY

Please enter your comment!
Please enter your name here

2 × five =