Lab 2 · PyTorch: Train a Day-vs-Night Classifier
Biological motivation
Many camera-trap analyses condition on diel period. A simple but useful first model is a day-vs-night binary classifier on the image itself (no EXIF needed). It also lets us validate your software environment end-to-end before tackling species identification on Day 2.
Data
You will be given a curated day_night/ folder built from the Oregon Critters
sample:
day_night/
├── train/
│ ├── day/ (800 images)
│ └── night/ (800 images)
└── val/
├── day/ (200 images)
└── night/ (200 images)
Day/night labels were derived from EXIF timestamps and sunrise/sunset at site location, then hand-verified.
Tasks
Task 1 — run the starter (4 pts)
Run lab2_train.py unmodified. Confirm that:
- It uses your GPU/MPS if available (it prints the device).
- It trains for 5 epochs without crashing.
- It produces
day_night.ptandtraining_curves.png.
Task 2 — train longer with augmentation (5 pts)
Edit the script to:
- Train for 10 epochs.
- Add random horizontal flips and a mild color jitter to the train transform.
- Save the model with the best validation accuracy, not the last epoch.
Task 3 — evaluate (5 pts)
Compute and save a confusion matrix on the validation set
(fig_confusion.png). Also report:
- Validation accuracy.
- Per-class precision and recall.
- The 5 most confidently wrong predictions, with thumbnails and predicted scores.
Task 4 — interpretation (4 pts)
In 150 words: when do the model's mistakes happen? Heavy snow at midday? Bright IR illuminator at night? What features is your model probably using? Does the data leak any cues you didn't intend (e.g., a sticker on the lens visible only at night)?
Go-further (2 pts within the rubric)
Re-train using only the bottom 20% of each image (cropped at load time). How much does accuracy drop? Why?
Rubric
| Component | Points |
|---|---|
| Code modifications run cleanly and produce required outputs | 10 |
| Written interpretation including a hypothesis about failure modes | 6 |
| Go-further (crop ablation) with written reasoning | 4 |
| Total | 20 |
Starter: lab2_train.py