Google Colab#
Google Colab is a free cloud service that supports free GPU and TPU. It is a Jupyter notebook environment that requires no setup to use. It allows you to write and execute Python code in the browser and save your code in Google Drive. It also provides a way to share your code with others.
Tips and Tricks#
Scratchpad Notebook: https://colab.research.google.com/notebooks/empty.ipynb
Open Notebooks from GitHub: simply replace
github.com
withgithubtocolab.com
. It will redirect you to a Colab notebook.Open in Colab Chrome extension: Install this Open in Colab extension to open any GitHub notebook in Colab with a single click.
Timing Execution of Cell: hover over the cell run icon and you will get an estimate of the execution time taken
Run part of a cell: Click
Runtime -> Run Selection
button or using the keyboard shortcutCtrl + Shift + Enter
Most commonly used shortcuts:
Run cell (
Ctrl + Enter
)Run cell and add new cell below (
Alt + Enter
)Run cell and goto the next cell below (
Shift + Enter
)Comment current line (
Ctrl + /
)
Jupyter Notebook Keyboard Shortcuts: Click Tools -> Keyboard shortcuts or Just add
Ctrl + M
before whatever keyboard shortcut you were using in Jupyter. For exampleadd a cell above (
Ctrl + M + A
)Add a cell below (
Ctrl + M + B
)Change cell to code (
Ctrl + M + Y
)Change cell to markdown (
Ctrl + M + M
)
Jump to Class definition: press
Ctrl
and then clicking a class nameRun bash commands:
Download dataset from the web with
!wget <ENTER URL>
Install libraries with
!pip install <LIBRARY>
Clone a git repository with
!git clone <REPOSITORY URL>
Change directory with
!cd
Mount your Google Drive to Colab:
from google.colab import drive
drive.mount('/content/gdrive')
To upload a file (or several) from your computer, run:
from google.colab import files
files.upload()
To download a file, run:
from google.colab import files
files.download('path/to/your/file')
“Open in Colab” Badge: You can add a
Open in Colab
badge to a markdown file or jupyter notebooks using the following markdown code:[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/notebooks/basic_features_overview.ipynb)
References: