@mauriciobenjamin700/ort-vision-sdk-web 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/README.md +26 -0
  3. package/dist/core/graph.d.ts +60 -0
  4. package/dist/core/graph.d.ts.map +1 -0
  5. package/dist/core/graph.js +68 -0
  6. package/dist/core/graph.js.map +1 -0
  7. package/dist/core/session.d.ts +27 -2
  8. package/dist/core/session.d.ts.map +1 -1
  9. package/dist/core/session.js +33 -2
  10. package/dist/core/session.js.map +1 -1
  11. package/dist/core/timing.d.ts +52 -0
  12. package/dist/core/timing.d.ts.map +1 -0
  13. package/dist/core/timing.js +46 -0
  14. package/dist/core/timing.js.map +1 -0
  15. package/dist/index.d.ts +2 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +3 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/postprocess/detection.d.ts +2 -2
  20. package/dist/postprocess/detection.js +4 -4
  21. package/dist/postprocess/segmentation.d.ts +1 -1
  22. package/dist/postprocess/segmentation.js +2 -2
  23. package/dist/results.d.ts +8 -6
  24. package/dist/results.d.ts.map +1 -1
  25. package/dist/results.js +12 -3
  26. package/dist/results.js.map +1 -1
  27. package/dist/tasks/classifier.d.ts +15 -1
  28. package/dist/tasks/classifier.d.ts.map +1 -1
  29. package/dist/tasks/classifier.js +24 -2
  30. package/dist/tasks/classifier.js.map +1 -1
  31. package/dist/tasks/detector.d.ts +21 -2
  32. package/dist/tasks/detector.d.ts.map +1 -1
  33. package/dist/tasks/detector.js +30 -3
  34. package/dist/tasks/detector.js.map +1 -1
  35. package/dist/tasks/segmenter.d.ts +15 -1
  36. package/dist/tasks/segmenter.d.ts.map +1 -1
  37. package/dist/tasks/segmenter.js +25 -2
  38. package/dist/tasks/segmenter.js.map +1 -1
  39. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,92 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.0] - 2026-08-03
11
+
12
+ ### Added
13
+
14
+ - **Tasks read their input resolution off the model instead of trusting
15
+ configuration.** `Classifier`, `Detector` and `Segmenter` now ask the ONNX
16
+ graph what shape it declares and preprocess to that. The resolution a session
17
+ must be fed at is a property of the export — feeding a 640x640 tensor to a
18
+ graph exported at 224x224 makes ORT abort mid-run with:
19
+
20
+ ```text
21
+ Inference failed: failed to call OrtRun(). ERROR_CODE: 2, ERROR_MESSAGE: Got
22
+ invalid dimensions for input: images for the following indices index: 2
23
+ Got: 640 Expected: 224
24
+ ```
25
+
26
+ A caller had no way to see that coming: the number lives in the file. So it is
27
+ read from there now.
28
+
29
+ ```typescript
30
+ // An Ultralytics -cls export is 224; nothing to configure, nothing to get wrong
31
+ const clf = await Classifier.create("/models/classify.onnx", { labels: LABELS });
32
+ console.log(clf.inputSize); // [224, 224]
33
+ ```
34
+
35
+ `inputSize` is now a *fallback*, used only when the graph leaves its spatial
36
+ axes dynamic. Passing a size that contradicts a static graph logs a warning
37
+ and the graph wins — honoring the caller there would only turn a fixable
38
+ mismatch into a failed run.
39
+
40
+ - **`inputSize` getter on every task**, so callers can read back the resolution
41
+ inference actually runs at rather than the one they asked for.
42
+
43
+ - **`OrtSession.inputShapes` / `OrtSession.inputShape`** expose what the graph
44
+ declares, with dynamic axes as `null`. Empty when the runtime reports no
45
+ metadata (`onnxruntime-web` older than 1.21).
46
+
47
+ - **`OrtSession.release()`** frees the native session. Needed whenever a session
48
+ is discarded while the page lives on — rebuilding a task at a different input
49
+ size, swapping in a newer model — which previously required reaching into
50
+ `session.raw`.
51
+
52
+ - **`declaredShapesFrom`, `spatialInputSize`, `resolveInputSize`** (plus the
53
+ `DeclaredShape` / `DeclaredDim` types): the pure helpers behind the above,
54
+ exported so callers building their own pipeline can reuse the same precedence
55
+ rules without importing `onnxruntime-web` types themselves.
56
+
57
+ ## [0.3.0] - 2026-08-02
58
+
59
+ ### Added
60
+
61
+ - **`predict()` now reports where the time went.** Every `Results` envelope
62
+ already carried a `speed` field, mirroring Ultralytics' `results[0].speed` —
63
+ and it was always empty, because no task ever filled it. `Classifier`,
64
+ `Detector` and `Segmenter` now time each stage and hand the breakdown to the
65
+ envelope:
66
+
67
+ ```typescript
68
+ const results = await det.predict("/images/street.jpg");
69
+ console.log(results[0].speed);
70
+ // { load: 84.2, preprocess: 11.7, inference: 118.9, postprocess: 6.4 }
71
+ ```
72
+
73
+ Four keys instead of Ultralytics' three: `preprocess`, `inference` and
74
+ `postprocess` measure the same boundaries Ultralytics does, and `load` covers
75
+ the fetch/decode this SDK performs inside `predict()` — on a cold cache it
76
+ dominates everything else, and folding it into `preprocess` would misreport
77
+ where the cost is.
78
+
79
+ New exports `Speed` (the four-key breakdown) and `SpeedTimer` (the stage
80
+ accumulator) let callers time their own pipeline stages around the SDK calls
81
+ using the same boundaries.
82
+
83
+ ### Changed
84
+
85
+ - `Results.speed` is typed `Readonly<Speed>` instead of
86
+ `Readonly<Record<string, number>>`, so `speed.inference` is a `number` rather
87
+ than `number | undefined`. Envelopes built by hand default to all-zeros.
88
+
89
+ ### Deprecated
90
+
91
+ - The `decodeYoloV8` / `decodeYoloV8Anchors` / `decodeYoloV8Seg` aliases were
92
+ announced for removal in `0.3.0`. They survive this release — dropping them
93
+ would break `tempest-react-sdk`, which re-exports all three from its vendored
94
+ copy. The warning now points at `0.4.0`.
95
+
10
96
  ## [0.2.1] - 2026-05-03
