Colab Tutorial
Colab Tutorial
Colab Tutorial
TA: 陳光銘
2023.02.20
[email protected]
Link of this Tutorial
https://reurl.cc/eWj6jL
There are options for moving your cell up/down or copy or delete it
Code Cell
Text
Cell
Getting Started
You can type python code in the code cell, or use a leading exclamation mark ! to
change the code cell to treating the input as a shell script
→ python
→ shell script
Getting Started
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 is called a magic command.
Available GPUs:
T4 > K80
you can mount your own google drive to colab and directly download/save the
data to your google drive.
Mount Drive:
Mounting Google Drive
Click on the Google Drive icon, the Mount Drive code block will be generated
Mounting Google Drive
Execute the following three code blocks in order
This will download the image to your google drive, and
you can access it later
Saving Notebook
● Download the .ipynb file to your 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 <dirname> : Create a directory <dirname>
cd <dirname> : Move to directory <dirname>
gdown : Download files from google drive
wget : Download files from the internet
python <python_file>: Executes a python file
Problems You May Encounter…
● Colab will automatically disconnect if idle timeout(90 min., sometimes varying) or
when your screen goes black
→ solution: keep your screen on or try using javascript
● GPU usage is not unlimited ! (your account will be stopped for a period if you reached
the max gpu usage 12 hrs)
* The cooldown period before you can connect to another GPU will extend from hours to
days to weeks depending on your usage
Best solution:
1. buy colab pro :)
2. use your own resource (if able)
Reminder: TAs are not required to help you solve environment problems
Reference
● https://colab.research.google.com
● https://research.google.com/colaboratory/faq.html