@ultralytics/yolo 0.0.55 → 0.0.56

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/README.md CHANGED
@@ -82,7 +82,7 @@ await annotate(document.querySelector("canvas"), "bus.jpg", results);
82
82
 
83
83
  `predict()` accepts a URL/path, a `Blob`/`File`, raw encoded image bytes
84
84
  (`Uint8Array`/`ArrayBuffer`), `ImageData`, an `HTMLImageElement`,
85
- `HTMLCanvasElement`, `HTMLVideoElement`, or an `ImageBitmap`.
85
+ `HTMLCanvasElement`, `HTMLVideoElement`, an `OffscreenCanvas`, or an `ImageBitmap`.
86
86
 
87
87
  ```ts
88
88
  const results = await model.predict(canvas, { conf: 0.25, iou: 0.7 });
@@ -184,6 +184,10 @@ await annotate(canvas, img, results, { keypointRadius: 4, skeleton: [[0, 1]] });
184
184
  `annotate()` also takes `lineWidth` and `font` to set the box width and label font, and `labels: false` or
185
185
  `keypoints: false` to hide labels or keypoints.
186
186
 
187
+ Arabic, Hebrew and other right-to-left class names are drawn right to left in every browser, Safari included. They use
188
+ the engine's wasm, so if `annotate()` runs where no model was loaded (for example on the main thread while a worker runs
189
+ the model), pass the same `wasmUrl` you gave `YOLO.load`.
190
+
187
191
  ## ⚙️ Requirements & Notes
188
192
 
189
193
  - **WebGPU** (Chrome/Edge, or Firefox with WebGPU enabled) from a **secure
@@ -311,7 +315,8 @@ Notes:
311
315
  - **Tasks**: detect, segment, semantic, depth, classify, pose, and obb are all supported.
312
316
  - **Cross-origin isolation**: LiteRT's threaded wasm wants `SharedArrayBuffer`,
313
317
  so serve with `Cross-Origin-Opener-Policy: same-origin` and
314
- `Cross-Origin-Embedder-Policy: require-corp`.
318
+ `Cross-Origin-Embedder-Policy: require-corp`. That blocks the default CDN wasm, so
319
+ pass a same-origin `litertWasmUrl` too.
315
320
 
316
321
  ## 🏎️ Benchmarks
317
322
 
package/README.zh-CN.md CHANGED
@@ -79,7 +79,7 @@ await annotate(document.querySelector("canvas"), "bus.jpg", results);
79
79
  ```
80
80
 
81
81
  `predict()` 接受 URL/路径、`Blob`/`File`、原始编码图片字节(`Uint8Array`/`ArrayBuffer`)、
82
- `ImageData`、`HTMLImageElement`、`HTMLCanvasElement`、`HTMLVideoElement` 或 `ImageBitmap`。
82
+ `ImageData`、`HTMLImageElement`、`HTMLCanvasElement`、`HTMLVideoElement`、`OffscreenCanvas` 或 `ImageBitmap`。
83
83
 
84
84
  ```ts
85
85
  const results = await model.predict(canvas, { conf: 0.25, iou: 0.7 });
@@ -177,6 +177,9 @@ await annotate(canvas, img, results, { keypointRadius: 4, skeleton: [[0, 1]] });
177
177
  `annotate()` 还接受 `lineWidth` 和 `font` 用于设置框线宽度和标签字体,以及 `labels: false` 或
178
178
  `keypoints: false` 用于隐藏标签或关键点。
179
179
 
180
+ 阿拉伯语、希伯来语等从右到左的类别名在所有浏览器(包括 Safari)中都会从右到左绘制。这需要引擎的 wasm,
181
+ 因此如果 `annotate()` 运行在未加载模型的线程中(例如模型在 worker 中运行而绘制在主线程),请传入与 `YOLO.load` 相同的 `wasmUrl`。
182
+
180
183
  ## ⚙️ 环境要求与注意事项
181
184
 
182
185
  - **WebGPU**(Chrome/Edge,或启用了 WebGPU 的 Firefox)配合**安全上下文**(`https://` 或
