Skip to content

Feat/containerize - #6

Merged
notsubash merged 5 commits into
mainfrom
feat/containerize
Aug 22, 2026
Merged

notsubash merged 5 commits into
mainfrom
feat/containerize

Conversation

@notsubash

@notsubash notsubash commented Aug 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

Ship a CPU inference path for the honest watch model, plus the CI/Makefile/docs needed to reproduce and talk about the numbers without leaking the student notebook split.

The headline result does not change: Protocol B watch statistical XGBoost is 0.7031 macro-F1. Phone under the same protocol is 0.3272. The student 0.8559 accuracy is Protocol A only (leaky windows, same people in train and test). This PR makes that distinction the default story in the README, and it makes the watch tree runnable as an API.

Serving

  • python -m har.models.export fits one device from a train YAML and writes ONNX (XGBoost trees via onnxmltools) plus a sidecar JSON. joblib is the fallback for stubs / non-XGB.
  • FastAPI app (har.serve.app) exposes GET /health, GET /labels, POST /predict for one 5 s / 20 Hz window (T=100, C=6). Wrong T, C, device, or hz is 422. Body over 1 MiB is 413.
  • Statistical features still run in Python. Only the tree head is ONNX. Export forces device: cpu even if the YAML says cuda.
  • Docker image (serving/Dockerfile) is inference-only: numpy, FastAPI, uvicorn, onnxruntime. It does not install MLflow, XGBoost, or pyarrow. Build from the repo root, mount models/.
  • Default bundle to serve is watch statistical XGBoost (configs/protocol_b_watch_stat_xgb.yaml). Phone is a different model; do not send phone windows to a watch bundle.

The served fit is a refit on all windows (one subject held out only for early stopping). Cite GroupKFold numbers from docs/reports/, not from the export command. Abstain is max(proba) < threshold with default 0.0 (never abstain). Uncalibrated.

Evaluation and docs

  • har.eval.plots builds the README ladder, leakage, ablation, per-class, and per-group figures from docs/reports/. make eval / make figures keep those images aligned with the JSON.
  • Training logs fold macro-F1 / accuracy, per-group F1, a per-class bar, and a confusion matrix to MLflow. Run names follow the config stem.
  • README, model card, limitations, and protocol docs now name protocol + config next to every number. Primary metric is macro-F1.

Tooling

  • GitHub Actions: Python 3.13, pip install -e ".[dev]", ruff, pytest. No WISDM download.
  • Makefile: install, test, audit, prepare, train, eval, figures, serve.
  • pyarrow pinned to 19.0.1 so it stays compatible with MLflow 2.22.5.

CI fix on this branch

models/ in .gitignore matched any directory named models, including src/har/models/. Older files in that package were already tracked; export.py was added after the ignore rule, so it never left the laptop. CI then failed with No module named 'har.models.export'. The rule is now /models/. There is a regression test so this does not come back.

The matplotlib / pydantic messages in the CI log are third-party deprecation warnings. They are not failures.

Test plan

  • python -m ruff check src tests
  • python -m pytest -q (fixtures only; 146 tests locally)
  • Confirm src/har/models/export.py is in the GitHub tree for this branch
  • Optional: python -m har.models.export --config configs/protocol_b_watch_stat_xgb.yaml --out models/watch_stat_xgb.onnx then HAR_MODEL_PATH=... make serve and hit /health + /predict
  • Optional: docker build -f serving/Dockerfile -t har-api . and run with $PWD/models:/models (Git Bash needs MSYS_NO_PATHCONV=1)

Out of scope

No TCN / 1D CNN. Hierarchical does not beat flat 18-way macro-F1 and cannot be exported (predict_proba). Protocol C is still 46/5 x 3, not 51-fold LOSO. Concat is stacked 6-channel windows, not 12-channel phone+watch fusion.

notsubash and others added 5 commits August 22, 2026 20:37
This commit introduces a new FastAPI application for serving the Human Activity Recognition (HAR) model, along with Docker support for deployment. Key changes include:

- Creation of a FastAPI app with endpoints for health checks, label retrieval, and predictions based on input data.
- Implementation of a Dockerfile to facilitate containerization of the application, ensuring a lightweight and reproducible environment.
- Addition of a .dockerignore file to exclude unnecessary files from the Docker context.
- Updates to the pyproject.toml to include new dependencies for ONNX model handling and HTTP client testing.
- Comprehensive documentation updates, including a new model card and serving instructions in the README.

These enhancements enable efficient deployment and usage of the HAR model in production environments, improving accessibility and usability for end-users.
…lation

This commit introduces a new CI workflow and a Makefile to facilitate testing and installation processes. Key changes include:

- Creation of a `.github/workflows/ci.yml` file to automate testing with Python 3.12, including steps for installing dependencies, running Ruff for linting, and executing pytest for tests.
- Addition of a `Makefile` with targets for installation, testing, auditing, preparing data, training, evaluating, and serving the model.
- Updates to `.editorconfig` and `.gitattributes` to ensure consistent formatting and line endings for the Makefile across different environments.

These enhancements improve the development workflow by automating testing and providing a clear structure for project setup and execution.
This commit includes several key updates:

- Downgraded `pyarrow` dependency from `23.0.1` to `19.0.1` to ensure compatibility with MLflow 2.22.5.
- Updated the CI configuration in `.github/workflows/ci.yml` to use Python 3.13.
- Rewritten sections of the `README.md` to provide clearer insights into model performance metrics and evaluation protocols, emphasizing the primary metric of macro-F1.
- Improved the `data/README.md` to clarify the checksum handling for dataset integrity.
- Enhanced documentation across various files, including `docs/data_card.md`, `docs/limitations.md`, and `docs/model_card.md`, to better reflect the current state of the project and its methodologies.

These changes improve the overall clarity, compatibility, and usability of the project.
This commit introduces several key updates to the evaluation framework:

- Added a new `figures` target in the Makefile to generate visualizations from evaluation reports.
- Integrated `matplotlib` for plotting and added new functions to create confusion matrices and per-class F1 score visualizations.
- Updated `README.md` to include instructions for generating figures and added new images to the documentation.
- Introduced new dependencies in `pyproject.toml` for `matplotlib`.
- Enhanced the `evaluate.py` script to automatically generate figures after summarizing reports.
- Added unit tests for the new plotting functionalities to ensure correctness.

These changes improve the project's ability to visualize and interpret model performance metrics, facilitating better insights into evaluation results.
… it.

Co-authored-by: Cursor <cursoragent@cursor.com>
@notsubash
notsubash merged commit 2cee6ff into main Aug 22, 2026
2 checks passed
@notsubash
notsubash deleted the feat/containerize branch August 22, 2026 15:50
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