@mauriciobenjamin700/ort-vision-sdk-web 0.5.0 → 0.5.1
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.
- package/CHANGELOG.md +21 -0
- package/dist/core/session.d.ts +17 -0
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +11 -1
- package/dist/core/session.js.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.1] - 2026-08-05
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **A model no longer costs twice its size at the peak of session creation.**
|
|
15
|
+
Reading the metadata map (0.5.0) fetches a URL model into a `Uint8Array`, and
|
|
16
|
+
that read sat *after* `InferenceSession.create` — so the JavaScript buffer
|
|
17
|
+
stayed reachable while ORT copied the model into its WASM heap and allocated
|
|
18
|
+
the graph and the weights on top of it. A 5 MB `.onnx` therefore held 5 MB of
|
|
19
|
+
JS heap plus 5 MB of WASM heap plus the weights at the same instant. On a phone
|
|
20
|
+
loading two models that was enough for ORT's allocator to give up with
|
|
21
|
+
`Can't create a session. failed to allocate a buffer of size 5355557`.
|
|
22
|
+
|
|
23
|
+
The metadata is now read before the session is built, so the buffer is
|
|
24
|
+
collectable as soon as ORT has copied it. `test/session.test.ts` pins the order.
|
|
25
|
+
|
|
26
|
+
`readMetadata: false` remains the escape hatch for a device that cannot afford
|
|
27
|
+
the bytes at all: ORT loads from the URL and nothing in the SDK ever holds the
|
|
28
|
+
model. Only the class names are lost — the input size still comes from the
|
|
29
|
+
graph — so that route has to pass `labels` itself.
|
|
30
|
+
|
|
10
31
|
## [0.5.0] - 2026-08-03
|
|
11
32
|
|
|
12
33
|
### Added
|
package/dist/core/session.d.ts
CHANGED
|
@@ -19,6 +19,13 @@ export interface OrtSessionOptions {
|
|
|
19
19
|
* of letting ORT fetch it. That is the same single download either way, and
|
|
20
20
|
* it is what lets a task resolve its labels off the model. Set to `false` to
|
|
21
21
|
* keep the URL path untouched and leave {@link OrtSession.metadata} empty.
|
|
22
|
+
*
|
|
23
|
+
* `false` is also the escape hatch when a device cannot afford the bytes: the
|
|
24
|
+
* fetched buffer is dropped before ORT builds the graph (see
|
|
25
|
+
* {@link OrtSession.create}), but ORT's own load path still keeps the model out
|
|
26
|
+
* of reach of anything the SDK holds. A session built this way resolves its
|
|
27
|
+
* input size from the graph as usual — only the class names are lost, so a
|
|
28
|
+
* caller taking this route has to pass `labels` itself.
|
|
22
29
|
*/
|
|
23
30
|
readonly readMetadata?: boolean;
|
|
24
31
|
}
|
|
@@ -37,6 +44,16 @@ export declare class OrtSession {
|
|
|
37
44
|
/**
|
|
38
45
|
* Load an ONNX model into an ORT inference session.
|
|
39
46
|
*
|
|
47
|
+
* The metadata map is read **before** the session is built, and that order is
|
|
48
|
+
* load-bearing on memory-constrained devices. ORT copies the model into its
|
|
49
|
+
* WASM heap and then allocates the graph and the weights on top of that copy;
|
|
50
|
+
* a `readModelMetadata` call placed after `InferenceSession.create` keeps the
|
|
51
|
+
* JavaScript-side buffer reachable across the whole build, so a 5 MB model
|
|
52
|
+
* costs 5 MB of JS heap plus 5 MB of WASM heap plus the weights at the same
|
|
53
|
+
* instant. Reading first makes the buffer collectable as soon as ORT has copied
|
|
54
|
+
* it — on a phone that was the difference between a session and
|
|
55
|
+
* `Can't create a session. failed to allocate a buffer of size N`.
|
|
56
|
+
*
|
|
40
57
|
* @param model Either a URL string, or a `Uint8Array`/`ArrayBuffer` containing the model bytes.
|
|
41
58
|
* @param options Provider list, pass-through `SessionOptions`, and whether to
|
|
42
59
|
* read the model's metadata map (see {@link OrtSessionOptions.readMetadata}).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../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AO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,UAAU,CAAC;IAkCtB,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;;;;;;OAMG;IACH,IAAI,WAAW,IAAI,SAAS,aAAa,EAAE,CAM1C;IAED;;;;OAIG;IACH,IAAI,UAAU,IAAI,aAAa,CAE9B;IAED;;;;;OAKG;IACH,IAAI,YAAY,IAAI,SAAS,aAAa,EAAE,CAM3C;IAED;;;;OAIG;IACH,IAAI,WAAW,IAAI,aAAa,CAE/B;IAED;;;;;;;OAOG;IACH,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAE/C;IAED;;;;;;;OAOG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,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"}
|
package/dist/core/session.js
CHANGED
|
@@ -46,6 +46,16 @@ export class OrtSession {
|
|
|
46
46
|
/**
|
|
47
47
|
* Load an ONNX model into an ORT inference session.
|
|
48
48
|
*
|
|
49
|
+
* The metadata map is read **before** the session is built, and that order is
|
|
50
|
+
* load-bearing on memory-constrained devices. ORT copies the model into its
|
|
51
|
+
* WASM heap and then allocates the graph and the weights on top of that copy;
|
|
52
|
+
* a `readModelMetadata` call placed after `InferenceSession.create` keeps the
|
|
53
|
+
* JavaScript-side buffer reachable across the whole build, so a 5 MB model
|
|
54
|
+
* costs 5 MB of JS heap plus 5 MB of WASM heap plus the weights at the same
|
|
55
|
+
* instant. Reading first makes the buffer collectable as soon as ORT has copied
|
|
56
|
+
* it — on a phone that was the difference between a session and
|
|
57
|
+
* `Can't create a session. failed to allocate a buffer of size N`.
|
|
58
|
+
*
|
|
49
59
|
* @param model Either a URL string, or a `Uint8Array`/`ArrayBuffer` containing the model bytes.
|
|
50
60
|
* @param options Provider list, pass-through `SessionOptions`, and whether to
|
|
51
61
|
* read the model's metadata map (see {@link OrtSessionOptions.readMetadata}).
|
|
@@ -59,6 +69,7 @@ export class OrtSession {
|
|
|
59
69
|
};
|
|
60
70
|
const wantsMetadata = options.readMetadata !== false;
|
|
61
71
|
const source = typeof model === "string" && wantsMetadata ? await fetchModel(model) : model;
|
|
72
|
+
const metadata = wantsMetadata && typeof source !== "string" ? readModelMetadata(source) : {};
|
|
62
73
|
let session;
|
|
63
74
|
try {
|
|
64
75
|
if (typeof source === "string") {
|
|
@@ -74,7 +85,6 @@ export class OrtSession {
|
|
|
74
85
|
catch (err) {
|
|
75
86
|
throw new ModelLoadError(`Failed to load ONNX model: ${err.message}`, { cause: err });
|
|
76
87
|
}
|
|
77
|
-
const metadata = wantsMetadata && typeof source !== "string" ? readModelMetadata(source) : {};
|
|
78
88
|
return new OrtSession(session, providers, metadata);
|
|
79
89
|
}
|
|
80
90
|
/** Names of the model's inputs, in declaration order. */
|
package/dist/core/session.js.map
CHANGED
|
@@ -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,iBAAiB,CAAC;AACjE,OAAO,EAAsB,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAA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AAS,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"}
|
package/dist/index.js
CHANGED
|
@@ -20,5 +20,5 @@ export { VisionTask } from "./tasks/base.js";
|
|
|
20
20
|
export { Classifier, } from "./tasks/classifier.js";
|
|
21
21
|
export { Detector, } from "./tasks/detector.js";
|
|
22
22
|
export { Segmenter, } from "./tasks/segmenter.js";
|
|
23
|
-
export const VERSION = "0.5.
|
|
23
|
+
export const VERSION = "0.5.1";
|
|
24
24
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED