@ultralytics/yolo 0.0.56 → 0.0.57

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
@@ -85,7 +85,7 @@ await annotate(document.querySelector("canvas"), "bus.jpg", results);
85
85
  `HTMLCanvasElement`, `HTMLVideoElement`, an `OffscreenCanvas`, or an `ImageBitmap`.
86
86
 
87
87
  ```ts
88
- const results = await model.predict(canvas, { conf: 0.25, iou: 0.7 });
88
+ const results = await model.predict(canvas, { conf: 0.25, iou: 0.5 });
89
89
  console.log(model.device); // "webgpu" or "cpu"
90
90
  ```
91
91
 
@@ -160,9 +160,10 @@ Rust/Ultralytics `Results` API one-to-one:
160
160
  | `speed` | `{ preprocess, inference, postprocess }` ms | all |
161
161
 
162
162
  `model.names` is the class id to name map (like `model.names` in Python). Every
163
- detection carries its Ultralytics palette `color`, and `annotate()` draws the
163
+ detection carries its class `color` (the model's `colors` metadata entry, else the
164
+ Ultralytics palette), and `annotate()` draws the
164
165
  `masks` overlay and the pose skeleton with the same per-limb/keypoint colors as
165
- the native renderer. None of this is duplicated in JS.
166
+ the native renderer.
166
167
 
167
168
  For the `depth` task, `predict(img, { colormap, depthViz })` picks the colormap
168
169
  (`"jet"` default, `"inferno"`, `"spectral"`, `"gray"`) and normalization
@@ -230,13 +231,16 @@ the model), pass the same `wasmUrl` you gave `YOLO.load`.
230
231
  bundle (~25 MB, browser-cached afterward) from `cdn.pyke.io`. If you set a
231
232
  Content-Security-Policy, allow that origin in `script-src`/`connect-src`. To
232
233
  avoid the CDN entirely, self-host the runtime and point to it:
234
+
233
235
  ```ts
234
236
  const model = await YOLO.load("/models/yolo26n.onnx", { ortBaseUrl: "/ort/" });
235
237
  ```
238
+
236
239
  The folder must contain the ONNX Runtime Web entry scripts (`ort.webgpu.min.js`
237
240
  and `ort.wasm.min.js` for the CPU fallback) plus the
238
241
  `ort-wasm-simd-threaded.{jsep,asyncify,}.{mjs,wasm}` binaries. If your bundler does not serve this package's
239
242
  own `ultralytics_inference_web_bg.wasm`, pass its URL as `wasmUrl`.
243
+
240
244
  - **Telemetry**: `ort-web` can report the page domain to pyke on first session
241
245
  creation. This package turns that off, so nothing is sent. See the