@@ -288,7 +291,7 @@ wasm 默认从 jsDelivr CDN 加载;向 `YOLO.load` 传入 `litertWasmUrl: "/li
288
291
  - **支持的任务**:detect、segment、semantic、depth、classify、pose 和 obb 均已支持。
289
292
  - **跨源隔离**:LiteRT 的多线程 wasm 需要 `SharedArrayBuffer`,因此请以
290
293
  `Cross-Origin-Opener-Policy: same-origin` 和 `Cross-Origin-Embedder-Policy: require-corp`
291
- 提供服务。
294
+ 提供服务。这会拦截默认 CDN 上的 wasm,因此还需传入同源的 `litertWasmUrl`。
292
295
 
293
296
  ## 🏎️ 基准测试
294
297
 
package/dist/index.d.ts CHANGED
@@ -82,8 +82,8 @@ export interface LoadOptions {
82
82
  * Optional base URL to self-host the ONNX Runtime Web build instead of
83
83
  * fetching it from `cdn.pyke.io`. The directory must contain
84
84
  * `ort.webgpu.min.js`, `ort-wasm-simd-threaded.jsep.wasm`, and
85
- * `ort-wasm-simd-threaded.jsep.mjs` for WebGPU, plus `ort.wasm.min.js` and
86
- * `ort-wasm-simd-threaded.wasm` for the CPU build, which is what a `"cpu"`
85
+ * `ort-wasm-simd-threaded.jsep.mjs` for WebGPU, plus `ort.wasm.min.js`,
86
+ * `ort-wasm-simd-threaded.wasm`, and `ort-wasm-simd-threaded.mjs` for the CPU build, which is what a `"cpu"`
87
87
  * device and the WebGPU fallback below load. Use an absolute URL ending in `/`.
88
88
  */
89
89
  ortBaseUrl?: string | URL;
@@ -159,6 +159,11 @@ export interface AnnotateOptions {
159
159
  * annotator); `1` shows the raw colorized depth map, `0` shows only the source.
160
160
  */
161
161
  depthAlpha?: number;
162
+ /**
163
+ * Optional URL/path to the wasm binary, as in {@link LoadOptions.wasmUrl}. Labels with
164
+ * right-to-left text need the engine, so pass it when no model has loaded it in this thread.
165
+ */
166
+ wasmUrl?: string | URL;
162
167
  }
163
168
  /** Image-like inputs accepted by {@link YOLO.predict}. */
164
169
  export type ImageInput = string | URL | Blob | ArrayBuffer | Uint8Array | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas | ImageBitmap;
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@
17
17
  * }
18
18
  * ```
19
19
  */
20
- import init, { YoloModel, YoloPipeline, start, pose_palette } from "../pkg/ultralytics_inference_web.js";
20
+ import init, { YoloModel, YoloPipeline, start, pose_palette, bidi_runs } from "../pkg/ultralytics_inference_web.js";
21
21
  let poseSchemeCache = null;
22
22
  /** The Ultralytics pose skeleton + per-keypoint/limb colors (constant). */
