HW2/code — Detailed developer guide
This document explains the code-level entry points, how to run experiments reproducibly, and where outputs are saved.
Primary scripts & purpose
tabular.py— training pipeline for Pima diabetes dataset (downloads fallback / synthetic if offline).models.py—MLPClassifierandNAMClassifierused in experiments.interpretability.py— LIME and SHAP wrappers for per-sample explanations.vision.py— Grad-CAM, Guided Backprop, SmoothGrad, and activation maximization utilities.generate_report_plots.py— convenience script to create PNGs used in the LaTeX report.
How to reproduce the tabular baseline
Create environment and install (see
requirements.txt).Run:
cd HomeWorks/HW2/code python tabular.pytabular.pyuses localdiabetes.csvif present, otherwise attempts to download; it falls back to a deterministic synthetic dataset when offline.
Generated metrics are printed to stdout; use
generate_report_plots.pyto export figures.
Vision experiments & explanations
- The notebook
../notebooks/HW2_solution.ipynbdemonstrates how to load models, compute Grad-CAM maps, combine Guided Backprop + Grad-CAM, and run activation maximization. vision.pycontains reusable functions so you can call them programmatically from other scripts/notebooks.- Custom six-image set: to use your own images for the vision six-image analysis, pass
custom_image_paths=[...]togenerate_vision_figures()ingenerate_report_plots.py, or set the env varHW2_VISION_IMAGES(comma-separated paths or URLs). See the main HW2 README for details.
Notes on interpretability tools
- LIME/SHAP can be slow for larger datasets; use
n_samples/nsamplesparameters to limit runtime. - SHAP
KernelExplaineris model-agnostic but computationally expensive — use a small background subset for demos.
Expected outputs
report/figures/— standard plots used in the assignment report (saved bygenerate_report_plots.py).- Notebook cells include figure exports and the code used to generate them.
Troubleshooting & tips
- No internet: tabular dataset fallback ensures the notebook is runnable offline.
- Pretrained weights unavailable:
vision.pytries a non-pretrained fallback; visualizations still work but results differ.
If you want, I can add explicit CLI flags to tabular.py and vision.py for dataset path, device selection, and logging to make experiments even more reproducible.
Xet Storage Details
- Size:
- 2.58 kB
- Xet hash:
- 176ba19160bf6546053444a2251f8a8ba86c0c5a3e14c8fd2a5733cb3ab9ce06
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.