Skip to content

Lab 5 - #5

Open
tutoringjedi wants to merge 5 commits into
mainfrom
lab_5
Open

Lab 5#5
tutoringjedi wants to merge 5 commits into
mainfrom
lab_5

Conversation

@tutoringjedi

@tutoringjedi tutoringjedi commented Jul 9, 2026

Copy link
Copy Markdown
Owner

PULL REQUEST TITLE: UofT-DSI | Deep Learning - Lab 5
What changes are you trying to make?
Fixing a series of bugs in lab_5.ipynb (the object detection notebook) that were preventing it from running end-to-end, and completing the "build a better model" exercise. Changes include:

Restoring extract_xml_annotation to its original form after a stray edit had broken it
Fixing tensorize_ground_truth to work with the flattened annotation format ({"size", "filename", "class", "bbox"}) instead of assuming the old nested "objects" structure
Adding the missing call classes, boxes = tensorize_ground_truth(annotations), which had been defined but never invoked
Fixing display_prediction and compute_acc to read annotations in the correct flat format
Removing a duplicate cell that was silently overwriting the trained better_model with fresh random weights before evaluation
Adding a stale-cache check when loading voc_representations.h5, so a mismatched cache from an earlier run can't cause a length mismatch
Implementing classif_and_loc, the two-headed (classification + localization) model for the exercise, using a Conv2D layer before global average pooling plus dropout, trained with Adam(learning_rate=1e-4)

What did you learn from the changes you have made?
That annotations needs to hold a single consistent shape throughout the whole notebook — inconsistent formats for the same variable (nested vs. flattened) across cells is what caused most of the KeyErrors. Also reinforced that a function being defined doesn't mean it's been called — silent gaps like that are easy to miss when scanning a long notebook cell by cell rather than tracing the full variable lifecycle.
Was there another approach you were thinking about making? If so, what approach(es) were you thinking of?
Considered keeping multiple objects per image (instead of filtering down to single-object images) and flattening to one row per object rather than one row per image, which would make the dataset closer to a true multi-object detection setup. Went with the single-object simplification instead, consistent with how the notebook was originally structured.
Were there any challenges? If so, what issue(s) did you face? How did you overcome it?
The main challenge was a Python/TensorFlow environment mismatch on Windows — a .venv, a conda env (deep-learning-env), and base anaconda3 were all layered on top of each other, so the notebook's Jupyter kernel wasn't necessarily the one active in the terminal. Resolved by explicitly registering ipykernel inside the conda env and confirming via pip show tensorflow and where python that the kernel and terminal were pointing at the same environment. Also hit a dead GitHub mirror for the PASCAL VOC 2007 dataset and switched to the pjreddie.com mirror with a fallback to the original host.
How were these changes tested?
Verified all cells parse without syntax errors. Traced the notebook's full variable lifecycle (annotations → reprs → classes/boxes → model inputs) cell by cell to confirm consistent data shapes throughout, rather than testing cells in isolation.
A reference to a related issue in your repository (if applicable)
(add issue link here if you have one)

Checklist

  • [ X] I can confirm that my changes are working as intended

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant