Skip to content

Unit support: units on upload, unit conversion in OnnxPredictor - #23

Merged
hamza-aamer merged 1 commit into
mainfrom
feat/units
Nov 4, 2026
Merged

hamza-aamer merged 1 commit into
mainfrom
feat/units

Conversation

@hamza-aamer

Copy link
Copy Markdown
Contributor

Part of edge-ml/edge-ml#91 (follow-up to #85).

Uploads

  • datasetCollector and sendDataset take { name, unit, quantity } per time-series and send it on dataset init. Plain names are still sent as plain strings, so existing apps and servers without unit support keep working.

Predictor

  • OnnxPredictor.inputUnits: expected unit per input, read from manifest.input.units.
  • Apps declare what their sensors deliver (loadModel(url, key, id, { units: { accX: "g" } }) or predictor.setUnits(...)); values are converted with the conversions shipped in the manifest before predicting (buffered values and predictWindow).
  • A unit the model can't convert from throws a UnitError listing the accepted units.
  • Models trained before units existed, or on unknown units, get values unchanged even if units are declared.
  • Unit ids by default; pass catalog to also accept labels/aliases like °F, m/s².

Other

  • fetchUnits(url) returns GET /ml/units/.
  • Types, README, browser example (declares m/s² for devicemotion).
  • Tests (__tests__/test_units.js, fixtures generated from the ml service's own unit code): conversion, buffered conversion, errors, catalog aliases, backwards compatibility with the existing pre-units fixtures, upload payloads.

Checked

  • npm test 44/44, npm run test:browser ok.
  • Live on beta.edge-ml.org: uploaded datasets in m/s² (collector) and g (sendDataset), units stored; trained on both → model expects m/s²; loaded with g declared → same scores as feeding m/s² directly, 10/10 correct labels; UnitError for degC.

Release note: the version is not bumped here on purpose: npm-publish.yml publishes as soon as package.json has a newer version (also on PR runs). Bump to 4.1.0 when this should go out. Uploading with units needs #85 on the server; prod doesn't have it yet (plain names keep working there).

- datasetCollector and sendDataset accept { name, unit, quantity } per
  time-series and send them when the dataset is created; plain names are
  still sent as plain strings
- OnnxPredictor reads input.units from the manifest (inputUnits), converts
  declared sensor units (units option / setUnits) to the expected unit and
  throws a UnitError for units the model cannot convert from
- models without unit information keep getting values unchanged
- fetchUnits(url) returns the server's unit catalog (GET /ml/units/)
- README, example and types updated
@hamza-aamer
hamza-aamer merged commit 2556917 into main Nov 4, 2026
2 checks passed
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