@mauriciobenjamin700/ort-vision-sdk-web 0.5.0 → 0.6.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.
- package/CHANGELOG.md +178 -0
- package/README.md +48 -0
- package/dist/core/canvas.d.ts +11 -2
- package/dist/core/canvas.d.ts.map +1 -1
- package/dist/core/canvas.js +12 -3
- package/dist/core/canvas.js.map +1 -1
- package/dist/core/exceptions.d.ts +26 -0
- package/dist/core/exceptions.d.ts.map +1 -1
- package/dist/core/exceptions.js +26 -0
- package/dist/core/exceptions.js.map +1 -1
- package/dist/core/metadata.d.ts +12 -0
- package/dist/core/metadata.d.ts.map +1 -1
- package/dist/core/metadata.js +15 -1
- package/dist/core/metadata.js.map +1 -1
- package/dist/core/session.d.ts +17 -0
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +34 -3
- package/dist/core/session.js.map +1 -1
- package/dist/fusion.d.ts +105 -0
- package/dist/fusion.d.ts.map +1 -0
- package/dist/fusion.js +141 -0
- package/dist/fusion.js.map +1 -0
- package/dist/index.d.ts +10 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/dist/labels.d.ts +16 -0
- package/dist/labels.d.ts.map +1 -1
- package/dist/labels.js +21 -0
- package/dist/labels.js.map +1 -1
- package/dist/postprocess/detection.d.ts +8 -14
- package/dist/postprocess/detection.d.ts.map +1 -1
- package/dist/postprocess/detection.js +10 -28
- package/dist/postprocess/detection.js.map +1 -1
- package/dist/postprocess/segmentation.d.ts +0 -4
- package/dist/postprocess/segmentation.d.ts.map +1 -1
- package/dist/postprocess/segmentation.js +0 -10
- package/dist/postprocess/segmentation.js.map +1 -1
- package/dist/preprocess/pipeline.d.ts +117 -0
- package/dist/preprocess/pipeline.d.ts.map +1 -0
- package/dist/preprocess/pipeline.js +153 -0
- package/dist/preprocess/pipeline.js.map +1 -0
- package/dist/results.d.ts +33 -0
- package/dist/results.d.ts.map +1 -1
- package/dist/results.js +48 -0
- package/dist/results.js.map +1 -1
- package/dist/tasks/base.d.ts +21 -0
- package/dist/tasks/base.d.ts.map +1 -1
- package/dist/tasks/base.js +25 -0
- package/dist/tasks/base.js.map +1 -1
- package/dist/tasks/detectClassify.d.ts +171 -0
- package/dist/tasks/detectClassify.d.ts.map +1 -0
- package/dist/tasks/detectClassify.js +448 -0
- package/dist/tasks/detectClassify.js.map +1 -0
- package/dist/tasks/detector.d.ts +42 -0
- package/dist/tasks/detector.d.ts.map +1 -1
- package/dist/tasks/detector.js +66 -16
- package/dist/tasks/detector.js.map +1 -1
- package/dist/tasks/segmenter.d.ts +33 -0
- package/dist/tasks/segmenter.d.ts.map +1 -1
- package/dist/tasks/segmenter.js +57 -16
- package/dist/tasks/segmenter.js.map +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,184 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.6.0] - 2026-08-07
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **`DetectClassify` runs through the fused letterbox pipeline, and can be
|
|
15
|
+
warmed up.** It was written against the pre-`LetterboxPipeline` preprocessing
|
|
16
|
+
and would otherwise have been the only task left on the slow path — and the
|
|
17
|
+
only one unable to pay its shader compilation up front, which is the task that
|
|
18
|
+
needs it most: two models plus the bridge compile on the first inference.
|
|
19
|
+
|
|
20
|
+
- **`raiseOnEmpty` — opt in to treating an empty result as an error.** Mirrors
|
|
21
|
+
the Python SDK: `Detector`, `Segmenter` and `DetectClassify` resolve to an
|
|
22
|
+
empty envelope by default, and throw the new `NoDetectionsError` when the flag
|
|
23
|
+
is set. Available on the construction options and as a per-call override, with
|
|
24
|
+
the same message — which names the threshold that applied, plus the image and
|
|
25
|
+
the class filter when either narrowed the search.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
const det = await Detector.create("/models/yolov8n.onnx", {
|
|
29
|
+
confThreshold: 0.7,
|
|
30
|
+
raiseOnEmpty: true,
|
|
31
|
+
});
|
|
32
|
+
await det.predict("/img.jpg");
|
|
33
|
+
// NoDetectionsError: No detections in /img.jpg: nothing cleared confThreshold=0.7.
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- **`DetectClassify` — run a fused detect→classify pipeline in the browser.**
|
|
37
|
+
A pipeline built by the Python SDK's `ort_vision_sdk.compose` (0.7.0) already
|
|
38
|
+
contains both models plus the crop-and-resize bridge between them. That matters
|
|
39
|
+
more in a tab than anywhere else: two models mean two `.onnx` downloads, two
|
|
40
|
+
WASM/WebGPU session initializations, and a per-crop round trip through
|
|
41
|
+
JavaScript to slice, resize and restack the regions before the second model can
|
|
42
|
+
see them. A fused pipeline has one download, one session, and no round trip.
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { DetectClassify } from "@mauriciobenjamin700/ort-vision-sdk-web";
|
|
46
|
+
|
|
47
|
+
const pipeline = await DetectClassify.create("/models/pipeline.onnx");
|
|
48
|
+
for (const d of (await pipeline.predict("/images/flock.jpg"))[0]) {
|
|
49
|
+
console.log(d.name, d.conf, d.classification?.name);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- **`readFusionSpec()` and the pipeline contract** (`FusionSpec`, `CropSource`,
|
|
54
|
+
the `INPUT_*` / `OUTPUT_*` names, `METADATA_PREFIX`). The letterbox resolution,
|
|
55
|
+
the crop size, whether the classifier output still needs a softmax and the class
|
|
56
|
+
names of both stages are read out of the model's own `ovs.` metadata — the same
|
|
57
|
+
keys, encodings and fallbacks the Python side writes. A pipeline fused once
|
|
58
|
+
therefore behaves identically in both runtimes, off the same file.
|
|
59
|
+
|
|
60
|
+
- **`DetectionResult.classification`** (optional, absent for a plain detector) and
|
|
61
|
+
the `DetectClassifyResults` envelope, which carries `names` and
|
|
62
|
+
`classifierNames` separately because the two stages have unrelated label spaces.
|
|
63
|
+
|
|
64
|
+
- **`FusionError`** and `parseNames()`, split out of `modelNames()` so both class
|
|
65
|
+
maps of a pipeline can be parsed with the same reader.
|
|
66
|
+
|
|
67
|
+
- **`warmup()` on `Detector` and `Segmenter`.** The first inference of a session
|
|
68
|
+
is not representative: WebGPU compiles its shaders on it and the WASM backend
|
|
69
|
+
faults in its arenas, so on a phone the first frame can take seconds while
|
|
70
|
+
every later frame takes tens of milliseconds. `await det.warmup()` runs the
|
|
71
|
+
model once on a zero tensor, moving that cost to wherever the user is already
|
|
72
|
+
watching a spinner.
|
|
73
|
+
|
|
74
|
+
- **`LetterboxPipeline`, exported.** The fused preprocessing path the tasks now
|
|
75
|
+
take, available to a custom pipeline that wants the same allocation-free
|
|
76
|
+
behaviour. `letterboxToTensorData` is the one-shot form.
|
|
77
|
+
|
|
78
|
+
### Changed
|
|
79
|
+
|
|
80
|
+
- **Preprocessing is ~2x faster and allocates nothing per frame.** Chaining the
|
|
81
|
+
composable primitives cost eleven full-buffer passes and six large allocations
|
|
82
|
+
per frame: `getImageData` → RGBA→RGB → RGB→RGBA → `putImageData` →
|
|
83
|
+
`drawImage` → `getImageData` → RGBA→RGB → fill → row copies → `toFloat32` →
|
|
84
|
+
`toCHW`. The tasks now go through `LetterboxPipeline`, which collapses the
|
|
85
|
+
second half into one `drawImage` — resizing *and* positioning the content
|
|
86
|
+
inside the padded target in a single accelerated operation — plus one loop
|
|
87
|
+
that reads the resulting RGBA and writes planar float32 straight into a buffer
|
|
88
|
+
reused across frames.
|
|
89
|
+
|
|
90
|
+
Measured in Chromium, median of 31 runs, letterboxing into 640x640:
|
|
91
|
+
|
|
92
|
+
| Source | Before | After | Speedup |
|
|
93
|
+
| --- | --- | --- | --- |
|
|
94
|
+
| 1920x1080 | 19.8 ms | 10.7 ms | 1.85x |
|
|
95
|
+
| 1280x720 | 13.8 ms | 7.8 ms | 1.77x |
|
|
96
|
+
| 640x480 | 6.8 ms | 3.1 ms | 2.19x |
|
|
97
|
+
|
|
98
|
+
**The output is bit-identical**, verified in a real browser against the
|
|
99
|
+
primitive-chained path across four source sizes — maximum difference 0.
|
|
100
|
+
|
|
101
|
+
The primitives are unchanged and still exported: they are what makes a custom
|
|
102
|
+
pipeline writable. Only the path the built-in tasks take has changed.
|
|
103
|
+
|
|
104
|
+
- **The preprocessing canvas is created with `willReadFrequently`.** It is read
|
|
105
|
+
back with `getImageData` on every frame, which is what the hint exists for.
|
|
106
|
+
Measured effect on speed in Chromium: none beyond noise. What it removes is
|
|
107
|
+
the `Canvas2D: Multiple readback operations using getImageData are faster with
|
|
108
|
+
the willReadFrequently attribute set to true` warning the browser was printing
|
|
109
|
+
into every consumer's console, once per frame.
|
|
110
|
+
|
|
111
|
+
### Removed
|
|
112
|
+
|
|
113
|
+
- **`decodeYoloV8`, `decodeYoloV8Anchors`, `decodeYoloV8Seg` and the
|
|
114
|
+
`DecodeYoloV8*Options` type aliases are gone.** Deprecated in 0.2.0 with
|
|
115
|
+
"will be removed in 0.4.0", and still shipping at 0.5.1. Use `decodeYolo`,
|
|
116
|
+
`decodeYoloAnchors`, `decodeYoloSeg` and their `DecodeYolo*Options` types:
|
|
117
|
+
same functions, honest names, since the decoder covers every anchor-free YOLO
|
|
118
|
+
head from v8 through v12.
|
|
119
|
+
|
|
120
|
+
`test/deprecations.test.ts` now guards the removal rather than the
|
|
121
|
+
deprecation, so a re-add fails loudly.
|
|
122
|
+
|
|
123
|
+
### Fixed
|
|
124
|
+
|
|
125
|
+
- **A custom model with no baked-in `names` no longer fails to create.** Same
|
|
126
|
+
defect as the Python SDK: the fallback was the 80-name COCO preset, so a
|
|
127
|
+
3-class detector threw `Resolved 80 labels but the model has 3 classes`.
|
|
128
|
+
Labels now come up as `class_0`, `class_1`, ..., and the COCO preset applies
|
|
129
|
+
only when the model really does have 80 classes. `defaultLabels` is exported.
|
|
130
|
+
|
|
131
|
+
- **A model URL that cannot be fetched for its metadata now says so.** The
|
|
132
|
+
fallback — hand the URL to ORT and let it load the model itself — is right,
|
|
133
|
+
but it was silent, and the symptom it produces is remote from the cause:
|
|
134
|
+
class names come back as `class_0`, `class_1`, ... with nothing explaining
|
|
135
|
+
why. It warns now, and names `labels` as the way out.
|
|
136
|
+
|
|
137
|
+
- **Score ties in `nms` and `batchedNms` break by index explicitly.** Both
|
|
138
|
+
relied on `Array.prototype.sort` being stable to order tied scores. It is, in
|
|
139
|
+
every engine that matters, but leaning on it left the tie behaviour implicit —
|
|
140
|
+
and in `batchedNms` the surviving order also depended on `Map` insertion order,
|
|
141
|
+
which the Python SDK (iterating classes in sorted order) does not share. The
|
|
142
|
+
comparators now fall back to `a - b`, so a tie resolves to the lowest index on
|
|
143
|
+
both sides, matching `torchvision`.
|
|
144
|
+
|
|
145
|
+
Only exact ties are affected. The Python SDK was the one actually producing a
|
|
146
|
+
different survivor — it visited ties in descending index order — and this is
|
|
147
|
+
the other half of that fix.
|
|
148
|
+
|
|
149
|
+
### Notes
|
|
150
|
+
|
|
151
|
+
- Fusing models stays a Python-side build step; there is no ONNX protobuf writer
|
|
152
|
+
here and no reason for one. The browser only loads the result.
|
|
153
|
+
- ORT Web returns `int64` outputs as `BigInt64Array`. The pipeline's class ids and
|
|
154
|
+
detection count are widened to `number` internally, so no caller has to handle
|
|
155
|
+
`BigInt`.
|
|
156
|
+
|
|
157
|
+
### Internal
|
|
158
|
+
|
|
159
|
+
- **Parity tests against shared fixtures** (`test/parity.test.ts`, reading
|
|
160
|
+
`fixtures/parity/` at the repository root). They feed the web implementation
|
|
161
|
+
the same inputs the Python SDK was given and require the same outputs, with
|
|
162
|
+
mask bitmaps compared pixel for pixel. Two published artifacts promising the
|
|
163
|
+
same numbers had nothing checking the promise; this is that check, and it
|
|
164
|
+
found a mask-resampling divergence on its first run (fixed on the Python
|
|
165
|
+
side, see that package's changelog).
|
|
166
|
+
|
|
167
|
+
## [0.5.1] - 2026-08-05
|
|
168
|
+
|
|
169
|
+
### Fixed
|
|
170
|
+
|
|
171
|
+
- **A model no longer costs twice its size at the peak of session creation.**
|
|
172
|
+
Reading the metadata map (0.5.0) fetches a URL model into a `Uint8Array`, and
|
|
173
|
+
that read sat *after* `InferenceSession.create` — so the JavaScript buffer
|
|
174
|
+
stayed reachable while ORT copied the model into its WASM heap and allocated
|
|
175
|
+
the graph and the weights on top of it. A 5 MB `.onnx` therefore held 5 MB of
|
|
176
|
+
JS heap plus 5 MB of WASM heap plus the weights at the same instant. On a phone
|
|
177
|
+
loading two models that was enough for ORT's allocator to give up with
|
|
178
|
+
`Can't create a session. failed to allocate a buffer of size 5355557`.
|
|
179
|
+
|
|
180
|
+
The metadata is now read before the session is built, so the buffer is
|
|
181
|
+
collectable as soon as ORT has copied it. `test/session.test.ts` pins the order.
|
|
182
|
+
|
|
183
|
+
`readMetadata: false` remains the escape hatch for a device that cannot afford
|
|
184
|
+
the bytes at all: ORT loads from the URL and nothing in the SDK ever holds the
|
|
185
|
+
model. Only the class names are lost — the input size still comes from the
|
|
186
|
+
graph — so that route has to pass `labels` itself.
|
|
187
|
+
|
|
10
188
|
## [0.5.0] - 2026-08-03
|
|
11
189
|
|
|
12
190
|
### Added
|
package/README.md
CHANGED
|
@@ -66,6 +66,54 @@ for (const d of detections) {
|
|
|
66
66
|
}
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
+
### Fused detect → classify pipeline
|
|
70
|
+
|
|
71
|
+
A pipeline fused by the Python SDK's `ort_vision_sdk.compose` puts a detector,
|
|
72
|
+
the crop-and-resize bridge and a classifier into **one** `.onnx`. In a browser
|
|
73
|
+
that is one download and one session instead of two, and no per-crop round trip
|
|
74
|
+
through JavaScript.
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { DetectClassify } from "@mauriciobenjamin700/ort-vision-sdk-web";
|
|
78
|
+
|
|
79
|
+
const pipeline = await DetectClassify.create("/models/pipeline.onnx");
|
|
80
|
+
const result = (await pipeline.predict("/images/flock.jpg"))[0];
|
|
81
|
+
|
|
82
|
+
for (const d of result) {
|
|
83
|
+
console.log(d.name, d.conf, d.box.asXyxy()); // what the detector found
|
|
84
|
+
console.log(d.classification?.name, d.classification?.conf); // what the classifier said
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The resolution, crop size, thresholds and both class maps come out of the file's
|
|
89
|
+
own metadata, so nothing is restated here. Building the pipeline is a Python-side
|
|
90
|
+
step; the browser only loads the result. Full guide:
|
|
91
|
+
[Fused pipelines](https://mauriciobenjamin700.github.io/ort-vision-sdk/en/guia/pipeline/).
|
|
92
|
+
|
|
93
|
+
### When finding nothing is an error
|
|
94
|
+
|
|
95
|
+
`predict()` resolves to an empty envelope when nothing is detected. When an
|
|
96
|
+
empty result instead means the surrounding flow should stop, opt in:
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { Detector, NoDetectionsError } from "@mauriciobenjamin700/ort-vision-sdk-web";
|
|
100
|
+
|
|
101
|
+
const det = await Detector.create("/models/yolov8n.onnx", {
|
|
102
|
+
confThreshold: 0.7,
|
|
103
|
+
raiseOnEmpty: true,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
const result = (await det.predict("/img.jpg"))[0];
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (error instanceof NoDetectionsError) console.log(error.message);
|
|
110
|
+
// No detections in /img.jpg: nothing cleared confThreshold=0.7.
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Available on `Detector`, `Segmenter` and `DetectClassify`, and overridable per
|
|
115
|
+
call (`predict(img, { raiseOnEmpty: false })`).
|
|
116
|
+
|
|
69
117
|
## Inference speed
|
|
70
118
|
|
|
71
119
|
Every result envelope carries a per-stage timing breakdown:
|
package/dist/core/canvas.d.ts
CHANGED
|
@@ -12,8 +12,17 @@ export type Canvas2D = HTMLCanvasElement | OffscreenCanvas;
|
|
|
12
12
|
export type Context2D = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
|
|
13
13
|
/** Allocate a `Canvas2D`, preferring `OffscreenCanvas` when available. */
|
|
14
14
|
export declare function createCanvas(width: number, height: number): Canvas2D;
|
|
15
|
-
/**
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Get a 2D context from a canvas, throwing a typed error if the browser refuses.
|
|
17
|
+
*
|
|
18
|
+
* @param canvas The canvas to obtain a context for.
|
|
19
|
+
* @param options Context attributes, forwarded verbatim. `willReadFrequently`
|
|
20
|
+
* tells the browser the canvas is read back with `getImageData` repeatedly,
|
|
21
|
+
* which moves the backing store to software: faster readback, slower
|
|
22
|
+
* compositing. Whether it pays depends on the surface, so it is the caller's
|
|
23
|
+
* call rather than a default here.
|
|
24
|
+
*/
|
|
25
|
+
export declare function get2DContext(canvas: Canvas2D, options?: CanvasRenderingContext2DSettings): Context2D;
|
|
17
26
|
/** Convert RGBA `ImageData` into the canonical HWC RGB `RGBImage`. */
|
|
18
27
|
export declare function imageDataToRGB(imageData: ImageData): RGBImage;
|
|
19
28
|
/** Convert an `RGBImage` into RGBA `ImageData` (alpha forced to 255). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../../src/core/canvas.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,MAAM,QAAQ,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAC3D,MAAM,MAAM,SAAS,GACjB,wBAAwB,GACxB,iCAAiC,CAAC;AAEtC,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAWpE;AAED
|
|
1
|
+
{"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../../src/core/canvas.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,MAAM,QAAQ,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAC3D,MAAM,MAAM,SAAS,GACjB,wBAAwB,GACxB,iCAAiC,CAAC;AAEtC,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAWpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,QAAQ,EAChB,OAAO,GAAE,gCAAqC,GAC7C,SAAS,CAMX;AAED,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,SAAS,EAAE,SAAS,GAAG,QAAQ,CAgB7D;AAED,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,CASzD"}
|
package/dist/core/canvas.js
CHANGED
|
@@ -22,9 +22,18 @@ export function createCanvas(width, height) {
|
|
|
22
22
|
}
|
|
23
23
|
throw new ImageLoadError("No canvas implementation available in this environment.");
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Get a 2D context from a canvas, throwing a typed error if the browser refuses.
|
|
27
|
+
*
|
|
28
|
+
* @param canvas The canvas to obtain a context for.
|
|
29
|
+
* @param options Context attributes, forwarded verbatim. `willReadFrequently`
|
|
30
|
+
* tells the browser the canvas is read back with `getImageData` repeatedly,
|
|
31
|
+
* which moves the backing store to software: faster readback, slower
|
|
32
|
+
* compositing. Whether it pays depends on the surface, so it is the caller's
|
|
33
|
+
* call rather than a default here.
|
|
34
|
+
*/
|
|
35
|
+
export function get2DContext(canvas, options = {}) {
|
|
36
|
+
const ctx = canvas.getContext("2d", options);
|
|
28
37
|
if (ctx === null) {
|
|
29
38
|
throw new ImageLoadError("Failed to obtain 2D rendering context.");
|
|
30
39
|
}
|
package/dist/core/canvas.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas.js","sourceRoot":"","sources":["../../src/core/canvas.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAOvC,0EAA0E;AAC1E,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,MAAc;IACxD,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE,CAAC;QAC3C,OAAO,IAAI,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACpC,MAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC3C,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC;QAChB,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC;QAClB,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,IAAI,cAAc,CAAC,yDAAyD,CAAC,CAAC;AACtF,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"canvas.js","sourceRoot":"","sources":["../../src/core/canvas.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAOvC,0EAA0E;AAC1E,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,MAAc;IACxD,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE,CAAC;QAC3C,OAAO,IAAI,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACpC,MAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC3C,CAAC,CAAC,KAAK,GAAG,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AC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAW,CAAC;IACrC,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAC1C,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,cAAc,CAAC,KAAe;IAC5C,MAAM,IAAI,GAAG,IAAI,iBAAiB,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7D,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAW,CAAC;QAClC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAW,CAAC;QAC1C,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAW,CAAC;QAC1C,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;IACpB,CAAC;IACD,OAAO,IAAI,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -22,4 +22,30 @@ export declare class ImageLoadError extends OrtVisionError {
|
|
|
22
22
|
/** Raised when class labels cannot be resolved from the supplied spec. */
|
|
23
23
|
export declare class LabelMapError extends OrtVisionError {
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Raised when a detection task finds nothing and was asked to treat that as an error.
|
|
27
|
+
*
|
|
28
|
+
* Only raised when the caller opts in with `raiseOnEmpty: true`. The default
|
|
29
|
+
* stays an empty result, because "the model looked and found nothing" is a
|
|
30
|
+
* successful inference, not a failure — a photo of an empty field is a valid
|
|
31
|
+
* photo. What the flag is for is the opposite situation: a pipeline step whose
|
|
32
|
+
* *precondition* is that something is there, where an empty result means the
|
|
33
|
+
* caller should stop rather than quietly carry on with zero rows.
|
|
34
|
+
*
|
|
35
|
+
* "Nothing was detected" and "nothing was confident enough" are the same
|
|
36
|
+
* condition here, since the confidence threshold is what decides what counts as
|
|
37
|
+
* a detection in the first place.
|
|
38
|
+
*/
|
|
39
|
+
export declare class NoDetectionsError extends OrtVisionError {
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Raised when a model cannot be driven as a fused detect→classify pipeline.
|
|
43
|
+
*
|
|
44
|
+
* In the browser this means the file carries no `ovs.*` metadata — it is a
|
|
45
|
+
* plain detector or classifier rather than something `ort_vision_sdk.compose`
|
|
46
|
+
* produced — or the graph is missing an output the pipeline contract requires.
|
|
47
|
+
* Building a pipeline is a Python-side build step; the browser only runs one.
|
|
48
|
+
*/
|
|
49
|
+
export declare class FusionError extends OrtVisionError {
|
|
50
|
+
}
|
|
25
51
|
//# sourceMappingURL=exceptions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../src/core/exceptions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD;AAED,4EAA4E;AAC5E,qBAAa,cAAe,SAAQ,cAAc;CAAG;AAErD,8DAA8D;AAC9D,qBAAa,cAAe,SAAQ,cAAc;CAAG;AAErD,mEAAmE;AACnE,qBAAa,yBAA0B,SAAQ,cAAc;CAAG;AAEhE,8EAA8E;AAC9E,qBAAa,cAAe,SAAQ,cAAc;CAAG;AAErD,0EAA0E;AAC1E,qBAAa,aAAc,SAAQ,cAAc;CAAG"}
|
|
1
|
+
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../src/core/exceptions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD;AAED,4EAA4E;AAC5E,qBAAa,cAAe,SAAQ,cAAc;CAAG;AAErD,8DAA8D;AAC9D,qBAAa,cAAe,SAAQ,cAAc;CAAG;AAErD,mEAAmE;AACnE,qBAAa,yBAA0B,SAAQ,cAAc;CAAG;AAEhE,8EAA8E;AAC9E,qBAAa,cAAe,SAAQ,cAAc;CAAG;AAErD,0EAA0E;AAC1E,qBAAa,aAAc,SAAQ,cAAc;CAAG;AAEpD;;;;;;;;;;;;;GAaG;AACH,qBAAa,iBAAkB,SAAQ,cAAc;CAAG;AAExD;;;;;;;GAOG;AACH,qBAAa,WAAY,SAAQ,cAAc;CAAG"}
|
package/dist/core/exceptions.js
CHANGED
|
@@ -25,4 +25,30 @@ export class ImageLoadError extends OrtVisionError {
|
|
|
25
25
|
/** Raised when class labels cannot be resolved from the supplied spec. */
|
|
26
26
|
export class LabelMapError extends OrtVisionError {
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Raised when a detection task finds nothing and was asked to treat that as an error.
|
|
30
|
+
*
|
|
31
|
+
* Only raised when the caller opts in with `raiseOnEmpty: true`. The default
|
|
32
|
+
* stays an empty result, because "the model looked and found nothing" is a
|
|
33
|
+
* successful inference, not a failure — a photo of an empty field is a valid
|
|
34
|
+
* photo. What the flag is for is the opposite situation: a pipeline step whose
|
|
35
|
+
* *precondition* is that something is there, where an empty result means the
|
|
36
|
+
* caller should stop rather than quietly carry on with zero rows.
|
|
37
|
+
*
|
|
38
|
+
* "Nothing was detected" and "nothing was confident enough" are the same
|
|
39
|
+
* condition here, since the confidence threshold is what decides what counts as
|
|
40
|
+
* a detection in the first place.
|
|
41
|
+
*/
|
|
42
|
+
export class NoDetectionsError extends OrtVisionError {
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Raised when a model cannot be driven as a fused detect→classify pipeline.
|
|
46
|
+
*
|
|
47
|
+
* In the browser this means the file carries no `ovs.*` metadata — it is a
|
|
48
|
+
* plain detector or classifier rather than something `ort_vision_sdk.compose`
|
|
49
|
+
* produced — or the graph is missing an output the pipeline contract requires.
|
|
50
|
+
* Building a pipeline is a Python-side build step; the browser only runs one.
|
|
51
|
+
*/
|
|
52
|
+
export class FusionError extends OrtVisionError {
|
|
53
|
+
}
|
|
28
54
|
//# sourceMappingURL=exceptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../src/core/exceptions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED,4EAA4E;AAC5E,MAAM,OAAO,cAAe,SAAQ,cAAc;CAAG;AAErD,8DAA8D;AAC9D,MAAM,OAAO,cAAe,SAAQ,cAAc;CAAG;AAErD,mEAAmE;AACnE,MAAM,OAAO,yBAA0B,SAAQ,cAAc;CAAG;AAEhE,8EAA8E;AAC9E,MAAM,OAAO,cAAe,SAAQ,cAAc;CAAG;AAErD,0EAA0E;AAC1E,MAAM,OAAO,aAAc,SAAQ,cAAc;CAAG"}
|
|
1
|
+
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../src/core/exceptions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED,4EAA4E;AAC5E,MAAM,OAAO,cAAe,SAAQ,cAAc;CAAG;AAErD,8DAA8D;AAC9D,MAAM,OAAO,cAAe,SAAQ,cAAc;CAAG;AAErD,mEAAmE;AACnE,MAAM,OAAO,yBAA0B,SAAQ,cAAc;CAAG;AAEhE,8EAA8E;AAC9E,MAAM,OAAO,cAAe,SAAQ,cAAc;CAAG;AAErD,0EAA0E;AAC1E,MAAM,OAAO,aAAc,SAAQ,cAAc;CAAG;AAEpD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,iBAAkB,SAAQ,cAAc;CAAG;AAExD;;;;;;;GAOG;AACH,MAAM,OAAO,WAAY,SAAQ,cAAc;CAAG"}
|
package/dist/core/metadata.d.ts
CHANGED
|
@@ -36,4 +36,16 @@ export declare function readModelMetadata(model: Uint8Array | ArrayBufferLike):
|
|
|
36
36
|
* usable `names` entry.
|
|
37
37
|
*/
|
|
38
38
|
export declare function modelNames(metadata: Readonly<Record<string, string>> | undefined): readonly string[] | null;
|
|
39
|
+
/**
|
|
40
|
+
* Parse a `repr`-encoded `dict[int, str]` class map.
|
|
41
|
+
*
|
|
42
|
+
* Split out of {@link modelNames} because the same encoding is reused by a
|
|
43
|
+
* fused pipeline, which carries one class map per stage and therefore cannot
|
|
44
|
+
* store both under the single `names` key Ultralytics uses.
|
|
45
|
+
*
|
|
46
|
+
* @param encoded The encoded map — e.g. `"{0: 'deworm', 1: 'not_deworm'}"`.
|
|
47
|
+
* @returns Class names in class-id order, or `null` when the value is missing,
|
|
48
|
+
* unparseable, not a `dict`, or not keyed by contiguous integers from zero.
|
|
49
|
+
*/
|
|
50
|
+
export declare function parseNames(encoded: string | undefined): readonly string[] | null;
|
|
39
51
|
//# sourceMappingURL=metadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/core/metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAyIH;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,UAAU,GAAG,eAAe,GAClC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAqBlC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,GACrD,SAAS,MAAM,EAAE,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/core/metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAyIH;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,UAAU,GAAG,eAAe,GAClC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAqBlC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,GACrD,SAAS,MAAM,EAAE,GAAG,IAAI,CAE1B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,MAAM,EAAE,GAAG,IAAI,CA6BhF"}
|
package/dist/core/metadata.js
CHANGED
|
@@ -182,7 +182,21 @@ export function readModelMetadata(model) {
|
|
|
182
182
|
* usable `names` entry.
|
|
183
183
|
*/
|
|
184
184
|
export function modelNames(metadata) {
|
|
185
|
-
|
|
185
|
+
return parseNames(metadata?.names);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Parse a `repr`-encoded `dict[int, str]` class map.
|
|
189
|
+
*
|
|
190
|
+
* Split out of {@link modelNames} because the same encoding is reused by a
|
|
191
|
+
* fused pipeline, which carries one class map per stage and therefore cannot
|
|
192
|
+
* store both under the single `names` key Ultralytics uses.
|
|
193
|
+
*
|
|
194
|
+
* @param encoded The encoded map — e.g. `"{0: 'deworm', 1: 'not_deworm'}"`.
|
|
195
|
+
* @returns Class names in class-id order, or `null` when the value is missing,
|
|
196
|
+
* unparseable, not a `dict`, or not keyed by contiguous integers from zero.
|
|
197
|
+
*/
|
|
198
|
+
export function parseNames(encoded) {
|
|
199
|
+
const raw = encoded?.trim();
|
|
186
200
|
if (!raw || !raw.startsWith("{") || !raw.endsWith("}"))
|
|
187
201
|
return null;
|
|
188
202
|
const body = raw.slice(1, -1).trim();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/core/metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,0FAA0F;AAC1F,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAEtC,sEAAsE;AACtE,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B,mDAAmD;AACnD,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB;;;;GAIG;AACH,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,CAAC;AAShC;;;;;;GAMG;AACH,SAAS,UAAU,CAAC,MAAc;IAChC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAE,CAAC;QACvC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;QAChB,MAAM,IAAI,CAAC,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,IAAI,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAE7C,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC3B,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACpC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,IAAY;IAClC,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,IAAY,EAAE,EAAE;QAChD,IAAI,IAAI,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;QAC9B,IAAI,IAAI,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;QAC9B,IAAI,IAAI,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC"}
|
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":["../../src/core/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,KAAK,GAAG,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAE,KAAK,aAAa,EAAsB,MAAM,YAAY,CAAC;AAIpE,kDAAkD;AAClD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,eAAe,GAAG,UAAU,CAAC;
|
|
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,KAAK,aAAa,EAAsB,MAAM,YAAY,CAAC;AAIpE,kDAAkD;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AAI,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
|
@@ -19,14 +19,35 @@ import { resolveProviders } from "./providers.js";
|
|
|
19
19
|
async function fetchModel(url) {
|
|
20
20
|
try {
|
|
21
21
|
const response = await fetch(url);
|
|
22
|
-
if (!response.ok)
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
warnMetadataUnavailable(url, `HTTP ${response.status} ${response.statusText}`);
|
|
23
24
|
return url;
|
|
25
|
+
}
|
|
24
26
|
return new Uint8Array(await response.arrayBuffer());
|
|
25
27
|
}
|
|
26
|
-
catch {
|
|
28
|
+
catch (err) {
|
|
29
|
+
warnMetadataUnavailable(url, err.message);
|
|
27
30
|
return url;
|
|
28
31
|
}
|
|
29
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Warn that a model's metadata could not be read, and say what that costs.
|
|
35
|
+
*
|
|
36
|
+
* The fallback itself is right — losing the metadata beats failing a load that
|
|
37
|
+
* ORT could have completed on its own — but it used to be silent, and the
|
|
38
|
+
* symptom it produces is remote from the cause: class names come back as
|
|
39
|
+
* `class_0`, `class_1`, ... with nothing anywhere explaining why. Whoever hits
|
|
40
|
+
* this needs to be told that passing `labels` is the way out.
|
|
41
|
+
*
|
|
42
|
+
* @param url The model URL that could not be fetched here.
|
|
43
|
+
* @param reason What went wrong, as reported by `fetch`.
|
|
44
|
+
*/
|
|
45
|
+
function warnMetadataUnavailable(url, reason) {
|
|
46
|
+
console.warn(`[@ort-vision-sdk/web] Could not fetch ${url} to read its metadata (${reason}). ` +
|
|
47
|
+
"Letting ONNX Runtime load it instead: the model will work, but its baked-in " +
|
|
48
|
+
"class names are unavailable, so labels fall back to class_0, class_1, ... " +
|
|
49
|
+
"Pass `labels` explicitly to name them.");
|
|
50
|
+
}
|
|
30
51
|
/**
|
|
31
52
|
* Wrap an ONNX Runtime Web `InferenceSession` with convenient metadata access.
|
|
32
53
|
*
|
|
@@ -46,6 +67,16 @@ export class OrtSession {
|
|
|
46
67
|
/**
|
|
47
68
|
* Load an ONNX model into an ORT inference session.
|
|
48
69
|
*
|
|
70
|
+
* The metadata map is read **before** the session is built, and that order is
|
|
71
|
+
* load-bearing on memory-constrained devices. ORT copies the model into its
|
|
72
|
+
* WASM heap and then allocates the graph and the weights on top of that copy;
|
|
73
|
+
* a `readModelMetadata` call placed after `InferenceSession.create` keeps the
|
|
74
|
+
* JavaScript-side buffer reachable across the whole build, so a 5 MB model
|
|
75
|
+
* costs 5 MB of JS heap plus 5 MB of WASM heap plus the weights at the same
|
|
76
|
+
* instant. Reading first makes the buffer collectable as soon as ORT has copied
|
|
77
|
+
* it — on a phone that was the difference between a session and
|
|
78
|
+
* `Can't create a session. failed to allocate a buffer of size N`.
|
|
79
|
+
*
|
|
49
80
|
* @param model Either a URL string, or a `Uint8Array`/`ArrayBuffer` containing the model bytes.
|
|
50
81
|
* @param options Provider list, pass-through `SessionOptions`, and whether to
|
|
51
82
|
* read the model's metadata map (see {@link OrtSessionOptions.readMetadata}).
|
|
@@ -59,6 +90,7 @@ export class OrtSession {
|
|
|
59
90
|
};
|
|
60
91
|
const wantsMetadata = options.readMetadata !== false;
|
|
61
92
|
const source = typeof model === "string" && wantsMetadata ? await fetchModel(model) : model;
|
|
93
|
+
const metadata = wantsMetadata && typeof source !== "string" ? readModelMetadata(source) : {};
|
|
62
94
|
let session;
|
|
63
95
|
try {
|
|
64
96
|
if (typeof source === "string") {
|
|
@@ -74,7 +106,6 @@ export class OrtSession {
|
|
|
74
106
|
catch (err) {
|
|
75
107
|
throw new ModelLoadError(`Failed to load ONNX model: ${err.message}`, { cause: err });
|
|
76
108
|
}
|
|
77
|
-
const metadata = wantsMetadata && typeof source !== "string" ? readModelMetadata(source) : {};
|
|
78
109
|
return new OrtSession(session, providers, metadata);
|
|
79
110
|
}
|
|
80
111
|
/** 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,gBAAgB,CAAC;AAKlD;;;;;;;;;GASG;AACH,KAAK,UAAU,UAAU,CAAC,GAAW;IACnC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,EAAE;
|
|
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,gBAAgB,CAAC;AAKlD;;;;;;;;;GASG;AACH,KAAK,UAAU,UAAU,CAAC,GAAW;IACnC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,uBAAuB,CAAC,GAAG,EAA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