Colab Introduciton part-2
Starting Colab
- Create a google account (Gmail account)
- Go to https://colab.research.google.com
- Sign in with your google account
- Start using colaboratory
Colaborary Machine Details
- It’s a linux-baesd operating system machine
-
It’s CPU is Intel(R) Xeon(R) CPU @ 2.20GHz
To check CPU info run the below command in colab
!cat /proc/cpuinfo
-
Total RAM 13GB
To check RAM info run the below command in Colab
!cat /proc/meminfo
- Total disk space 108GB
-
It has Tesla T4 16GB GPU memory
To check GPU fist switch the colab machine to GPU by Edit>Notebook Settings and select GPU from Hardware accelerator dropdown
!nvidia-smi -L
!nvidia-smi
- It has google TPU v2 with 8GB memory per core
Colab is a Linux Machine
Colab is a linux-based machine. You can run any linux-based command here.
# check files and directories in current directory
!ls
sample_data
!ls -a
. .. .config sample_data
%cd sample_data/
/content/sample_data
!ls
anscombe.json mnist_test.csv
california_housing_test.csv mnist_train_small.csv
california_housing_train.csv README.md
%cd ..
/content
!mkdir hello
%cd hello
!touch test.py
/content/hello
# edit the script
# then run
!python test.py
hello world!
%cd ..
/content
## install any third party linux software
!apt install docker.io
!docker --version
Docker version 20.10.7, build 20.10.7-0ubuntu5~18.04.3
# download a file from online
!wget https://huggingface.co/sagorsarker/bangla-glove-vectors/resolve/main/bn_glove.100d.zip
# unzip the file
!unzip bn_glove.100d.zip
Archive: bn_glove.100d.zip
inflating: bn_glove.100d.txt
# remove the file
!rm -rf bn_glove.100d.zip
!rm -rf bn_glove.100d.txt
!cat hello/test.py
print("hello world!")
!cp hello/test.py ./
!mv test.py sample_data
!df -h
Filesystem Size Used Avail Use% Mounted on
overlay 108G 38G 71G 35% /
tmpfs 64M 0 64M 0% /dev
shm 5.8G 0 5.8G 0% /dev/shm
/dev/root 2.0G 1.1G 910M 54% /sbin/docker-init
tmpfs 6.4G 28K 6.4G 1% /var/colab
/dev/sda1 55G 39G 17G 71% /etc/hosts
tmpfs 6.4G 0 6.4G 0% /proc/acpi
tmpfs 6.4G 0 6.4G 0% /proc/scsi
tmpfs 6.4G 0 6.4G 0% /sys/firmware
!du -sh
55M .
!pwd
/content
Colab contains build in virtual environment
# install any python package using pip
!pip install tqdm
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (4.64.1)
from tqdm import tqdm
for i in tqdm(range(100)):
pass
100%|██████████| 100/100 [00:00<00:00, 57621.98it/s]
# download google drive file using gdown
!pip install gdown
import gdown
url = "https://drive.google.com/uc?id=1l_5RK28JRL19wpT22B-DY9We3TVXnnQQ"
output = "fcn8s_from_caffe.npz"
gdown.download(url, output, quiet=False)
Downloading...
From: https://drive.google.com/uc?id=1l_5RK28JRL19wpT22B-DY9We3TVXnnQQ
To: /content/fcn8s_from_caffe.npz
100%|██████████| 499M/499M [00:02<00:00, 227MB/s]
'fcn8s_from_caffe.npz'
Special Options
# install or run any module without showing the log
%%capture
!pip install scikit-learn
# write any file using the magic command
%%writefile hello.py
print("hello world!")
Writing hello.py
# check time while running any command or code
%%time
print('hello')
hello
CPU times: user 1.84 ms, sys: 0 ns, total: 1.84 ms
Wall time: 1.78 ms
Pre-installed well known libraries
import tensorflow as tf
tf.__version__
'2.8.2'
import torch
torch.__version__
'1.12.1+cu113'
import sklearn
sklearn.__version__
'1.0.2'
Comments