11
97
 
12
98
  First **published** release on npm. The previous `0.2.0` tag never produced a
package/README.md CHANGED
@@ -4,6 +4,11 @@
4
4
  [![GitHub](https://img.shields.io/badge/github-mauriciobenjamin700%2Fort--vision--sdk-181717?logo=github)](https://github.com/mauriciobenjamin700/ort-vision-sdk)
5
5
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/mauriciobenjamin700/ort-vision-sdk/blob/main/sdk-js-web/LICENSE)
6
6
 
7
+ > **Documentation / Docs (bilingual):**
8
+ > [Português (BR)](https://mauriciobenjamin700.github.io/ort-vision-sdk/) ·
9
+ > [English (US)](https://mauriciobenjamin700.github.io/ort-vision-sdk/en/) —
10
+ > use the PT-BR / EN-US selector at the top of the site to switch language.
11
+
7
12
  High-level TypeScript SDK for browser computer vision inference on top of [ONNX Runtime Web](https://onnxruntime.ai/docs/get-started/with-javascript/web.html).
8
13
 
9
14
  Mirrors the Python [`ort-vision-sdk`](https://pypi.org/project/ort-vision-sdk/) API: task-oriented classes (`Classifier`, `Detector`) that handle image loading, preprocessing, execution-provider selection and postprocessing. Output is the same typed shape as the Python version (`ClassificationResult`, `DetectionResult`, `BoundingBox`).
@@ -32,8 +37,17 @@ const result = await clf.predict("/images/dog.jpg", { topK: 5 });
32
37
  console.log(result.className, result.confidence);
33
38
  console.log(result.probabilities);
34
39
  // result.image is an RGBImage (HWC RGB Uint8Array) — the original input.
40
+ console.log(clf.inputSize);
41
+ // [224, 224] — read from the .onnx graph, not configured.
35
42
  ```
36
43
 
44
+ > **The model decides its input size.** `inputSize` is optional: the resolution
45
+ > the graph declares always wins, because it is the only shape ONNX Runtime will
46
+ > accept. An Ultralytics `-cls` export is 224x224 while a detector is 640x640 —
47
+ > get it wrong and ORT aborts with `Got invalid dimensions for input: images`.
48
+ > Read it back with `task.inputSize`, or inspect `session.inputShape`. See
49
+ > [O modelo manda / The model decides](https://mauriciobenjamin700.github.io/ort-vision-sdk/en/guia/modelo/).
50
+
37
51
  ### Object detection
38
52
 
39
53
  ```typescript
@@ -52,6 +66,18 @@ for (const d of detections) {
52
66
  }
53
67
  ```
54
68
 
69
+ ## Inference speed
70
+
71
+ Every result envelope carries a per-stage timing breakdown:
72
+
73
+ ```typescript
74
+ const results = await det.predict("/images/street.jpg");
75
+ console.log(results[0].speed);
76
+ // { load: 84.2, preprocess: 11.7, inference: 118.9, postprocess: 6.4 }
77
+ ```
78
+
79
+ Milliseconds. `preprocess` / `inference` / `postprocess` measure the same boundaries Ultralytics reports; `load` is the fetch/decode this SDK does inside `predict()`, which on a cold cache dominates everything else. Loading the model is *not* included — that is startup cost. Export `SpeedTimer` to time your own pipeline stages with the same boundaries.
80
+
55
81
  ## Accepted image inputs
56
82
 
57
83
  `predict(image)` and `loadImage(image)` both accept:
@@ -0,0 +1,60 @@
1
+ /**
2
+ * What the ONNX graph itself says about its inputs.
3
+ *
4
+ * The resolution a session must be fed at is a property of the exported model,
5
+ * not of the configuration around it. Feeding a 640x640 tensor to a graph
6
+ * exported at 224x224 makes ORT abort the run with
7
+ * `Got invalid dimensions for input: images ... Got: 640 Expected: 224`, and the
8
+ * caller has no way to see that coming from the outside — the number lives in
9
+ * the file. So the SDK reads it from the graph and treats any configured size as
10
+ * a fallback for when the graph leaves it open.
11
+ */
12
+ import type * as ort from "onnxruntime-web";
13
+ /**
14
+ * One declared dimension: a number when the graph pins it, `null` when the
15
+ * dimension is symbolic (dynamic).
16
+ */
17
+ export type DeclaredDim = number | null;
18
+ /** A declared input/output shape, dynamic axes appearing as `null`. */
19
+ export type DeclaredShape = readonly DeclaredDim[];
20
+ /**
21
+ * Convert ORT value metadata into declared shapes.
22
+ *
23
+ * @param metadata Metadata as reported by `InferenceSession.inputMetadata`, or
24
+ * `undefined` on ORT builds that predate it (added in onnxruntime 1.21).
25
+ * @returns One shape per value, in declaration order. Non-tensor values and
26
+ * builds without metadata yield empty shapes, which read as "nothing
27
+ * declared" everywhere downstream.
28
+ */
29
+ export declare function declaredShapesFrom(metadata: readonly ort.InferenceSession.ValueMetadata[] | undefined): readonly DeclaredShape[];
30
+ /**
31
+ * Read the spatial input size out of a declared NCHW shape.
32
+ *
33
+ * @param shape The declared shape of the model's image input.
34
+ * @returns `[width, height]` in pixels, or `null` when the shape is not 4D or
35
+ * leaves either spatial axis dynamic — in which case the model accepts more
36
+ * than one resolution and there is nothing to correct.
37
+ */
38
+ export declare function spatialInputSize(shape: DeclaredShape): readonly [number, number] | null;
39
+ export interface ResolveInputSizeOptions {
40
+ /** Declared shape of the model's image input, from {@link declaredShapesFrom}. */
41
+ readonly graphShape?: DeclaredShape;
42
+ /** Size the caller asked for, if any. */
43
+ readonly requested?: readonly [number, number];
44
+ /** Size to use when neither the graph nor the caller pins one. */
45
+ readonly fallback: readonly [number, number];
46
+ }
47
+ /**
48
+ * Decide the input size a task will preprocess to.
49
+ *
50
+ * Precedence is graph → caller → fallback. The graph wins over an explicit
51
+ * `inputSize` because a static shape is not a preference, it is what ORT will
52
+ * accept: honoring the caller there would only turn a fixable mismatch into a
53
+ * failed run. A disagreement is a configuration bug in the caller, so it is
54
+ * reported through `console.warn` instead of being swallowed.
55
+ *
56
+ * @param options Graph shape, requested size and per-task fallback.
57
+ * @returns The `[width, height]` to preprocess to.
58
+ */
59
+ export declare function resolveInputSize(options: ResolveInputSizeOptions): readonly [number, number];
60
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/core/graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,KAAK,GAAG,MAAM,iBAAiB,CAAC;AAE5C;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,IAAI,CAAC;AAExC,uEAAuE;AACvE,MAAM,MAAM,aAAa,GAAG,SAAS,WAAW,EAAE,CAAC;AAEnD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,SAAS,GAAG,CAAC,gBAAgB,CAAC,aAAa,EAAE,GAAG,SAAS,GAClE,SAAS,aAAa,EAAE,CAO1B;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAMvF;AAED,MAAM,WAAW,uBAAuB;IACtC,kFAAkF;IAClF,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC;IACpC,yCAAyC;IACzC,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/C,kEAAkE;IAClE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAW5F"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * What the ONNX graph itself says about its inputs.
3
+ *
4
+ * The resolution a session must be fed at is a property of the exported model,
5
+ * not of the configuration around it. Feeding a 640x640 tensor to a graph
6
+ * exported at 224x224 makes ORT abort the run with
7
+ * `Got invalid dimensions for input: images ... Got: 640 Expected: 224`, and the
8
+ * caller has no way to see that coming from the outside — the number lives in
9
+ * the file. So the SDK reads it from the graph and treats any configured size as
10
+ * a fallback for when the graph leaves it open.
11
+ */
12
+ /**
13
+ * Convert ORT value metadata into declared shapes.
14
+ *
15
+ * @param metadata Metadata as reported by `InferenceSession.inputMetadata`, or
16
+ * `undefined` on ORT builds that predate it (added in onnxruntime 1.21).
17
+ * @returns One shape per value, in declaration order. Non-tensor values and
18
+ * builds without metadata yield empty shapes, which read as "nothing
19
+ * declared" everywhere downstream.
20
+ */
21
+ export function declaredShapesFrom(metadata) {
22
+ if (metadata === undefined)
23
+ return [];
24
+ return metadata.map((value) => value.isTensor
25
+ ? value.shape.map((dim) => (typeof dim === "number" && Number.isInteger(dim) && dim > 0 ? dim : null))
26
+ : []);
27
+ }
28
+ /**
29
+ * Read the spatial input size out of a declared NCHW shape.
30
+ *
31
+ * @param shape The declared shape of the model's image input.
32
+ * @returns `[width, height]` in pixels, or `null` when the shape is not 4D or
33
+ * leaves either spatial axis dynamic — in which case the model accepts more
34
+ * than one resolution and there is nothing to correct.
35
+ */
36
+ export function spatialInputSize(shape) {
37
+ if (shape.length !== 4)
38
+ return null;
39
+ const height = shape[2];
40
+ const width = shape[3];
41
+ if (height === null || height === undefined || width === null || width === undefined)
42
+ return null;
43
+ return [width, height];
44
+ }
45
+ /**
46
+ * Decide the input size a task will preprocess to.
47
+ *
48
+ * Precedence is graph → caller → fallback. The graph wins over an explicit
49
+ * `inputSize` because a static shape is not a preference, it is what ORT will
50
+ * accept: honoring the caller there would only turn a fixable mismatch into a
51
+ * failed run. A disagreement is a configuration bug in the caller, so it is
52
+ * reported through `console.warn` instead of being swallowed.
53
+ *
54
+ * @param options Graph shape, requested size and per-task fallback.
55
+ * @returns The `[width, height]` to preprocess to.
56
+ */
57
+ export function resolveInputSize(options) {
58
+ const graph = options.graphShape === undefined ? null : spatialInputSize(options.graphShape);
59
+ const requested = options.requested;
60
+ if (graph === null)
61
+ return requested ?? options.fallback;
62
+ if (requested !== undefined && (requested[0] !== graph[0] || requested[1] !== graph[1])) {
63
+ console.warn(`[ort-vision-sdk] The model declares a ${graph[0]}x${graph[1]} input; ` +
64
+ `ignoring the requested ${requested[0]}x${requested[1]}, which ONNX Runtime would reject.`);
65
+ }
66
+ return graph;
67
+ }
68
+ //# sourceMappingURL=graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/core/graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAaH;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAAmE;IAEnE,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACtC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAC5B,KAAK,CAAC,QAAQ;QACZ,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CA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K,CAAC;AACf,CAAC"}
@@ -2,6 +2,7 @@
2
2
  * Thin wrapper around `onnxruntime-web` `InferenceSession` with typed metadata.
3
3
  */
4
4
  import type * as ort from "onnxruntime-web";
5
+ import { type DeclaredShape } from "./graph.js";
5
6
  /** Anything `InferenceSession.create` accepts. */
6
7
  export type ModelSource = string | ArrayBufferLike | Uint8Array;
7
8
  export interface OrtSessionOptions {
@@ -13,8 +14,9 @@ export interface OrtSessionOptions {
13
14
  /**
14
15
  * Wrap an ONNX Runtime Web `InferenceSession` with convenient metadata access.
15
16
  *
16
- * The wrapper exposes input/output names, manages execution-provider
17
- * selection, and provides a typed {@link OrtSession.run} method.
17
+ * The wrapper exposes input/output names and the shapes the graph declares,
18
+ * manages execution-provider selection, provides a typed {@link OrtSession.run}
19
+ * method, and releases the native session through {@link OrtSession.release}.
18
20
  */
19
21
  export declare class OrtSession {
20
22
  private readonly _session;
@@ -34,6 +36,29 @@ export declare class OrtSession {
34
36
  get inputName(): string;
35
37
  /** Names of the model's outputs, in declaration order. */
36
38
  get outputNames(): readonly string[];
39
+ /**
40
+ * Shapes the graph declares for its inputs, in declaration order.
41
+ *
42
+ * Dynamic (symbolic) axes appear as `null`. Empty shapes mean the runtime
43
+ * reported no metadata — either a non-tensor input, or an `onnxruntime-web`
44
+ * older than 1.21, which predates input metadata.
45
+ */
46
+ get inputShapes(): readonly DeclaredShape[];
47
+ /**
48
+ * Shape the graph declares for its first input, dynamic axes as `null`.
49
+ *
50
+ * Empty when the runtime reports no metadata for it.
51
+ */
52
+ get inputShape(): DeclaredShape;
53
+ /**
54
+ * Release the native session and free its memory.
55
+ *
56
+ * Call it when a session is discarded while the page lives on — rebuilding a
57
+ * task at a different input size, swapping in a newer model. A failure from
58
+ * the runtime is ignored: a session being torn down has nothing left to fail
59
+ * at, and the caller is already moving on.
60
+ */
61
+ release(): Promise<void>;
37
62
  /** The underlying `onnxruntime-web` session, for advanced use cases. */
38
63
  get raw(): ort.InferenceSession;
39
64
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/core/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,KAAK,GAAG,MAAM,iBAAiB,CAAC;AAM5C,kDAAkD;AAClD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,eAAe,GAAG,UAAU,CAAC;AAEhE,MAAM,WAAW,iBAAiB;IAChC,2FAA2F;IAC3F,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,2EAA2E;IAC3E,QAAQ,CAAC,cAAc,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,cAAc,CAAC;CAC/D;AAED;;;;;GAKG;AACH,qBAAa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,QAAQ;aACT,SAAS,EAAE,SAAS,MAAM,EAAE;IAF9C,OAAO;IAKP;;;;;;OAMG;WACU,MAAM,CACjB,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,UAAU,CAAC;IA6BtB,yDAAyD;IACzD,IAAI,UAAU,IAAI,SAAS,MAAM,EAAE,CAElC;IAED,kDAAkD;IAClD,IAAI,SAAS,IAAI,MAAM,CAMtB;IAED,0DAA0D;IAC1D,IAAI,WAAW,IAAI,SAAS,MAAM,EAAE,CAEnC;IAED,wEAAwE;IACxE,IAAI,GAAG,IAAI,GAAG,CAAC,gBAAgB,CAE9B;IAED;;;;;OAKG;IACG,GAAG,CACP,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,GAChC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAWvC"}
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/core/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,KAAK,GAAG,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAE,KA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from "./exceptions.js";
6
+ import { declaredShapesFrom } from "./graph.js";
6
7
  import { resolveProviders } from "./providers.js";
7
8
  /**
8
9
  * Wrap an ONNX Runtime Web `InferenceSession` with convenient metadata access.
9
10
  *
10
- * The wrapper exposes input/output names, manages execution-provider
11
- * selection, and provides a typed {@link OrtSession.run} method.
11
+ * The wrapper exposes input/output names and the shapes the graph declares,
12
+ * manages execution-provider selection, provides a typed {@link OrtSession.run}
13
+ * method, and releases the native session through {@link OrtSession.release}.
12
14
  */
13
15
  export class OrtSession {
14
16
  _session;
@@ -63,6 +65,35 @@ export class OrtSession {
63
65
  get outputNames() {
64
66
  return this._session.outputNames;
65
67
  }
68
+ /**
69
+ * Shapes the graph declares for its inputs, in declaration order.
70
+ *
71
+ * Dynamic (symbolic) axes appear as `null`. Empty shapes mean the runtime
72
+ * reported no metadata — either a non-tensor input, or an `onnxruntime-web`
73
+ * older than 1.21, which predates input metadata.
74
+ */
75
+ get inputShapes() {
76
+ return declaredShapesFrom(this._session.inputMetadata);
77
+ }
78
+ /**
79
+ * Shape the graph declares for its first input, dynamic axes as `null`.
80
+ *
81
+ * Empty when the runtime reports no metadata for it.
82
+ */
83
+ get inputShape() {
84
+ return this.inputShapes[0] ?? [];
85
+ }
86
+ /**
87
+ * Release the native session and free its memory.
88
+ *
89
+ * Call it when a session is discarded while the page lives on — rebuilding a
90
+ * task at a different input size, swapping in a newer model. A failure from
91
+ * the runtime is ignored: a session being torn down has nothing left to fail
92
+ * at, and the caller is already moving on.
93
+ */
94
+ async release() {
95
+ await this._session.release().catch(() => undefined);
96
+ }
66
97
  /** The underlying `onnxruntime-web` session, for advanced use cases. */
67
98
  get raw() {
68
99
  return this._session;
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/core/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,i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AC,UAAU,CAAC,CAAC,CAAC,CAAC;QACzC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,MAAM,IAAI,cAAc,CAAC,sBAAsB,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0DAA0D;IAC1D,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;IACnC,CAAC;IAED;;;;;;OAMG;IACH,IAAI,WAAW;QACb,OAAO,kBAAkB,CACvB,IAAI,CAAC,QAAQ,CAAC,aAED,CACd,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,wEAAwE;IACxE,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CACP,KAAiC;QAEjC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAC9C,OAAO,MAAoC,CAAC;QAC9C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,cAAc,CACtB,qBAAsB,GAAa,CAAC,OAAO,EAAE,EAC7C,EAAE,KAAK,EAAE,GAAG,EAAE,CACf,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Per-stage timing for a single `predict()` call.
3
+ *
4
+ * Populates the `speed` field every `Results` envelope carries, mirroring
5
+ * Ultralytics' `results[0].speed`. All values are milliseconds measured with
6
+ * `performance.now()`.
7
+ */
8
+ /**
9
+ * Stage durations of one inference, in milliseconds.
10
+ *
11
+ * `preprocess`, `inference` and `postprocess` are the three keys Ultralytics
12
+ * reports, measured over the same boundaries. `load` is specific to this SDK:
13
+ * `predict()` accepts a URL, `Blob` or DOM element and decodes it internally,
14
+ * so the fetch/decode cost would otherwise be invisible — and on a cold cache
15
+ * it dominates everything else.
16
+ */
17
+ export interface Speed {
18
+ /** Fetching and decoding the input into an `RGBImage`. */
19
+ load: number;
20
+ /** Letterbox/resize, normalization and tensor packing. */
21
+ preprocess: number;
22
+ /** The ONNX Runtime forward pass. */
23
+ inference: number;
24
+ /** Decoding raw outputs into results (NMS, mask assembly, top-k). */
25
+ postprocess: number;
26
+ }
27
+ /**
28
+ * Accumulate stage durations while a `predict()` call runs.
29
+ *
30
+ * Each `stage()` call closes the previous stage: the elapsed time since the
31
+ * last boundary is attributed to the name given. This keeps the call sites
32
+ * free of paired start/stop bookkeeping and guarantees the four stages tile
33
+ * the whole call without gaps.
34
+ */
35
+ export declare class SpeedTimer {
36
+ private _last;
37
+ private readonly _speed;
38
+ constructor();
39
+ /**
40
+ * Attribute the time elapsed since the previous boundary to `stage`.
41
+ *
42
+ * @param stage Which stage just finished.
43
+ */
44
+ stage(stage: keyof Speed): void;
45
+ /**
46
+ * The accumulated durations.
47
+ *
48
+ * @returns The `speed` object to hand to the `Results` envelope.
49
+ */
50
+ speed(): Speed;
51
+ }
52
+ //# sourceMappingURL=timing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timing.d.ts","sourceRoot":"","sources":["../../src/core/timing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;GAQG;AACH,MAAM,WAAW,KAAK;IACpB,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,UAAU,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAKrB;;IAMF;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,IAAI;IAM/B;;;;OAIG;IACH,KAAK,IAAI,KAAK;CAGf"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Per-stage timing for a single `predict()` call.
3
+ *
4
+ * Populates the `speed` field every `Results` envelope carries, mirroring
5
+ * Ultralytics' `results[0].speed`. All values are milliseconds measured with
6
+ * `performance.now()`.
7
+ */
8
+ /**
9
+ * Accumulate stage durations while a `predict()` call runs.
10
+ *
11
+ * Each `stage()` call closes the previous stage: the elapsed time since the
12
+ * last boundary is attributed to the name given. This keeps the call sites
13
+ * free of paired start/stop bookkeeping and guarantees the four stages tile
14
+ * the whole call without gaps.
15
+ */
16
+ export class SpeedTimer {
17
+ _last;
18
+ _speed = {
19
+ load: 0,
20
+ preprocess: 0,
21
+ inference: 0,
22
+ postprocess: 0,
23
+ };
24
+ constructor() {
25
+ this._last = performance.now();
26
+ }
27
+ /**
28
+ * Attribute the time elapsed since the previous boundary to `stage`.
29
+ *
30
+ * @param stage Which stage just finished.
31
+ */
32
+ stage(stage) {
33
+ const now = performance.now();
34
+ this._speed[stage] += now - this._last;
35
+ this._last = now;
36
+ }
37
+ /**
38
+ * The accumulated durations.
39
+ *
40
+ * @returns The `speed` object to hand to the `Results` envelope.
41
+ */
42
+ speed() {
43
+ return { ...this._speed };
44
+ }
45
+ }
46
+ //# sourceMappingURL=timing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timing.js","sourceRoot":"","sources":["../../src/core/timing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAsBH;;;;;;;GAOG;AACH,MAAM,OAAO,UAAU;IACb,KAAK,CAAS;IACL,MAAM,GAAU;QAC/B,IAAI,EAAE,CAAC;QACP,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,CAAC;QACZ,WAAW,EAAE,CAAC;KACf,CAAC;IAEF;QACE,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAkB;QACtB,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAC9B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC;QACvC,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,KAAK;QACH,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -7,7 +7,9 @@ export { Boxes, ClassificationResults, DetectionResults, Masks, Probs, Segmentat
7
7
  export { COCO_CLASSES, type LabelSpec, type ResolveLabelsOptions, resolveLabels, } from "./labels.js";
8
8
  export { ImageLoadError, InferenceError, LabelMapError, ModelLoadError, OrtVisionError, ProviderNotAvailableError, } from "./core/exceptions.js";
9
9
  export { type ModelSource, type OrtSessionOptions, OrtSession, } from "./core/session.js";
10
+ export { type DeclaredDim, type DeclaredShape, type ResolveInputSizeOptions, declaredShapesFrom, resolveInputSize, spatialInputSize, } from "./core/graph.js";
10
11
  export { DEFAULT_PROVIDERS, resolveProviders } from "./core/providers.js";
12
+ export { type Speed, SpeedTimer } from "./core/timing.js";
11
13
  export { type ImageInput, loadImage } from "./io/image.js";
12
14
  export { type LetterboxResult, fromCv2, letterbox, normalize, resize, toCHW, toCv2, toFloat32, toFloat32Tensor, toTensor, } from "./preprocess/image.js";
13
15
  export { type TopKResult, softmax, topK, } from "./postprocess/classification.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,WAAW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DetectionResults, Masks, Probs, Segmentat
7
7
  export { COCO_CLASSES, resolveLabels, } from "./labels.js";
8
8
  export { ImageLoadError, InferenceError, LabelMapError, ModelLoadError, OrtVisionError, ProviderNotAvailableError, } from "./core/exceptions.js";
9
9
  export { OrtSession, } from "./core/session.js";
10
+ export { declaredShapesFrom, resolveInputSize, spatialInputSize, } from "./core/graph.js";
10
11
  export { DEFAULT_PROVIDERS, resolveProviders } from "./core/providers.js";
12
+ export { SpeedTimer } from "./core/timing.js";
11
13
  export { loadImage } from "./io/image.js";
12
14
  export { fromCv2, letterbox, normalize, resize, toCHW, toCv2, toFloat32, toFloat32Tensor, toTensor, } from "./preprocess/image.js";
13
15
  export { softmax, topK, } from "./postprocess/classification.js";
@@ -17,5 +19,5 @@ export { VisionTask } from "./tasks/base.js";
17
19
  export { Classifier, } from "./tasks/classifier.js";
18
20
  export { Detector, } from "./tasks/detector.js";
19
21
  export { Segmenter, } from "./tasks/segmenter.js";
20
- export const VERSION = "0.2.1";
22
+ export const VERSION = "0.4.0";
21
23
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,WAAW,EACX,IAAI,EACJ,QAAQ,GAKT,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,KAAK,EACL,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,EACL,KAAK,EACL,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,YAAY,EAGZ,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,cAAc,EACd,cAAc,EACd,aAAa,EACb,cAAc,EACd,cAAc,EACd,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAGL,UAAU,GACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,q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jB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAc,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,EAAmB,SAAS,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAEL,OAAO,EACP,SAAS,EACT,SAAS,EACT,MAAM,EACN,KAAK,EACL,KAAK,EACL,SAAS,EACT,eAAe,EACf,QAAQ,GACT,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAEL,OAAO,EACP,IAAI,GACL,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAOL,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,GAAG,GACJ,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAIL,aAAa,EACb,eAAe,GAChB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAGL,UAAU,GACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAIL,QAAQ,GACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAIL,SAAS,GACV,MAAM,sBAAsB,CAAC;AAE9B,MAAM,CAAC,MAAM,OAAO,GAAW,OAAO,CAAC"}
@@ -98,11 +98,11 @@ export interface DecodedDetection {
98
98
  export declare function decodeYolo(output: Float32Array, outputDims: readonly number[], options: DecodeYoloOptions): DecodedDetection[];
99
99
  /**
100
100
  * @deprecated since 0.2.0 — use {@link decodeYolo}. Same behavior; the
101
- * decoder covers v8/v9/v10/v11/v12 detect heads. Will be removed in 0.3.0.
101
+ * decoder covers v8/v9/v10/v11/v12 detect heads. Will be removed in 0.4.0.
102
102
  */
103
103
  export declare function decodeYoloV8(output: Float32Array, outputDims: readonly number[], options: DecodeYoloOptions): DecodedDetection[];
104
104
  /**
105
- * @deprecated since 0.2.0 — use {@link decodeYoloAnchors}. Will be removed in 0.3.0.
105
+ * @deprecated since 0.2.0 — use {@link decodeYoloAnchors}. Will be removed in 0.4.0.
106
106
  */
107
107
  export declare function decodeYoloV8Anchors(data: Float32Array, dims: readonly number[], options: DecodeYoloAnchorsOptions): DecodedAnchors;
108
108
  /** @deprecated since 0.2.0 — use {@link DecodeYoloAnchorsOptions}. */
@@ -259,24 +259,24 @@ let _warnedDecodeYoloV8 = false;
259
259
  let _warnedDecodeYoloV8Anchors = false;
260
260
  /**
261
261
  * @deprecated since 0.2.0 — use {@link decodeYolo}. Same behavior; the
262
- * decoder covers v8/v9/v10/v11/v12 detect heads. Will be removed in 0.3.0.
262
+ * decoder covers v8/v9/v10/v11/v12 detect heads. Will be removed in 0.4.0.
263
263
  */
264
264
  export function decodeYoloV8(output, outputDims, options) {
265
265
  if (!_warnedDecodeYoloV8) {
266
266
  _warnedDecodeYoloV8 = true;
267
267
  console.warn("[@ort-vision-sdk/web] decodeYoloV8 is deprecated since 0.2.0; use decodeYolo. " +
268
- "The alias will be removed in 0.3.0.");
268
+ "The alias will be removed in 0.4.0.");
269
269
  }
270
270
  return decodeYolo(output, outputDims, options);
271
271
  }
272
272
  /**
273
- * @deprecated since 0.2.0 — use {@link decodeYoloAnchors}. Will be removed in 0.3.0.
273
+ * @deprecated since 0.2.0 — use {@link decodeYoloAnchors}. Will be removed in 0.4.0.
274
274
  */
275
275
  export function decodeYoloV8Anchors(data, dims, options) {
276
276
  if (!_warnedDecodeYoloV8Anchors) {
277
277
  _warnedDecodeYoloV8Anchors = true;
278
278
  console.warn("[@ort-vision-sdk/web] decodeYoloV8Anchors is deprecated since 0.2.0; use decodeYoloAnchors. " +
279
- "The alias will be removed in 0.3.0.");
279
+ "The alias will be removed in 0.4.0.");
280
280
  }
281
281
  return decodeYoloAnchors(data, dims, options);
282
282
  }
@@ -54,7 +54,7 @@ export interface DecodedSegmentation {
54
54
  * @param prototypeDims Dims as reported by ORT, e.g. `[1, 32, 160, 160]`.
55
55
  */
56
56
  export declare function decodeYoloSeg(perAnchorData: Float32Array, perAnchorDims: readonly number[], prototypeData: Float32Array, prototypeDims: readonly number[], options: DecodeYoloSegOptions): DecodedSegmentation[];
57
- /** @deprecated since 0.2.0 — use {@link decodeYoloSeg}. Will be removed in 0.3.0. */
57
+ /** @deprecated since 0.2.0 — use {@link decodeYoloSeg}. Will be removed in 0.4.0. */
58
58
  export declare function decodeYoloV8Seg(perAnchorData: Float32Array, perAnchorDims: readonly number[], prototypeData: Float32Array, prototypeDims: readonly number[], options: DecodeYoloSegOptions): DecodedSegmentation[];
59
59
  /** @deprecated since 0.2.0 — use {@link DecodeYoloSegOptions}. */
60
60
  export type DecodeYoloV8SegOptions = DecodeYoloSegOptions;
@@ -140,12 +140,12 @@ function sigmoid(x) {
140
140
  return e / (1 + e);
141
141
  }
142
142
  let _warnedDecodeYoloV8Seg = false;
143
- /** @deprecated since 0.2.0 — use {@link decodeYoloSeg}. Will be removed in 0.3.0. */
143
+ /** @deprecated since 0.2.0 — use {@link decodeYoloSeg}. Will be removed in 0.4.0. */
144
144
  export function decodeYoloV8Seg(perAnchorData, perAnchorDims, prototypeData, prototypeDims, options) {
145
145
  if (!_warnedDecodeYoloV8Seg) {
146
146
  _warnedDecodeYoloV8Seg = true;
147
147
  console.warn("[@ort-vision-sdk/web] decodeYoloV8Seg is deprecated since 0.2.0; use decodeYoloSeg. " +
148
- "The alias will be removed in 0.3.0.");
148
+ "The alias will be removed in 0.4.0.");
149
149
  }
150
150
  return decodeYoloSeg(perAnchorData, perAnchorDims, prototypeData, prototypeDims, options);
151
151
  }