Colab Tutorial

Google Colab is a free Jupyter notebook environment that runs in the cloud. You can use Google Colab from your browser so you don’t have to install anything on your own computer. With Google Colab, you can access Google’s computing resources, write and execture code, save and share.

1. Login your Gmail account
 
2. Go to the url link: https://colab.research.google.com/

3. Top pane
 
 

  • Top menu: You can see the Colab logo from the top left, and then you can find the top menu, including File, Edit, View, Insert, Runtime, etc.
  • Share: On the top right, the Share button gives you the option of creating a shareable link that you can share with others.
  • + Code: Under the top menu, the + Code will let you add more code cells.
  • + Text: will let you add more text cells.
  • Copy to Drive: allows you to copy this Colab notebook into your Colabe Notebook directory in your Google Drive.
  • Connect: will let you connet this Colab notebook to the runtime.

4. Left pane  
 

Click Files, and it will expand the left pane.

 
 

Then you can browse the directory structure on the left file-exlorer pane.

  • Upload: You can right click (your mouse) and choose Upload in order to upload files to the Colab. Since Colab notebook is hosted on Google’s cloud servers, there’s no direct access to files on your local computer. Or you can click the three dots visible when your mouse hovers above the directory and then you can select the “Upload” option.
  • Download: Hover your mouse above the filename you want to download, and you will see three dots. Click on the three dots and select the Download option.

5. Mount your Google Drive to Colab

  • Executing the following code to mount your Google Drive to Colab, and click “agree”.
    from google.colab import drive
    drive.mount('/content/gdrive')

6. Use the Bash Commands

  • You can use most of the bash commands with a ! added in front of the command.
  • You can also use magic commands with %.
  • Use % instead of ! for cd (change directory) command

7. Use GPUs on Colab

  • If you use the free GPU, click and choose Runtime -> Change Runtime Type -> Hardware accelerator
  • If you use the paid version of the GPUs, click and choose Runtime -> Change Runtime Type, then you will choose the following: Colab GPUs
    Click Save.

  • Check GPUs

GPUs