Google Colaboratory 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
- 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. In this blog post we shall discuss about setting up your Colab notebook to get started with Machine Learning or Deep Learning development.
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 library which is used for augmentation of images during test phase. This can be done using:
!pip install library-name
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:
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.
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:
One of the best features of Colab is the free GPU runtime it provides. You can enable your GPU runtime by:
- Go to Runtime
- Select Change runtime type
- Select GPU from the drop down menu and click on save
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.
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.