Colab_Tutorial
Carpe Tu Black Whistle

Link of this tutorial(Colab): https://reurl.cc/Epg3M0
Link of the class: https://www.youtube.com/watch?v=YmPF0jrWn6Y

Outline

image

Intro

What’s Colab? – Colab, or “Colaboratory”, allows you to write and execute Python in your browser with

  • Zero configuration required
  • Free access to GPUs
  • Easy sharing

Getting Started

Creating a new cell

+Code: create a code cell
+Text: create a text cell

There are options for moving your cell up/down or copy or delete it.

image

Using an exclamation mark(!) starts a new shell, does the operations, and then kills that shell while percentage(%) affects the process associated with the notebook, and it’s called a magic command.

Use % instead of ! for cd(change directory) command

Other magic commands are listed here

Runtime Setting

Changing Runtime

To utilize the free GPU provided by google,
click on “Runtime” -> “Change Runtime Type” -> select “GPU“ for “Hardware Accelerator”
Doing this will restart the session, so make sure you change to the desired runtime before executing any code

Check GPU Type

Use the command nvida-smi to check the allocated GPU type
Available GPUs:

(But most of the time you get K80 using the free Colab)

image

File Manipulation

Download files via Google Drive

image

Upload and Download Files

image

Mounting Google Drive

if u want some files to be saved permantly, u can mount ur own google drive to colab and directly download/save the data to ur google drive

1
2
3
4
5
from google.colab import drive
drive.mount('/content/drive')

Output:
Mouted at /content/frive

image

Execute the following three code blocks in order
This will download the image to your google drive, and u can access it later

image

Saving Notebook

  • Download the .ipynb file to ur local device (file > Download.ipynb)
  • Save the colab notebook to your google drive (file > Save a copy in Drive)
  • Convert .ipynb to .py and download (file > Download.py)

Useful Linux Commands(in Colab)

ls: List all files in the current directory
ls -l: List all files in the current directory with more detail
pwd: Output the working directory
mkdir: Create a directory
cd: Move to directory
gdown: Download files from google drive
wget: Download files from the internet
python: Executes a python file

Problems

  • Colab will automatically disconnect if idle timeout(90 min., sometimes varying) or when your screen goes black

  • GPU usage is not unlimited! (ur account will be stopped for a period for a period if u reached the max gpu usage 12 hrs)