Spaces:
Sleeping
Sleeping
Damaris Adora Cursor commited on
Commit ·
6e5bbb2
1
Parent(s): 1d9751f
Stop tracking docs; keep local only
Browse filesCo-authored-by: Cursor <cursoragent@cursor.com>
- docs/SETUP_LOG.md +0 -142
docs/SETUP_LOG.md
DELETED
|
@@ -1,142 +0,0 @@
|
|
| 1 |
-
# Project Setup and Troubleshooting Log
|
| 2 |
-
|
| 3 |
-
Record of the setup work, design decisions, problems encountered, and remaining steps for the Oxford-IIIT Pet breed and species classifier. Last updated October 17, 2026.
|
| 4 |
-
|
| 5 |
-
## 1. Design Decisions
|
| 6 |
-
|
| 7 |
-
| Decision | Choice | Rationale |
|
| 8 |
-
|---|---|---|
|
| 9 |
-
| Models | Scratch CNN (`PetBreedCNN`) plus pretrained ResNet18 baseline | Both satisfy the rubric (at least 2 layers). Training both allows a direct, documented comparison. |
|
| 10 |
-
| Deployed model | ResNet18 (pretrained, fine-tuned) | Expected to generalize better from roughly 100 images per breed. The notebook checks this against validation results before export. |
|
| 11 |
-
| Python version | 3.14 | Project preference. Local `.venv` runs 3.14.0. Colab runs 3.13, and the code is compatible with both. |
|
| 12 |
-
| Packaging | Application project, no build backend (`package = false`) | The code lives in `src/` and is imported directly. It is not a distributable package. |
|
| 13 |
-
| Model selection | Validation metrics, never the test set | Keeps the test set an unbiased estimate of generalization. |
|
| 14 |
-
| ResNet18 learning rates | 0.001 for the new head, 0.0001 for the pretrained backbone | A rate of 0.001 on the backbone risks damaging pretrained features. The head still starts at the specified 0.001. |
|
| 15 |
-
| Latency definition | Forward pass plus softmax, per `CLAUDE.md` | Preprocessing time is returned separately by `predict_image`. |
|
| 16 |
-
|
| 17 |
-
## 2. Repository Fixes
|
| 18 |
-
|
| 19 |
-
1. **Python version.** `.python-version` and `pyproject.toml` use 3.14. The README Space metadata sets `python_version: '3.14'`.
|
| 20 |
-
2. **Packaging.** Removed the `uv_build` backend and the broken `pet_classifier:main` script entry from `pyproject.toml`. Listed the real dependencies. Replaced the `src/__init__.py` stub with a docstring-only package marker.
|
| 21 |
-
3. **`.gitignore`.**
|
| 22 |
-
- Stopped ignoring `pyproject.toml` and `.python-version`.
|
| 23 |
-
- Added `data/`, `checkpoints/`, `*.ckpt`, `.ipynb_checkpoints/`, and `.DS_Store`.
|
| 24 |
-
- Corrected the `claude.markdown` entry to `CLAUDE.md`.
|
| 25 |
-
- Added `data/.gitignore`.
|
| 26 |
-
4. **README.** Removed the emoji and rewrote it as project documentation. The Hugging Face Space YAML header is preserved.
|
| 27 |
-
|
| 28 |
-
## 3. Files Created
|
| 29 |
-
|
| 30 |
-
| File | Purpose |
|
| 31 |
-
|---|---|
|
| 32 |
-
| `src/model.py` | `PetBreedCNN` (four double-convolution blocks, adaptive pooling, Linear and Dropout head) and `build_resnet18_classifier` |
|
| 33 |
-
| `src/dataset.py` | Transforms, stratified 80/20 train/validation split of `trainval`, and DataLoaders (batch size 32, 2 workers) |
|
| 34 |
-
| `src/utils.py` | Class names, `CAT_BREEDS`, species mapping, timed `predict_image`, training loop with `ReduceLROnPlateau` and early stopping, metrics, and plots |
|
| 35 |
-
| `notebooks/train.ipynb` | Full training and evaluation workflow for Colab, including design justification |
|
| 36 |
-
| `app.py` | Gradio interface that loads `pet_breed_model.pth` (ResNet18) |
|
| 37 |
-
| `requirements.txt` | Pinned production dependencies: `torch`, `torchvision`, `gradio`, `Pillow`, `numpy` |
|
| 38 |
-
|
| 39 |
-
## 4. Verification Performed
|
| 40 |
-
|
| 41 |
-
- Imported `torch`, `torchvision`, `gradio`, `Pillow`, and `numpy` successfully on Python 3.14.
|
| 42 |
-
- Confirmed the 37 class names and label order against the downloaded `torchvision.datasets.OxfordIIITPet`.
|
| 43 |
-
- Confirmed that the static `CAT_BREEDS` mapping agrees with the dataset's own cat/dog annotation for all 37 breeds (12 cat, 25 dog).
|
| 44 |
-
- Ran synthetic tests of model output shapes, the stratified split, the training loop with early stopping, metrics, plots, and timed inference, including RGBA image input.
|
| 45 |
-
- Ran `app.py` with temporary random weights. It returns the top-3 breeds, species, and latency, handles an empty upload with a clear message, and reports a clear error when the weights file is empty.
|
| 46 |
-
- Ran the entire notebook end to end with `PET_QUICK_RUN=1` (tiny subset, 1 epoch per model). The reloaded weights reproduced the trained network's outputs. Accuracy values from that run are not meaningful.
|
| 47 |
-
|
| 48 |
-
## 5. Problems Encountered and Solutions
|
| 49 |
-
|
| 50 |
-
### 5.1 SSL certificate error when downloading the dataset (macOS)
|
| 51 |
-
|
| 52 |
-
- **Symptom:** `CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate` from `OxfordIIITPet(download=True)`.
|
| 53 |
-
- **Cause:** The python.org build of Python on macOS does not ship with a certificate bundle.
|
| 54 |
-
- **Fix:** Run the "Install Certificates.command" script that comes with that Python installation. As a one-off alternative, set `SSL_CERT_FILE` to the `certifi` bundle:
|
| 55 |
-
```bash
|
| 56 |
-
SSL_CERT_FILE="$(.venv/bin/python -c 'import certifi; print(certifi.where())')" <command>
|
| 57 |
-
```
|
| 58 |
-
|
| 59 |
-
### 5.2 Notebook error in Colab: `No module named 'src'`
|
| 60 |
-
|
| 61 |
-
- **Symptom:** `ModuleNotFoundError: No module named 'src'` in the imports cell.
|
| 62 |
-
- **Cause:** The setup cell clones the Hugging Face Space repository to obtain `src/`, but `src/` had not been pushed to the Space yet.
|
| 63 |
-
- **Fix:** Push `src/` and the notebook to the Space, or upload a zip of `src/` to `/content/pet_classifier/` in Colab and unzip it.
|
| 64 |
-
- **Notebook change:** The setup cell now stops with a clear message if `src/model.py` is missing.
|
| 65 |
-
|
| 66 |
-
### 5.3 Notebook error in Colab: `git clone` exit status 128
|
| 67 |
-
|
| 68 |
-
- **Symptom:** `CalledProcessError` from `git clone` on re-running the setup cell.
|
| 69 |
-
- **Cause:** The first run created `/content/pet_classifier` without `src/`. Each re-run saw no `src/` and attempted to clone again. Git refuses to clone into an existing non-empty folder.
|
| 70 |
-
- **Fix:** The setup cell now runs `git pull` when the folder is already a clone and clones only on the first run.
|
| 71 |
-
|
| 72 |
-
### 5.4 `git add .` fails: `git-lfs: command not found`
|
| 73 |
-
|
| 74 |
-
- **Symptom:**
|
| 75 |
-
```text
|
| 76 |
-
git-lfs filter-process: git-lfs: command not found
|
| 77 |
-
fatal: the remote end hung up unexpectedly
|
| 78 |
-
```
|
| 79 |
-
- **Cause:** `.gitattributes` routes `*.pth` (and other model file types) through Git LFS, and `git-lfs` was not installed locally. Hugging Face also requires LFS for files over 10 MB.
|
| 80 |
-
- **Fix:** `git-lfs` is a standalone program, not a Python package, so `uv` cannot install it. Use Homebrew:
|
| 81 |
-
```bash
|
| 82 |
-
brew install git-lfs
|
| 83 |
-
git lfs install
|
| 84 |
-
git lfs version
|
| 85 |
-
```
|
| 86 |
-
|
| 87 |
-
### 5.5 Hugging Face build error: torch version not compatible with ZeroGPU
|
| 88 |
-
|
| 89 |
-
- **Symptom:** The Space build reported that the `torch` version in `requirements.txt` is not compatible with ZeroGPU, and listed supported versions 2.8.0 through 2.13.0.
|
| 90 |
-
- **Cause:** The Space was set to ZeroGPU hardware. According to the Hugging Face ZeroGPU documentation, ZeroGPU supports only PyTorch 2.8.0 to 2.13.0 and only Python 3.12.12 and 3.10.13. It also requires the `spaces` package and a `@spaces.GPU` decorator on the inference function. This project pins `torch==2.14.1` and Python 3.14.
|
| 91 |
-
- **Resolution:** Run the Space on free CPU hardware (Settings > Space hardware), which is permitted by the project guidelines and keeps Python 3.14 and the pinned versions. After the change, the Space built successfully and reached application startup. A ResNet18 forward pass on CPU takes on the order of tens of milliseconds, so a GPU is not needed.
|
| 92 |
-
- **If ZeroGPU is required later:** set `python_version: '3.12'`, pin `torch` to 2.13.0 with the matching `torchvision`, add `spaces` to `requirements.txt`, and decorate the prediction function with `@spaces.GPU`.
|
| 93 |
-
|
| 94 |
-
### 5.6 Hugging Face startup error: model weights not found or empty
|
| 95 |
-
|
| 96 |
-
- **Symptom:** `FileNotFoundError: Model weights not found or empty at '/app/pet_breed_model.pth'`.
|
| 97 |
-
- **Cause:** The repository contains the 0-byte placeholder `pet_breed_model.pth`. This is the intended behavior of `app.py` until trained weights are added.
|
| 98 |
-
- **Resolution:** Train the model in Colab, add the downloaded `pet_breed_model.pth` to the repository root, and push it through Git LFS (see Remaining Steps).
|
| 99 |
-
|
| 100 |
-
### 5.7 Trained weights not downloaded to the local machine
|
| 101 |
-
|
| 102 |
-
- **Symptom:** Training completed, but no `pet_breed_model.pth` appeared in `~/Downloads`.
|
| 103 |
-
- **Cause:** The notebook runs through the VS Code Colab extension, not a browser. `google.colab.files.download()` relies on browser JavaScript, so it silently does nothing in that setup. The weights remained in the Colab runtime at `/content/pet_classifier/pet_breed_model.pth`.
|
| 104 |
-
- **Fix:** The final notebook cell now uploads the weights directly to the Hugging Face Space with `huggingface_hub.HfApi.upload_file`. It prompts for a write token with `getpass` (or reads `HF_TOKEN`), so the token is never stored in the notebook. After the upload, run `git pull` locally to retrieve the weights.
|
| 105 |
-
|
| 106 |
-
### 5.8 Local history rewritten and `origin` remote removed
|
| 107 |
-
|
| 108 |
-
- **Symptom:** `git fetch origin` failed with `'origin' does not appear to be a git repository`, and `git status` showed no upstream branch.
|
| 109 |
-
- **Cause:** `git filter-repo --path data --invert-paths --force` was run to strip the `data/` folder from history. This rewrote every commit hash and, by design, removed the `origin` remote (`https://huggingface.co/spaces/deeAdora/pet_classifier`). The local history no longer shares commits with the Space.
|
| 110 |
-
- **Consequence:** A normal `git push` is rejected. The remote must be re-added, and publishing either replaces the Space history (force push) or builds a new commit on top of the existing Space history.
|
| 111 |
-
|
| 112 |
-
## 6. Remaining Steps
|
| 113 |
-
|
| 114 |
-
1. Done: Git LFS installed (section 5.4).
|
| 115 |
-
2. Done: code pushed to the Space. Hugging Face prompts for a username and a write access token (create one at huggingface.co/settings/tokens). The Space shows a startup error until the trained weights are added (section 5.6).
|
| 116 |
-
3. Done: trained both models in Colab (T4). Results are recorded in section 7.
|
| 117 |
-
4. Done: the weights were uploaded to the Space (section 5.7). The live Space was tested and classified a sample Abyssinian correctly.
|
| 118 |
-
5. Confirm the Space builds and test it with several pet photos.
|
| 119 |
-
6. Record the final test metrics, confusion-matrix findings, and latency figures from the notebook for the course write-up.
|
| 120 |
-
|
| 121 |
-
## 7. Training Results (Colab T4, test set of 3,669 images)
|
| 122 |
-
|
| 123 |
-
| Model | Breed accuracy | Macro F1 | Species accuracy | CPU latency (mean, single image) |
|
| 124 |
-
|---|---|---|---|---|
|
| 125 |
-
| ResNet18 (pretrained) | 0.8714 | 0.8687 | 0.9891 | about 52 ms |
|
| 126 |
-
| Scratch CNN | 0.1496 | 0.1160 | 0.7024 | about 81 ms |
|
| 127 |
-
|
| 128 |
-
- ResNet18 reached 0.9253 validation accuracy at its best epoch (10 of 14, stopped early) and is the deployed model.
|
| 129 |
-
- The scratch CNN trained for all 40 epochs, ended near 10 percent training accuracy, and was still improving. This indicates underfitting rather than overfitting.
|
| 130 |
-
- The most frequent ResNet18 confusions are between visually similar breeds, for example American Pit Bull Terrier predicted as Staffordshire Bull Terrier, and Ragdoll with Birman.
|
| 131 |
-
|
| 132 |
-
## 8. Interface Changes (October 30, 2026)
|
| 133 |
-
|
| 134 |
-
- `app.py` now shows a gallery of sample photos from `images/` as clickable thumbnails below the upload area. The photos are discovered automatically, so adding a file to `images/` adds an example. Selecting a thumbnail loads it into the upload area, and the user then presses Submit.
|
| 135 |
-
- Sample photos were checked against the deployed model. The American Bulldog photo was predicted as American Pit Bull Terrier (a known confusion pair), and the Egyptian Mau photo was predicted as a Chihuahua. Both were moved to `images/excluded/`, which the app does not read and git ignores.
|
| 136 |
-
- `codeWithNotes/` contains annotated copies of the source files, with explanations enclosed in `# region` / `# endregion` blocks that can be collapsed in the editor.
|
| 137 |
-
|
| 138 |
-
## 9. Open Items
|
| 139 |
-
|
| 140 |
-
- The Space metadata sets `python_version: '3.14'`. The Space has built and started with it on CPU hardware, so Hugging Face accepted that version. The Space hardware setting should be confirmed as CPU Basic (section 5.5).
|
| 141 |
-
- Publishing the interface changes (section 8) requires reconnecting the `origin` remote and reconciling the rewritten history (section 5.8).
|
| 142 |
-
- The scratch CNN underfit. It remains a valid baseline for comparison, but a longer schedule or a larger network would be needed to improve it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|