23
23
  function poseScheme() {
@@ -39,9 +39,7 @@ async function resolveDevice(pref) {
39
39
  console.warn("[@ultralytics/yolo] WebGPU requested but no adapter found; running on CPU.");
40
40
  return "cpu";
41
41
  }
42
- /** Ultralytics default thresholds (mirrored in the option JSDoc above). */
43
- const DEFAULT_CONF = 0.25;
44
- const DEFAULT_IOU = 0.7;
42
+ /** Ultralytics default keypoint confidence threshold for drawing. */
45
43
  const DEFAULT_KEYPOINT_THRESHOLD = 0.25;
46
44
  /** Whether `bytes` begin with a TFLite flatbuffer (the `TFL3` identifier at offset 4). */
47
45
  function isTflite(bytes) {
@@ -202,10 +200,13 @@ function ensureLiteRtRuntime(litert, wasmUrl) {
202
200
  litertInitUrl = wasmUrl;
203
201
  // Enable WASM multithreading when the page is cross-origin isolated (COOP/COEP
204
202
  // set, so SharedArrayBuffer is available); otherwise LiteRT.js runs single-
205
- // threaded. SIMD is detected by LiteRT itself. Isolation is a page-global
206
- // property, so this needs no per-load option.
207
- const threads = typeof crossOriginIsolated !== "undefined" && crossOriginIsolated;
208
- litertInit = litert.loadLiteRt(wasmUrl, { threads }).catch((e) => {
203
+ // threaded. LiteRT's threaded build also needs relaxed SIMD, which Safari lacks.
204
+ // Isolation is a page-global property, so this needs no per-load option.
205
+ const isolated = typeof crossOriginIsolated !== "undefined" && crossOriginIsolated;
206
+ litertInit = (async () => {
207
+ const threads = isolated && (await litert.supportsFeature("relaxedSimd"));
208
+ await litert.loadLiteRt(wasmUrl, { threads });
209
+ })().catch((e) => {
209
210
  litertInit = null; // let a later load retry if the first init failed
210
211
  litertInitUrl = null;
211
212
  throw e;
@@ -320,21 +321,18 @@ class LiteRtEngine {
320
321
  get names() {
321
322
  return this.pipeline.names;
322
323
  }
323
- predictDrawable(data, width, height, p) {
324
- return this.runDrawable(data, width, height, p);
325
- }
326
324
  /** LiteRT takes raw pixels, so decode encoded inputs to RGBA in JS first. */
327
325
  async predictEncoded(bytes, p) {
328
326
  const bitmap = await createImageBitmap(new Blob([bytes]));
329
327
  try {
330
328
  const { data, width, height } = toImageData(bitmap);
331
- return await this.runDrawable(data, width, height, p);
329
+ return await this.predictDrawable(data, width, height, p);
332
330
  }
333
331
  finally {
334
332
  bitmap.close();
335
333
  }
336
334
  }
337
- async runDrawable(data, width, height, p) {
335
+ async predictDrawable(data, width, height, p) {
338
336
  const input = this.pipeline.preprocess_rgba(data, width, height);
339
337
  const { outputs, shapes, inferenceMs } = await this.backend.run(input, Array.from(this.pipeline.inputShape));
340
338
  return this.pipeline.postprocess(outputs, shapes.map((s) => new Uint32Array(s)), inferenceMs, p.conf, p.iou, p.classes, p.colormap, p.depthViz);
@@ -418,8 +416,9 @@ export class YOLO {
418
416
  */
419
417
  async predict(image, options) {
420
418
  const p = {
421
- conf: options?.conf ?? DEFAULT_CONF,
422
- iou: options?.iou ?? DEFAULT_IOU,
419
+ // Unset thresholds fall back to the Rust `InferenceConfig` defaults.
420
+ conf: options?.conf,
421
+ iou: options?.iou,
423
422
  classes: options?.classes ? new Uint32Array(options.classes) : undefined,
424
423
  // Empty means "unset": the wasm side falls back to the Rust `Colormap`/`DepthViz`
425
424
  // defaults, so the default lives in exactly one place.
@@ -456,7 +455,7 @@ function textColorFor(hex) {
456
455
  const g = parseInt(hex.slice(3, 5), 16);
457
456
  const b = parseInt(hex.slice(5, 7), 16);
458
457
  // Perceived luminance (same threshold Ultralytics uses).
459
- return r * 0.299 + g * 0.587 + b * 0.114 > 140 ? "#000000" : "#FFFFFF";
458
+ return r * 0.299 + g * 0.587 + b * 0.114 > 150 ? "#000000" : "#FFFFFF";
460
459
  }
461
460
  /**
462
461
  * Draw inference results onto a canvas, on top of the source image.
@@ -511,17 +510,47 @@ export async function annotate(canvas, image, results, options) {
511
510
  ctx.lineWidth = lineWidth;
512
511
  ctx.font = font;
513
512
  ctx.textBaseline = "top";
513
+ ctx.textAlign = "left";
514
+ // Labels that may hold right-to-left text (Unicode's right-to-left blocks and controls) are
515
+ // drawn as the engine's bidi runs, each in its resolved direction, since Safari's canvas
516
+ // does not pair brackets in right-to-left text. Other labels read left to right as they are.
517
+ const rtlText = /[\u0590-\u08FF\u200F\u202B\u202E\u2067\u2068\uFB1D-\uFDFF\uFE70-\uFEFF\u{10800}-\u{10FFF}\u{1E800}-\u{1EFFF}]/u;
518
+ const names = [...results.boxes, ...results.obb].map((b) => b.name);
519
+ if (showLabels && names.concat(results.probs?.top5names ?? []).some((n) => rtlText.test(n))) {
520
+ await ensureInit(options?.wasmUrl);
521
+ }
522
+ // Class names repeat across labels, so each run's width is measured once per call.
523
+ const widths = new Map();
524
+ const layout = (text) => (rtlText.test(text) ? bidi_runs(text) : [text]).map((run) => {
525
+ const rtl = run.startsWith("\u202E");
526
+ let width = widths.get(run);
527
+ if (width === undefined) {
528
+ ctx.direction = rtl ? "rtl" : "ltr";
529
+ width = ctx.measureText(run).width;
530
+ widths.set(run, width);
531
+ }
532
+ return { text: run, rtl, width };
533
+ });
534
+ const runsWidth = (runs) => runs.reduce((sum, run) => sum + run.width, 0);
535
+ const fillText = (runs, x, y) => {
536
+ for (const run of runs) {
537
+ ctx.direction = run.rtl ? "rtl" : "ltr";
538
+ ctx.fillText(run.text, x, y);
539
+ x += run.width;
540
+ }
541
+ };
514
542
  const label = (text, x, y, color) => {
515
543
  if (!showLabels)
516
544
  return;
517
545
  const pad = Math.round(fontSize * 0.2);
518
- const w = ctx.measureText(text).width + pad * 2;
546
+ const runs = layout(text);
547
+ const w = runsWidth(runs) + pad * 2;
519
548
  const h = fontSize + pad * 2;
520
549
  const ly = Math.max(0, y - h);
521
550
  ctx.fillStyle = color;
522
551
  ctx.fillRect(x, ly, w, h);
523
552
  ctx.fillStyle = textColorFor(color);
524
- ctx.fillText(text, x + pad, ly + pad);
553
+ fillText(runs, x + pad, ly + pad);
525
554
  };
526
555
  // Axis-aligned boxes (detect / segment / pose).
527
556
  for (const b of results.boxes) {
@@ -595,15 +624,15 @@ export async function annotate(canvas, image, results, options) {
595
624
  // and Python renderers, which list the top classes rather than a single banner).
596
625
  if (results.probs && showLabels) {
597
626
  const { top5, top5conf, top5names } = results.probs;
598
- const lines = top5.map((_, i) => `${top5names[i] ?? top5[i]} ${top5conf[i].toFixed(2)}`);
627
+ const lines = top5.map((_, i) => layout(`${top5names[i] ?? top5[i]} ${top5conf[i].toFixed(2)}`));
599
628
  const pad = Math.round(fontSize * 0.3);
600
629
  const lineH = Math.round(fontSize * 1.25);
601
- const boxW = Math.max(...lines.map((t) => ctx.measureText(t).width)) + pad * 2;
630
+ const boxW = Math.max(...lines.map(runsWidth)) + pad * 2;
602
631
  const boxH = lines.length * lineH + pad * 2;
603
632
  ctx.fillStyle = "rgba(0, 0, 0, 0.4)";
604
633
  ctx.fillRect(pad, pad, boxW, boxH);
605
634
  ctx.fillStyle = "#ffffff";
606
- lines.forEach((t, i) => ctx.fillText(t, pad * 2, pad * 2 + i * lineH));
635
+ lines.forEach((t, i) => fillText(t, pad * 2, pad * 2 + i * lineH));
607
636
  }
608
637
  }
609
638
  /** Resolve any {@link ImageInput} to something `drawImage` accepts. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultralytics/yolo",
3
- "version": "0.0.55",
3
+ "version": "0.0.56",
4
4
  "description": "Run Ultralytics YOLO models in the browser on WebGPU (WebAssembly, ONNX Runtime Web via ort-web).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/pkg/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "ultralytics-inference-web",
3
3
  "type": "module",
4
4
  "description": "Browser/WebAssembly bindings for ultralytics-inference (WebGPU via ort-web)",
5
- "version": "0.0.55",
5
+ "version": "0.0.56",
6
6
  "license": "AGPL-3.0",
7
7
  "repository": {
8
8
  "type": "git",
@@ -33,15 +33,15 @@ export class YoloModel {
33
33
  /**
34
34
  * Run inference on a single encoded image (JPEG or PNG bytes).
35
35
  *
36
- * `conf` and `iou` are the confidence and NMS IoU thresholds (pass the model
37
- * defaults 0.25 / 0.7 to match Ultralytics); `classes` optionally keeps only
36
+ * `conf` and `iou` are the confidence and NMS IoU thresholds (omit them for the
37
+ * Ultralytics defaults 0.25 / 0.7); `classes` optionally keeps only
38
38
  * the given class ids (for semantic, other pixels become background).
39
39
  * Returns a plain JS object whose shape mirrors the Ultralytics `Results` API.
40
40
  *
41
41
  * # Errors
42
42
  * Returns a JS error if the image cannot be decoded or inference fails.
43
43
  */
44
- predict(image: Uint8Array, conf: number, iou: number, classes: Uint32Array | null | undefined, colormap: string, depth_viz: string): Promise<any>;
44
+ predict(image: Uint8Array, conf: number | null | undefined, iou: number | null | undefined, classes: Uint32Array | null | undefined, colormap: string, depth_viz: string): Promise<any>;
45
45
  /**
46
46
  * Run inference on raw `RGBA` pixels (e.g. a canvas/webcam `ImageData`).
47
47
  *
@@ -51,7 +51,7 @@ export class YoloModel {
51
51
  * # Errors
52
52
  * Returns a JS error if the buffer size is wrong or inference fails.
53
53
  */
54
- predict_rgba(rgba: Uint8Array, width: number, height: number, conf: number, iou: number, classes: Uint32Array | null | undefined, colormap: string, depth_viz: string): Promise<any>;
54
+ predict_rgba(rgba: Uint8Array, width: number, height: number, conf: number | null | undefined, iou: number | null | undefined, classes: Uint32Array | null | undefined, colormap: string, depth_viz: string): Promise<any>;
55
55
  /**
56
56
  * The active device: `"webgpu"` or `"cpu"` (the fallback when WebGPU is
57
57
  * unavailable). Mirrors the native `Device` display.
@@ -110,7 +110,7 @@ export class YoloPipeline {
110
110
  * Returns a JS error if called before `preprocess_rgba`, if `shapes` does not
111
111
  * have one entry per output, or on serialization failure.
112
112
  */
113
- postprocess(outputs: Float32Array[], shapes: Uint32Array[], inference_ms: number, conf: number, iou: number, classes: Uint32Array | null | undefined, colormap: string, depth_viz: string): any;
113
+ postprocess(outputs: Float32Array[], shapes: Uint32Array[], inference_ms: number, conf: number | null | undefined, iou: number | null | undefined, classes: Uint32Array | null | undefined, colormap: string, depth_viz: string): any;
114
114
  /**
115
115
  * Preprocess raw RGBA pixels (e.g. a webcam `ImageData`) into the NCHW f32
116
116
  * input tensor an Ultralytics LiteRT/TFLite model expects, normalized to
@@ -139,10 +139,6 @@ export class YoloPipeline {
139
139
  * the metadata size in place.
140
140
  */
141
141
  setInputShape(shape: Int32Array): void;
142
- /**
143
- * Whether this is an NMS-free export, e.g. YOLO26 with `nms=False`.
144
- */
145
- readonly end2end: boolean;
146
142
  /**
147
143
  * The model input shape as `[1, 3, H, W]` (NCHW), for sizing the engine's
148
144
  * input tensor. Ultralytics LiteRT exports (`ai_edge_torch`) keep the native
@@ -156,16 +152,21 @@ export class YoloPipeline {
156
152
  * Returns a JS error only if serialization fails (not expected).
157
153
  */
158
154
  readonly names: any;
159
- /**
160
- * Whether this is an RT-DETR export.
161
- */
162
- readonly rtdetr: boolean;
163
155
  /**
164
156
  * The model's task (`"detect"`, `"segment"`, ...).
165
157
  */
166
158
  readonly task: string;
167
159
  }
168
160
 
161
+ /**
162
+ * Split a label into runs in left-to-right display order (Unicode bidi algorithm), each wrapped
163
+ * in a left-to-right or right-to-left override so canvas draws it in its resolved direction. The
164
+ * JS annotator draws runs one by one because Safari's canvas does not pair brackets in
165
+ * right-to-left text. Explicit embeddings, overrides and isolates are dropped, since the
166
+ * resolved levels already carry them.
167
+ */
168
+ export function bidi_runs(text: string): string[];
169
+
169
170
  /**
170
171
  * Return the Ultralytics pose skeleton + keypoint/limb colors (constant). The
171
172
  * JS annotator calls this once to color pose overlays from the shared palette.
@@ -186,6 +187,7 @@ export interface InitOutput {
186
187
  readonly memory: WebAssembly.Memory;
187
188
  readonly __wbg_yolomodel_free: (a: number, b: number) => void;
188
189
  readonly __wbg_yolopipeline_free: (a: number, b: number) => void;
190
+ readonly bidi_runs: (a: number, b: number, c: number) => void;
189
191
  readonly pose_palette: (a: number) => void;
190
192
  readonly start: () => void;
191
193
  readonly yolomodel_device: (a: number, b: number) => void;
@@ -194,19 +196,17 @@ export interface InitOutput {
194
196
  readonly yolomodel_predict: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => number;
195
197
  readonly yolomodel_predict_rgba: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number) => number;
196
198
  readonly yolomodel_task: (a: number, b: number) => void;
197
- readonly yolopipeline_end2end: (a: number) => number;
198
199
  readonly yolopipeline_inputShape: (a: number, b: number) => void;
199
200
  readonly yolopipeline_names: (a: number, b: number) => void;
200
201
  readonly yolopipeline_new: (a: number, b: number, c: number) => void;
201
202
  readonly yolopipeline_postprocess: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number) => void;
202
203
  readonly yolopipeline_preprocess_rgba: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
203
- readonly yolopipeline_rtdetr: (a: number) => number;
204
204
  readonly yolopipeline_setInputShape: (a: number, b: number, c: number) => void;
205
205
  readonly yolopipeline_task: (a: number, b: number) => void;
206
- readonly __wasm_bindgen_func_elem_1192: (a: number, b: number, c: number, d: number) => void;
207
- readonly __wasm_bindgen_func_elem_1823: (a: number, b: number, c: number, d: number) => void;
206
+ readonly __wasm_bindgen_func_elem_1216: (a: number, b: number, c: number, d: number) => void;
208
207
  readonly __wasm_bindgen_func_elem_1847: (a: number, b: number, c: number, d: number) => void;
209
- readonly __wasm_bindgen_func_elem_377: (a: number, b: number, c: number, d: number) => void;
208
+ readonly __wasm_bindgen_func_elem_1871: (a: number, b: number, c: number, d: number) => void;
209
+ readonly __wasm_bindgen_func_elem_382: (a: number, b: number, c: number, d: number) => void;
210
210
  readonly __wbindgen_export: (a: number, b: number) => number;
211
211
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
212
212
  readonly __wbindgen_export3: (a: number) => void;
@@ -104,16 +104,16 @@ export class YoloModel {
104
104
  /**
105
105
  * Run inference on a single encoded image (JPEG or PNG bytes).
106
106
  *
107
- * `conf` and `iou` are the confidence and NMS IoU thresholds (pass the model
108
- * defaults 0.25 / 0.7 to match Ultralytics); `classes` optionally keeps only
107
+ * `conf` and `iou` are the confidence and NMS IoU thresholds (omit them for the
108
+ * Ultralytics defaults 0.25 / 0.7); `classes` optionally keeps only
109
109
  * the given class ids (for semantic, other pixels become background).
110
110
  * Returns a plain JS object whose shape mirrors the Ultralytics `Results` API.
111
111
  *
112
112
  * # Errors
113
113
  * Returns a JS error if the image cannot be decoded or inference fails.
114
114
  * @param {Uint8Array} image
115
- * @param {number} conf
116
- * @param {number} iou
115
+ * @param {number | null | undefined} conf
116
+ * @param {number | null | undefined} iou
117
117
  * @param {Uint32Array | null | undefined} classes
118
118
  * @param {string} colormap
119
119
  * @param {string} depth_viz
@@ -128,7 +128,7 @@ export class YoloModel {
128
128
  const len2 = WASM_VECTOR_LEN;
129
129
  const ptr3 = passStringToWasm0(depth_viz, wasm.__wbindgen_export, wasm.__wbindgen_export2);
130
130
  const len3 = WASM_VECTOR_LEN;
131
- const ret = wasm.yolomodel_predict(this.__wbg_ptr, ptr0, len0, conf, iou, ptr1, len1, ptr2, len2, ptr3, len3);
131
+ const ret = wasm.yolomodel_predict(this.__wbg_ptr, ptr0, len0, isLikeNone(conf) ? Number.MAX_SAFE_INTEGER : Math.fround(conf), isLikeNone(iou) ? Number.MAX_SAFE_INTEGER : Math.fround(iou), ptr1, len1, ptr2, len2, ptr3, len3);
132
132
  return takeObject(ret);
133
133
  }
134
134
  /**
@@ -142,8 +142,8 @@ export class YoloModel {
142
142
  * @param {Uint8Array} rgba
143
143
  * @param {number} width
144
144
  * @param {number} height
145
- * @param {number} conf
146
- * @param {number} iou
145
+ * @param {number | null | undefined} conf
146
+ * @param {number | null | undefined} iou
147
147
  * @param {Uint32Array | null | undefined} classes
148
148
  * @param {string} colormap
149
149
  * @param {string} depth_viz
@@ -158,7 +158,7 @@ export class YoloModel {
158
158
  const len2 = WASM_VECTOR_LEN;
159
159
  const ptr3 = passStringToWasm0(depth_viz, wasm.__wbindgen_export, wasm.__wbindgen_export2);
160
160
  const len3 = WASM_VECTOR_LEN;
161
- const ret = wasm.yolomodel_predict_rgba(this.__wbg_ptr, ptr0, len0, width, height, conf, iou, ptr1, len1, ptr2, len2, ptr3, len3);
161
+ const ret = wasm.yolomodel_predict_rgba(this.__wbg_ptr, ptr0, len0, width, height, isLikeNone(conf) ? Number.MAX_SAFE_INTEGER : Math.fround(conf), isLikeNone(iou) ? Number.MAX_SAFE_INTEGER : Math.fround(iou), ptr1, len1, ptr2, len2, ptr3, len3);
162
162
  return takeObject(ret);
163
163
  }
164
164
  /**
@@ -207,14 +207,6 @@ export class YoloPipeline {
207
207
  const ptr = this.__destroy_into_raw();
208
208
  wasm.__wbg_yolopipeline_free(ptr, 0);
209
209
  }
210
- /**
211
- * Whether this is an NMS-free export, e.g. YOLO26 with `nms=False`.
212
- * @returns {boolean}
213
- */
214
- get end2end() {
215
- const ret = wasm.yolopipeline_end2end(this.__wbg_ptr);
216
- return ret !== 0;
217
- }
218
210
  /**
219
211
  * The model input shape as `[1, 3, H, W]` (NCHW), for sizing the engine's
220
212
  * input tensor. Ultralytics LiteRT exports (`ai_edge_torch`) keep the native
@@ -302,8 +294,8 @@ export class YoloPipeline {
302
294
  * @param {Float32Array[]} outputs
303
295
  * @param {Uint32Array[]} shapes
304
296
  * @param {number} inference_ms
305
- * @param {number} conf
306
- * @param {number} iou
297
+ * @param {number | null | undefined} conf
298
+ * @param {number | null | undefined} iou
307
299
  * @param {Uint32Array | null | undefined} classes
308
300
  * @param {string} colormap
309
301
  * @param {string} depth_viz
@@ -322,7 +314,7 @@ export class YoloPipeline {
322
314
  const len3 = WASM_VECTOR_LEN;
323
315
  const ptr4 = passStringToWasm0(depth_viz, wasm.__wbindgen_export, wasm.__wbindgen_export2);
324
316
  const len4 = WASM_VECTOR_LEN;
325
- wasm.yolopipeline_postprocess(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, inference_ms, conf, iou, ptr2, len2, ptr3, len3, ptr4, len4);
317
+ wasm.yolopipeline_postprocess(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, inference_ms, isLikeNone(conf) ? Number.MAX_SAFE_INTEGER : Math.fround(conf), isLikeNone(iou) ? Number.MAX_SAFE_INTEGER : Math.fround(iou), ptr2, len2, ptr3, len3, ptr4, len4);
326
318
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
327
319
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
328
320
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -367,14 +359,6 @@ export class YoloPipeline {
367
359
  wasm.__wbindgen_add_to_stack_pointer(16);
368
360
  }
369
361
  }
370
- /**
371
- * Whether this is an RT-DETR export.
372
- * @returns {boolean}
373
- */
374
- get rtdetr() {
375
- const ret = wasm.yolopipeline_rtdetr(this.__wbg_ptr);
376
- return ret !== 0;
377
- }
378
362
  /**
379
363
  * Adopt the input shape the engine reports for the compiled model.
380
364
  *
@@ -418,6 +402,31 @@ export class YoloPipeline {
418
402
  }
419
403
  if (Symbol.dispose) YoloPipeline.prototype[Symbol.dispose] = YoloPipeline.prototype.free;
420
404
 
405
+ /**
406
+ * Split a label into runs in left-to-right display order (Unicode bidi algorithm), each wrapped
407
+ * in a left-to-right or right-to-left override so canvas draws it in its resolved direction. The
408
+ * JS annotator draws runs one by one because Safari's canvas does not pair brackets in
409
+ * right-to-left text. Explicit embeddings, overrides and isolates are dropped, since the
410
+ * resolved levels already carry them.
411
+ * @param {string} text
412
+ * @returns {string[]}
413
+ */
414
+ export function bidi_runs(text) {
415
+ try {
416
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
417
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
418
+ const len0 = WASM_VECTOR_LEN;
419
+ wasm.bidi_runs(retptr, ptr0, len0);
420
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
421
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
422
+ var v2 = getArrayJsValueFromWasm0(r0, r1);
423
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
424
+ return v2;
425
+ } finally {
426
+ wasm.__wbindgen_add_to_stack_pointer(16);
427
+ }
428
+ }
429
+
421
430
  /**
422
431
  * Return the Ultralytics pose skeleton + keypoint/limb colors (constant). The
423
432
  * JS annotator calls this once to color pose overlays from the shared palette.
@@ -755,7 +764,7 @@ function __wbg_get_imports() {
755
764
  const a = state0.a;
756
765
  state0.a = 0;
757
766
  try {
758
- return __wasm_bindgen_func_elem_1847(a, state0.b, arg0, arg1);
767
+ return __wasm_bindgen_func_elem_1871(a, state0.b, arg0, arg1);
759
768
  } finally {
760
769
  state0.a = a;
761
770
  }
@@ -947,18 +956,18 @@ function __wbg_get_imports() {
947
956
  return addHeapObject(ret);
948
957
  },
949
958
  __wbindgen_generic_0000000000000001: function(arg0, arg1) {
950
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 364, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
951
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1192);
959
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 365, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
960
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1216);
952
961
  return addHeapObject(ret);
953
962
  },
954
963
  __wbindgen_generic_0000000000000002: function(arg0, arg1) {
955
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 648, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
956
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1823);
964
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 649, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
965
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1847);
957
966
  return addHeapObject(ret);
958
967
  },
959
968
  __wbindgen_generic_0000000000000003: function(arg0, arg1) {
960
969
  // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("boolean")], shim_idx: 21, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
961
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_377);
970
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_382);
962
971
  return addHeapObject(ret);
963
972
  },
964
973
  __wbindgen_generic_0000000000000004: function(arg0) {
@@ -1045,14 +1054,14 @@ function __wbg_get_imports() {
1045
1054
  };
1046
1055
  }
1047
1056
 
1048
- function __wasm_bindgen_func_elem_1847(arg0, arg1, arg2, arg3) {
1049
- wasm.__wasm_bindgen_func_elem_1847(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1057
+ function __wasm_bindgen_func_elem_1871(arg0, arg1, arg2, arg3) {
1058
+ wasm.__wasm_bindgen_func_elem_1871(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1050
1059
  }
1051
1060
 
1052
- function __wasm_bindgen_func_elem_1192(arg0, arg1, arg2) {
1061
+ function __wasm_bindgen_func_elem_1216(arg0, arg1, arg2) {
1053
1062
  try {
1054
1063
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1055
- wasm.__wasm_bindgen_func_elem_1192(retptr, arg0, arg1, addHeapObject(arg2));
1064
+ wasm.__wasm_bindgen_func_elem_1216(retptr, arg0, arg1, addHeapObject(arg2));
1056
1065
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1057
1066
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1058
1067
  if (r1) {
@@ -1063,10 +1072,10 @@ function __wasm_bindgen_func_elem_1192(arg0, arg1, arg2) {
1063
1072
  }
1064
1073
  }
1065
1074
 
1066
- function __wasm_bindgen_func_elem_1823(arg0, arg1, arg2) {
1075
+ function __wasm_bindgen_func_elem_1847(arg0, arg1, arg2) {
1067
1076
  try {
1068
1077
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1069
- wasm.__wasm_bindgen_func_elem_1823(retptr, arg0, arg1, addHeapObject(arg2));
1078
+ wasm.__wasm_bindgen_func_elem_1847(retptr, arg0, arg1, addHeapObject(arg2));
1070
1079
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1071
1080
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1072
1081
  if (r1) {
@@ -1077,10 +1086,10 @@ function __wasm_bindgen_func_elem_1823(arg0, arg1, arg2) {
1077
1086
  }
1078
1087
  }
1079
1088
 
1080
- function __wasm_bindgen_func_elem_377(arg0, arg1, arg2) {
1089
+ function __wasm_bindgen_func_elem_382(arg0, arg1, arg2) {
1081
1090
  try {
1082
1091
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1083
- wasm.__wasm_bindgen_func_elem_377(retptr, arg0, arg1, addHeapObject(arg2));
1092
+ wasm.__wasm_bindgen_func_elem_382(retptr, arg0, arg1, addHeapObject(arg2));
1084
1093
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1085
1094
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1086
1095
  if (r1) {
@@ -1217,6 +1226,16 @@ function getArrayI8FromWasm0(ptr, len) {
1217
1226
  return getInt8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
1218
1227
  }
1219
1228
 
1229
+ function getArrayJsValueFromWasm0(ptr, len) {
1230
+ ptr = ptr >>> 0;
1231
+ const mem = getDataViewMemory0();
1232
+ const result = [];
1233
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
1234
+ result.push(takeObject(mem.getUint32(i, true)));
1235
+ }
1236
+ return result;
1237
+ }
1238
+
1220
1239
  function getArrayU16FromWasm0(ptr, len) {
1221
1240
  ptr = ptr >>> 0;
1222
1241
  return getUint16ArrayMemory0().subarray(ptr / 2, ptr / 2 + len);
@@ -3,6 +3,7 @@
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_yolomodel_free: (a: number, b: number) => void;
5
5
  export const __wbg_yolopipeline_free: (a: number, b: number) => void;
6
+ export const bidi_runs: (a: number, b: number, c: number) => void;
6
7
  export const pose_palette: (a: number) => void;
7
8
  export const start: () => void;
8
9
  export const yolomodel_device: (a: number, b: number) => void;
@@ -11,19 +12,17 @@ export const yolomodel_names: (a: number, b: number) => void;
11
12
  export const yolomodel_predict: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => number;
12
13
  export const yolomodel_predict_rgba: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number) => number;
13
14
  export const yolomodel_task: (a: number, b: number) => void;
14
- export const yolopipeline_end2end: (a: number) => number;
15
15
  export const yolopipeline_inputShape: (a: number, b: number) => void;
16
16
  export const yolopipeline_names: (a: number, b: number) => void;
17
17
  export const yolopipeline_new: (a: number, b: number, c: number) => void;
18
18
  export const yolopipeline_postprocess: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number) => void;
19
19
  export const yolopipeline_preprocess_rgba: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
20
- export const yolopipeline_rtdetr: (a: number) => number;
21
20
  export const yolopipeline_setInputShape: (a: number, b: number, c: number) => void;
22
21
  export const yolopipeline_task: (a: number, b: number) => void;
23
- export const __wasm_bindgen_func_elem_1192: (a: number, b: number, c: number, d: number) => void;
24
- export const __wasm_bindgen_func_elem_1823: (a: number, b: number, c: number, d: number) => void;
22
+ export const __wasm_bindgen_func_elem_1216: (a: number, b: number, c: number, d: number) => void;
25
23
  export const __wasm_bindgen_func_elem_1847: (a: number, b: number, c: number, d: number) => void;
26
- export const __wasm_bindgen_func_elem_377: (a: number, b: number, c: number, d: number) => void;
24
+ export const __wasm_bindgen_func_elem_1871: (a: number, b: number, c: number, d: number) => void;
25
+ export const __wasm_bindgen_func_elem_382: (a: number, b: number, c: number, d: number) => void;
27
26
  export const __wbindgen_export: (a: number, b: number) => number;
28
27
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
29
28
  export const __wbindgen_export3: (a: number) => void;