Google Colab is a free cloud service that currently supports GPU (Tesla K80) and TPU (TPUv2). Because it is developed based on Jupiter Notebook, using Google Colab is similar to using Jupyter Notebook. Google Colab is an ideal tool for us to practice programming skills with Python language through deep learning libraries. Google Colab pre-installs for us very popular libraries in Deep Learning such as PyTorch, TensorFlow, Keras and OpenCV.
Machine Learning/Deep Learning is evolving at a very fast pace. To write a program using a Deep Learning framework like TensorFlow, Kera or Pytorch, we can use any Python IDE like PyCharm, Jupyter Notebook or Atom. However, because Machine Learning / Deep Learning algorithms require the system to have high speed and processing ability (usually based on GPU), our computers are usually not equipped with GPUs.
Many learners and researchers choose to hire compute services on AWS as a solution.
Since then, Google has launched a completely free service for the AI research community, developing Deep Learning applications by providing free GPU and TPU – That is Google Colab.
Currently, programmers often choose Colab instead of AWS’s high-cost service. Colab supports GPU (Tesla K80) and TPU (TPUv2). How to use Colab is similar to that on Jupiter Notebook. This is a great free service from Google if you don’t have a highly configurable computer to program and compile Python with deep learning libraries. Currently, Google Colab has available popular libraries to support research on artificial intelligence such as PyTorch, TensorFlow, Keras and OpenCV.
Google Colab is really cool. In addition to improving your coding skills, or working on Deep Learning PyTorch, Keras, TensorFlow, OpenCV libraries, you can also create notebooks on Colab, perform operations with those notebooks like upload, save store, share even on Google Drive. You can also use anything you store in notebooks like uploading to your personal Jupyter, GitHub, Kaggle, and more.
Colab really provides the most amazing things a programmer needs when doing Deep Learning.
Doing it on Google Colab is quite easy. If you already use Jupyter Notebooks then Google Colab is similar. And of course, you will feel the greatness of implementing Deep Learning on GPU-enabled software compared to the usual cramped instructions.
Google Colab – Make installation on Google Drive
Create a Folder for your Notebook
(Technically, this step may not really be necessary in case you only need to work on Colab. However, when you use Google Colab on Drive, it won’t be a bad idea for verification. specify the folder where you want to work.You can do it by going to Google Drive, click “ New ” to create a new Folder.I only mentioned this when my Google Drive was having problems and looks like millions of Colab Notebooks appear at the same time).
Alternatively, you can create a Colab notebook on your Google Drive. Just click “ New ”, scroll down to the “ More ” section and select “ Colaboratory ”.
Otherwise, you can go directly to Google Colab.
Start up
You can rename your notebook by clicking on the name of the notebook and changing it directly or clicking “ File ” on the toolbar and scrolling down to the “ Rename ” section.
Install GPU for free
When you want to use the GPU, it’s very simple. You just need to click “ Runtime” on the toolbar, select the “ Change runtime type ” section and select the GPU in the “ Hardware Accelerator ” section.
Start Code with Google Colab
Start Code
Now you can easily execute the code.
Improvements with Google Colab
When you want to link Google Drive, you can do the following:
from google.colab import drive
drive.mount(‘/content/gdrive’)
Then you will see a link. Click on it and allow access. Copy the code that appears and paste it into the box, then press enter. You are done. In case you don’t see your Drive in the left pane, just press “ Refresh ” and it will show up. Your result will have the following structure:
You should now be able to see your Drive on the left side of the screen. Plus, you can access your Drive at any time with:
!ls “/content/gdrive/My Drive/”
If you want to download a zip file you can use:
!wget
!unzip
For example:
!wget -cq https://s3.amazonaws.com/content.udacity-data.com/courses/nd188/flower_data.zip
!unzip -qq flower_data.zip
With this command, you will have the data of the Udacity’s flower file almost immediately.
If you upload a small file, you can execute the upload command immediately with simple commands. Or alternatively you can look to the left side of the screen, click “ Upload files ”.
Google Colab is very simple to use. Especially when you are used to Notebook Jupyter. However, it may take some time if you have a large volume of files and have a few specific folders to work with.
Start Code
Now you can easily execute the code.
Improvements with Google Colab
When you want to link Google Drive, you can do the following:
from google.colab import drive
drive.mount(‘/content/gdrive’)
Then you will see a link. Click on it and allow access. Copy the code that appears and paste it into the box, then press enter. You are done. In case you don’t see your Drive in the left pane, just press “ Refresh ” and it will show up. Your result will have the following structure:
You should now be able to see your Drive on the left side of the screen. Plus, you can access your Drive at any time with:
!ls “/content/gdrive/My Drive/”
If you want to download a zip file you can use:
!wget
!unzip
For example:
!wget -cq https://s3.amazonaws.com/content.udacity-data.com/courses/nd188/flower_data.zip
!unzip -qq flower_data.zip
With this command, you will have the data of the Udacity’s flower file almost immediately.
If you upload a small file, you can execute the upload command immediately with simple commands. Or alternatively you can look to the left side of the screen, click “ Upload files ”.
Upload files ”.
Google Colab is very simple to use. Especially when you are used to Notebook Jupyter. However, it may take some time if you have a large volume of files and have a few specific folders to work with.
Instructions for Importing Libraries in Google Colab
In most cases you can import libraries with the import command as you would in other software.
However, with PyTorch, before importing the library, you will have to run this command first:
# http://pytorch.org/
from os.path import exists
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag
platform = ‘{}{}-{}’.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
cuda_output = !ldconfig -p|grep cudart.so|sed -e ‘s/.*\.\([0-9]*\)\.\([0-9]*\)$/cu\1\ 2/’
accelerator = cuda_output[0] if exists(‘/dev/nvidia0’) else ‘cpu’
!pip install -q http://download.pytorch.org/whl/{accelerator}/torch-0.4.1-{platform}-linux_x86_64.whl torchvision
import torch
Only then can you do import . But if you try to import torch without running the above command, you will get an error message. In this case, I strongly recommend clicking on the link that pops up. Once pressed, you will receive a code for you to install torch: “INSTALL TORCH” to your notebook. The code will appear on the left side of your screen, and then press “INSERT.”
Alternatively, you can perform the installation with the “pip install” command.
Note, on Colab, you need an exclamation point before most statements.
!pip install -q keras
import keras
Or:
!pip3 install torch torchvision
Or:
!apt-get install
also very helpful.
With Pillow you can get an error and it can be fixed by:
import PIL
print(PIL.PILLOW_VERSION)
In case you get anything below 5.3, run “runtime” in the toolbar. Restart the runtime and then continue to run the command.
You can easily create a new notebook by clicking “ File ”, clicking “ New Python 3 Notebook .” If you want to open a specific notebook, click “ File ”, then click “ Open notebook ”.
You will see the following screen appear:
Wish you get acquainted and master Google Colab
Wish you get acquainted and master Google Colab