Setting up Google Colab for Deep Learning
Tags: deeplearning, machinelearning, python, datascience
Published: 2021-06-09 22:13:20

## Introduction
[Google Colaboratory](https://colab.research.google.com/notebooks/intro.ipynb#recent=true) or Colab is a free service provided by Google that allows a person to run Python notebooks without having to install python on their systems. Colab provides a user with numerous features, the most important of them being:
* No need to configure for basic notebooks
* Free and easy GPU access
* Easily sharing of codes and link the notebooks to [GitHub](https://github.com)
* Loading datasets straight from your Google Drive and saving notebooks/ trained models to your drive too.
Google Colab also comes with a Pro feature, you can learn more about the details of Colab Pro from [here](https://colab.research.google.com/signup).
In this blog post we shall discuss about setting up your Colab notebook to get started with Machine Learning or Deep Learning development.

## Installing dependencies
While Colab usually comes pre-installed with most of the basic dependencies like Tensorflow, PyTorch, scikit-learn, pandas and many more, there are chances that you have to install external packages at times. You can do that using the `!pip install` command. For example we can install the [ttach](https://github.com/qubvel/ttach) library which is used for augmentation of images during test phase. This can be done using:
```!pip install library-name```
Running the cell will yeild an output like:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dur71n8z6u7ln4kg0zvg.png)
This way we can install custom libraries as per our needs.

## Mounting Google Drive
You can mount your Google Drive using a simple the simple script given below:
```
from google.colab import drive
drive.mount('/content/drive')
```
Upon running this you will get a link that will redicrect you to select the account whose google drive you want to mount. Select the account, accept the the permission request and copy the code that appears on the screen and paste that in the dialog box and press enter. Your Google Drive is now mounted and you can access it via the files menu on your left. The output would look something like this:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/duo4q0xdwcu9noayf7vv.png) 

## Cloning GitHub Repositories
At times you might need to clone your GitHub repository to your Colab library to work on complex projects that utilize multiple scripts. That can be done using `!git clone link-to-repository`
Running the cell would clone the repository to your working directory.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pcgoyl7m8g9yzjw7snc3.png)
You can also clone a repository to your google drive if you have mounted it. That is done using `!git clone link-to-repository path-to-drive`. The sample output would look like:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g1hfljsw2pxoxal481rs.png)

## Accessing GPU runtime
One of the best features of Colab is the free GPU runtime it provides. You can enable your GPU runtime by:
1. Go to Runtime
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2x66zgnv8win79oo7asx.png)
2. Select Change runtime type
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vlh5w2jduolou98xcsq3.png)
3. Select GPU from the drop down menu and click on save
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/frqnocxyi7koupulpequ.png)
That's it, now you can use your GPU runtime provided by Colab.
You can also check which GPU you are provided using `!nvidia-smi`.
The output shows GPU memory you are consuming and other details as well.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gfuxt2wldkgltq3aoodo.png)

This concludes our discussion for setting up Colab to run Machine Learning and Deep Learning applications. Now you can easily clone GitHub repositories to your drive and execute them using GPU runtime without having to install Python on your local machine.