Vision Field Notes

Training on Google Colab: Limits and Workarounds

Google Colab is the easiest way to get a GPU for a first training run. You open a notebook, pick a GPU runtime, and start. For learning, small datasets and quick experiments, that is often enough. The problems start when you treat it like a machine you own. It is not. It is a temporary session, and anything you do not save somewhere else can disappear.

This article covers what Colab is good for, where it limits you, and a few habits that stop you from losing work.

What the free tier is good for

Colab works well for:

It works badly for long jobs, large datasets, anything that must finish on a deadline, and anything you need to repeat exactly.

The limits you will hit

The exact numbers change over time and depend on your plan, so check the current Colab documentation rather than trusting a blog post. The behaviours, though, are stable enough to plan for.

Limit What it means in practice
GPU is not guaranteed You may get a different GPU model from one session to the next, or none at all at busy times.
Session time cap A runtime stops after a maximum number of hours, even if your job is still running.
Idle timeout If the browser tab is closed or the notebook is idle, the runtime can be disconnected.
Temporary disk Files in the runtime's local storage are deleted when the session ends.
Limited RAM and disk Large datasets and big batch sizes can hit memory or disk limits.

The most important line is the fourth. Your trained weights, logs and even your dataset are gone if they live only on the local disk of a session that ends.

Habit 1: save everything outside the runtime

The simplest fix is to mount Google Drive and write training output there.

from google.colab import drive
drive.mount('/content/drive')

Then point Ultralytics at a folder on Drive using the project and name arguments:

from ultralytics import YOLO

model = YOLO("yolov8n.pt")
model.train(
    data="/content/dataset/data.yaml",
    epochs=100,
    imgsz=640,
    project="/content/drive/MyDrive/runs",
    name="exp1",
)

Ultralytics writes last.pt and best.pt into the weights folder of the run. Because that folder is on Drive, the files survive a disconnect. If you are not sure which version of the library you have, run pip show ultralytics and check the documentation for that version.

Writing many small files to Drive during training can be slow. A common compromise is to train on the local disk and copy the run folder to Drive at the end, or periodically from a second cell. If you do that, you must remember to copy before the session ends, so the Drive-first approach is safer for long runs.

Diagram with two areas. On the left, a dashed red box labelled Colab runtime local disk, deleted when the session ends, holds the unzipped dataset folder and the training process. On the right, a green box labelled Google Drive, persists between sessions, holds dataset.zip and the runs/exp1/weights folder with last.pt and best.pt. Arrows show the zip being copied and unzipped into the runtime at the start, and the training process saving checkpoints to Drive.
Caption: Keep the dataset zip and the checkpoints on Drive, and treat everything in the runtime as disposable. The images are read from the fast local copy, while the weights go straight to Drive.

Habit 2: keep the dataset as one archive

Copying thousands of small image files from Drive into the runtime is slow. Copying one zip file and unzipping it locally is much faster.

  1. Keep your dataset as a single .zip on Drive.
  2. At the start of each session, copy it to /content and unzip it there.
  3. Edit data.yaml so the paths point to the unzipped location.

Do this in the first cells of the notebook so a fresh session is ready in a minute or two. Training from the local copy is also faster than reading images from Drive on every epoch.

Habit 3: make runs resumable

Assume the session will end before training finishes. Ultralytics can continue an interrupted run from its last checkpoint:

from ultralytics import YOLO

model = YOLO("/content/drive/MyDrive/runs/exp1/weights/last.pt")
model.train(resume=True)

This only works if last.pt exists, which is why saving to Drive matters. Also plan your epoch count with the session cap in mind. If one epoch takes a known time on your GPU, you can estimate how many fit in a session. Measure it from a short run instead of guessing.

Timeline with two rows. The top row, saving to Drive with resume=True, shows three sessions covering epochs 1 to 37, 38 to 74 and 75 to 100, with arrows carrying the run from one session to the next. The bottom row, local disk only, shows two sessions that both cover epochs 1 to 37, followed by the note weights lost, start over. Dotted red lines mark where each session ends.
Caption: With checkpoints on Drive, each new session continues where the last one stopped; without them, every disconnect sends you back to epoch 1. Session lengths and epoch counts are illustrative.

Habit 4: write the setup as code

Every new session starts from a blank machine. Put the following in the top cells of the notebook, in order:

  1. Install packages (pip install ultralytics).
  2. Mount Drive.
  3. Copy and unzip the dataset.
  4. Check the GPU is attached.

For the last step, torch.cuda.is_available() returns True when PyTorch can see a GPU. If it returns False, change the runtime type before you waste time on a CPU run.

Pin versions if you need repeatable results. A notebook that installs "the latest" package may behave differently three months from now. Our guide to setting up a clean Python environment for computer vision explains version pinning in more detail.

Common mistakes

When to move on

Colab is a good place to start. You should think about something else when:

Your main options are a paid Colab plan, a rented cloud GPU, or a local machine with a graphics card for training. Each has different costs and trade-offs. The comparison in cloud GPUs for model training goes through how to choose without overspending. Check current prices before deciding, since they change often.

A reasonable path is to prototype on Colab, then move to a rented or local GPU once you know the dataset and settings work. The expensive mistake is renting a GPU to debug a dataset problem that a short Colab run would have shown.

Checklist

Next steps: cloud GPUs for model training, train YOLO on a custom dataset.