242
246
  [ort-web docs](https://ort.pyke.io/backends/web) for what it would send.
package/README.zh-CN.md CHANGED
@@ -82,7 +82,7 @@ await annotate(document.querySelector("canvas"), "bus.jpg", results);
82
82
  `ImageData`、`HTMLImageElement`、`HTMLCanvasElement`、`HTMLVideoElement`、`OffscreenCanvas` 或 `ImageBitmap`。
83
83
 
84
84
  ```ts
85
- const results = await model.predict(canvas, { conf: 0.25, iou: 0.7 });
85
+ const results = await model.predict(canvas, { conf: 0.25, iou: 0.5 });
86
86
  console.log(model.device); // "webgpu" 或 "cpu"
87
87
  ```
88
88
 
@@ -155,8 +155,8 @@ GitHub release 资源不会返回 `Access-Control-Allow-Origin`,因此浏览
155
155
  | `speed` | `{ preprocess, inference, postprocess }`,单位 ms | 全部 |
156
156
 
157
157
  `model.names` 是类别 id 到名称的映射(相当于 Python 中的 `model.names`)。每个检测结果都带有
158
- Ultralytics 调色板中的 `color`,`annotate()` 绘制 `masks` 叠加层和姿态骨架时,使用的每条肢体/
159
- 关键点配色与原生渲染器完全一致。这些逻辑都没有在 JS 中重复实现。
158
+ 其类别的 `color`(模型 `colors` 元数据中的颜色,否则为 Ultralytics 调色板颜色),`annotate()` 绘制 `masks`
159
+ 叠加层和姿态骨架时,使用的每条肢体/关键点配色与原生渲染器完全一致。
160
160
 
161
161
  对于 `depth` 任务,`predict(img, { colormap, depthViz })` 用于选择配色方案(默认 `"jet"`,
162
162
  另有 `"inferno"`、`"spectral"`、`"gray"`)和归一化方式(默认 `"disparity"`,另有 `"metric"`);
@@ -215,12 +215,15 @@ await annotate(canvas, img, results, { keypointRadius: 4, skeleton: [[0, 1]] });
215
215
  - **运行时资源**:首次加载时,`ort-web` 会从 `cdn.pyke.io` 获取 ONNX Runtime Web 的 wasm 包
216
216
  (约 25 MB,之后由浏览器缓存)。如果你设置了 Content-Security-Policy,请在
217
217
  `script-src`/`connect-src` 中放行该源。若想完全避开 CDN,可自行托管运行时并指向它:
218
+
218
219
  ```ts
219
220
  const model = await YOLO.load("/models/yolo26n.onnx", { ortBaseUrl: "/ort/" });
220
221
  ```
222
+
221
223
  该目录需包含 ONNX Runtime Web 的入口脚本(`ort.webgpu.min.js`,以及 CPU 回退所需的
222
224
  `ort.wasm.min.js`)和 `ort-wasm-simd-threaded.{jsep,asyncify,}.{mjs,wasm}` 二进制文件。如果打包工具没有提供本包自带的
223
225
  `ultralytics_inference_web_bg.wasm`,可通过 `wasmUrl` 传入其 URL。
226
+
224
227
  - **遥测**:`ort-web` 可以在首次创建会话时向 pyke 上报页面域名。本包已将其关闭,不会发送任何数据。
225
228
  上报内容见 [ort-web 文档](https://ort.pyke.io/backends/web)。
226
229
 
package/dist/index.d.ts CHANGED
@@ -112,7 +112,7 @@ export type ModelSource = string | URL | ArrayBuffer | Uint8Array | Blob;
112
112
  export interface PredictOptions {
113
113
  /** Confidence threshold. Default `0.25` (matches Ultralytics). */
114
114
  conf?: number;
115
- /** NMS IoU threshold. Default `0.7` (matches Ultralytics). */
115
+ /** NMS IoU threshold. Default `0.5` (matches Ultralytics predict). */
116
116
  iou?: number;
117
117
  /**
118
118
  * Keep only these class ids. Omit to keep all. Filters detections for
package/dist/index.js CHANGED
@@ -447,15 +447,12 @@ export class YOLO {
447
447
  this.engine.free();
448
448
  }
449
449
  }
450
- // Colors come from the Rust engine (the Ultralytics palette) on each detection,
451
- // so there is no palette duplicated here.
452
- /** Pick black or white text for readability over a given hex background. */
450
+ /** Label text color over a `#rrggbb` background, the rule of `Color::text_color` in the engine. */
453
451
  function textColorFor(hex) {
454
452
  const r = parseInt(hex.slice(1, 3), 16);
455
453
  const g = parseInt(hex.slice(3, 5), 16);
456
454
  const b = parseInt(hex.slice(5, 7), 16);
457
- // Perceived luminance (same threshold Ultralytics uses).
458
- return r * 0.299 + g * 0.587 + b * 0.114 > 150 ? "#000000" : "#FFFFFF";
455
+ return r * 0.299 + g * 0.587 + b * 0.114 > 150 ? "#111F68" : "#FFFFFF";
459
456
  }
460
457
  /**
461
458
  * Draw inference results onto a canvas, on top of the source image.
@@ -590,19 +587,20 @@ export async function annotate(canvas, image, results, options) {
590
587
  ctx.lineWidth = Math.max(1, Math.round(lineWidth / 1.5));
591
588
  for (const kp of results.keypoints) {
592
589
  // Like Ultralytics, only the 17-keypoint COCO-Pose layout gets the pose palette and the
593
- // human skeleton; other layouts take one palette color per keypoint and no lines.
590
+ // human skeleton; other layouts take one class palette color per keypoint and no lines,
591
+ // and a custom skeleton colors each line like its start keypoint.
594
592
  const coco = kp.points.length === scheme.keypoint_colors.length;
595
593
  const skeleton = options?.skeleton ?? (coco ? scheme.skeleton : []);
596
594
  const paletteAt = (i) => scheme.palette[i % scheme.palette.length];
597
- const limbColor = (i) => fixed ?? (coco && !options?.skeleton ? scheme.limb_colors[i] : paletteAt(i));
598
595
  const kptColor = (i) => fixed ?? (coco ? scheme.keypoint_colors[i] : paletteAt(i));
596
+ const limbColor = (i, a) => coco && !options?.skeleton ? (fixed ?? scheme.limb_colors[i]) : kptColor(a);
599
597
  if (options?.keypointLines ?? true) {
600
598
  skeleton.forEach(([a, b], li) => {
601
599
  const pa = kp.points[a];
602
600
  const pb = kp.points[b];
603
601
  if (!pa || !pb || pa[2] < kptThresh || pb[2] < kptThresh)
604
602
  return;
605
- ctx.strokeStyle = limbColor(li);
603
+ ctx.strokeStyle = limbColor(li, a);
606
604
  ctx.beginPath();
607
605
  ctx.moveTo(pa[0], pa[1]);
608
606
  ctx.lineTo(pb[0], pb[1]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultralytics/yolo",
3
- "version": "0.0.56",
3
+ "version": "0.0.57",
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.56",
5
+ "version": "0.0.57",
6
6
  "license": "AGPL-3.0",
7
7
  "repository": {
8
8
  "type": "git",
@@ -34,7 +34,7 @@ export class YoloModel {
34
34
  * Run inference on a single encoded image (JPEG or PNG bytes).
35
35
  *
36
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
37
+ * Ultralytics defaults 0.25 / 0.5); `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
  *
@@ -203,9 +203,9 @@ export interface InitOutput {
203
203
  readonly yolopipeline_preprocess_rgba: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
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_1216: (a: number, b: number, c: number, d: number) => void;
207
- readonly __wasm_bindgen_func_elem_1847: (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;
206
+ readonly __wasm_bindgen_func_elem_1232: (a: number, b: number, c: number, d: number) => void;
207
+ readonly __wasm_bindgen_func_elem_1863: (a: number, b: number, c: number, d: number) => void;
208
+ readonly __wasm_bindgen_func_elem_1887: (a: number, b: number, c: number, d: number) => void;
209
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;
@@ -105,7 +105,7 @@ export class YoloModel {
105
105
  * Run inference on a single encoded image (JPEG or PNG bytes).
106
106
  *
107
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
108
+ * Ultralytics defaults 0.25 / 0.5); `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
  *
@@ -764,7 +764,7 @@ function __wbg_get_imports() {
764
764
  const a = state0.a;
765
765
  state0.a = 0;
766
766
  try {
767
- return __wasm_bindgen_func_elem_1871(a, state0.b, arg0, arg1);
767
+ return __wasm_bindgen_func_elem_1887(a, state0.b, arg0, arg1);
768
768
  } finally {
769
769
  state0.a = a;
770
770
  }
@@ -956,13 +956,13 @@ function __wbg_get_imports() {
956
956
  return addHeapObject(ret);
957
957
  },
958
958
  __wbindgen_generic_0000000000000001: function(arg0, arg1) {
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);
959
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 371, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
960
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1232);
961
961
  return addHeapObject(ret);
962
962
  },
963
963
  __wbindgen_generic_0000000000000002: function(arg0, arg1) {
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);
964
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 655, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
965
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1863);
966
966
  return addHeapObject(ret);
967
967
  },
968
968
  __wbindgen_generic_0000000000000003: function(arg0, arg1) {
@@ -1054,14 +1054,14 @@ function __wbg_get_imports() {
1054
1054
  };
1055
1055
  }
1056
1056
 
1057
- function __wasm_bindgen_func_elem_1871(arg0, arg1, arg2, arg3) {
1058
- wasm.__wasm_bindgen_func_elem_1871(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1057
+ function __wasm_bindgen_func_elem_1887(arg0, arg1, arg2, arg3) {
1058
+ wasm.__wasm_bindgen_func_elem_1887(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1059
1059
  }
1060
1060
 
1061
- function __wasm_bindgen_func_elem_1216(arg0, arg1, arg2) {
1061
+ function __wasm_bindgen_func_elem_1232(arg0, arg1, arg2) {
1062
1062
  try {
1063
1063
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1064
- wasm.__wasm_bindgen_func_elem_1216(retptr, arg0, arg1, addHeapObject(arg2));
1064
+ wasm.__wasm_bindgen_func_elem_1232(retptr, arg0, arg1, addHeapObject(arg2));
1065
1065
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1066
1066
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1067
1067
  if (r1) {
@@ -1072,10 +1072,10 @@ function __wasm_bindgen_func_elem_1216(arg0, arg1, arg2) {
1072
1072
  }
1073
1073
  }
1074
1074
 
1075
- function __wasm_bindgen_func_elem_1847(arg0, arg1, arg2) {
1075
+ function __wasm_bindgen_func_elem_1863(arg0, arg1, arg2) {
1076
1076
  try {
1077
1077
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1078
- wasm.__wasm_bindgen_func_elem_1847(retptr, arg0, arg1, addHeapObject(arg2));
1078
+ wasm.__wasm_bindgen_func_elem_1863(retptr, arg0, arg1, addHeapObject(arg2));
1079
1079
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1080
1080
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1081
1081
  if (r1) {
@@ -19,9 +19,9 @@ export const yolopipeline_postprocess: (a: number, b: number, c: number, d: numb
19
19
  export const yolopipeline_preprocess_rgba: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
20
20
  export const yolopipeline_setInputShape: (a: number, b: number, c: number) => void;
21
21
  export const yolopipeline_task: (a: number, b: number) => void;
22
- export const __wasm_bindgen_func_elem_1216: (a: number, b: number, c: number, d: number) => void;
23
- export const __wasm_bindgen_func_elem_1847: (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;
22
+ export const __wasm_bindgen_func_elem_1232: (a: number, b: number, c: number, d: number) => void;
23
+ export const __wasm_bindgen_func_elem_1863: (a: number, b: number, c: number, d: number) => void;
24
+ export const __wasm_bindgen_func_elem_1887: (a: number, b: number, c: number, d: number) => void;
25
25
  export const __wasm_bindgen_func_elem_382: (a: number, b: number, c: number, d: number) => void;
26
26
  export const __wbindgen_export: (a: number, b: number) => number;
27
27
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;