Google Colab — Introduction
Google Colab — Introduction
Section titled “Google Colab — Introduction”What is Google Colab?
Section titled “What is Google Colab?”Google Colaboratory (Colab) is a free, cloud-hosted Jupyter notebook environment provided by Google. It requires no setup, runs entirely in the browser, and provides free access to GPUs and TPUs — making it the most popular platform for ML experimentation and learning.
Key facts:
- Built on Jupyter Notebook (
.ipynbcompatible) - Runs on Google’s infrastructure
- Free tier includes GPU/TPU access
- Notebooks stored in Google Drive
- Collaborative editing (like Google Docs)
Colab vs Local Jupyter
Section titled “Colab vs Local Jupyter”| Feature | Google Colab | Local Jupyter |
|---|---|---|
| Setup | None | Install Python + packages |
| GPU/TPU | Free (with limits) | Requires hardware |
| Storage | Google Drive | Local disk |
| RAM | 12–52 GB (tier dependent) | Your machine’s RAM |
| Session timeout | 12h (free), longer (paid) | No timeout |
| Collaboration | Real-time | Manual sharing |
| Internet access | Yes | Yes |
| Custom packages | Yes (per session) | Persistent |
| Cost | Free / Pro / Pro+ | Free (hardware cost) |
Colab Tiers
Section titled “Colab Tiers”| Tier | GPU | RAM | Session Length | Price |
|---|---|---|---|---|
| Free | T4 (shared, limited) | ~12 GB | 12h max | Free |
| Colab Pro | T4/V100 (priority) | ~25 GB | 24h | ~$10/mo |
| Colab Pro+ | A100/V100 (priority) | ~52 GB | 24h+ background | ~$50/mo |
Getting Started
Section titled “Getting Started”- Go to colab.research.google.com
- Sign in with Google account
File → New notebookor open from Drive- Start coding — Python environment is pre-configured
Pre-installed Libraries
Section titled “Pre-installed Libraries”Colab comes with most data science libraries pre-installed:
# These work out of the boximport numpy as npimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsimport sklearnimport tensorflow as tfimport torchimport cv2import PILChecking Runtime
Section titled “Checking Runtime”import platformprint(platform.python_version()) # Python version
# Check GPUimport torchprint(torch.cuda.is_available())print(torch.cuda.get_device_name(0))
# TensorFlow GPUimport tensorflow as tfprint(tf.config.list_physical_devices('GPU'))
# System info!nvidia-smi # GPU details!cat /proc/cpuinfo # CPU info!cat /proc/meminfo # Memory info!df -h # Disk spaceConnecting to Google Drive
Section titled “Connecting to Google Drive”from google.colab import drivedrive.mount('/content/drive')
# Access filesimport pandas as pddf = pd.read_csv('/content/drive/MyDrive/data/myfile.csv')
# Save filesdf.to_csv('/content/drive/MyDrive/output/results.csv', index=False)Uploading Files
Section titled “Uploading Files”from google.colab import files
# Upload from local machineuploaded = files.upload()# Returns dict: {filename: bytes}
import iodf = pd.read_csv(io.BytesIO(uploaded['data.csv']))
# Download a filefiles.download('output.csv')Runtime Types
Section titled “Runtime Types”Change via Runtime → Change runtime type:
| Runtime | Use Case |
|---|---|
| CPU | General Python, light ML |
| GPU (T4/V100/A100) | Deep learning, PyTorch, TensorFlow |
| TPU | Large-scale TensorFlow training |
# Verify GPU is activeimport tensorflow as tfprint("GPU available:", tf.test.is_gpu_available())
# PyTorchdevice = 'cuda' if torch.cuda.is_available() else 'cpu'model = model.to(device)