14. Colab Training
Notebook Location
colab/cattle_buffalo_trainer.ipynb— main Colab notebookcolab/cattle_buffalo_trainer.py— same content as percent-format scriptcolab/README.md— setup instructions
Project Setup Options (in Colab)
- GitHub clone (recommended):
!rm -rf /content/project # force-refresh to pick up latest code !git clone https://github.com/Bharaths31/ML-CB-B-identifier /content/projectImportant: Always
rm -rf /content/projectbefore cloning so that updated code (bug fixes, new features) is pulled correctly. Simply re-running the clone cell without deleting first silently keeps the old cached copy. - Upload
colab_project.zip: created bypython scripts/create_colab_project_zip.py - Google Drive mount: copy
colab_project.zipfromMy Drive/ML-CB-B-identifier/
Dataset Options (in Colab)
- Kaggle API / Direct Download: auto-downloads unified
algsoch/breed-cattle-buffalodataset containing both cattle and buffalo breeds - Upload
archive.zip: created bypython scripts/create_colab_archive.py - Google Drive: copy
archive.zipfrom Drive
T4 GPU Optimizations
| Setting | Value | Reason |
|---|---|---|
batch_size |
64 | Maximizes T4 utilization (15 GB VRAM) |
grad_accum |
2 | Effective batch = 128 |
num_workers |
2 | Colab has 2 CPU cores |
prefetch_factor |
4 | Keeps GPU fed |
pin_memory |
True | Faster CPU→GPU transfer |
| AMP | phases 1-2 only | Disabled for QAT phase 3 |
| Dataset location | /content/data/raw/ |
Local SSD, not Drive |
Known Colab Gotchas
| Symptom | Root Cause | Fix |
|---|---|---|
AttributeError: 'torch._C._CudaDeviceProperties' object has no attribute 'total_mem' |
PyTorch attribute is total_memory, not total_mem |
Fixed in src/train.py:49 and colab/cattle_buffalo_trainer.py:29,900 |
| Re-running GitHub clone cell doesn't pick up new code | Colab re-uses cached /content/project/ directory |
Add !rm -rf /content/project before git clone in §1 |
| Runtime restarts wipe all files | Colab free tier has ephemeral storage | Re-run all cells from §0 top-to-bottom after any restart |