@ultralytics/yolo 0.0.59 → 0.0.60

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
@@ -32,7 +32,7 @@
32
32
 
33
33
  </div>
34
34
 
35
- Run [Ultralytics](https://www.ultralytics.com) YOLO models directly in the browser, with no server and no Python. It runs on **WebGPU** (with an automatic CPU/wasm fallback) and covers [object detection](https://docs.ultralytics.com/tasks/detect), [instance segmentation](https://docs.ultralytics.com/tasks/segment), [semantic segmentation](https://docs.ultralytics.com/tasks/semantic), [depth estimation](https://docs.ultralytics.com/tasks/depth), [image classification](https://docs.ultralytics.com/tasks/classify), [pose estimation](https://docs.ultralytics.com/tasks/pose), and [oriented bounding boxes](https://docs.ultralytics.com/tasks/obb), behind a small TypeScript API with a built-in `annotate()` that draws results straight to a canvas.
35
+ Run [Ultralytics](https://www.ultralytics.com) YOLO models directly in the browser, with no server and no Python. It runs on **WebGPU** (with an automatic CPU/wasm fallback) and covers [object detection](https://docs.ultralytics.com/tasks/detect), [instance segmentation](https://docs.ultralytics.com/tasks/segment), [semantic segmentation](https://docs.ultralytics.com/tasks/semantic), [depth estimation](https://docs.ultralytics.com/tasks/depth), [image classification](https://docs.ultralytics.com/tasks/classify), [pose estimation](https://docs.ultralytics.com/tasks/pose), and [oriented object detection](https://docs.ultralytics.com/tasks/obb), and can [track](https://docs.ultralytics.com/modes/track) detected objects across video frames, behind a small TypeScript API with a built-in `annotate()` that draws results straight to a canvas.
36
36
 
37
37
  ```ts
38
38
  import { YOLO, annotate } from "@ultralytics/yolo";
@@ -113,6 +113,46 @@ async function frame() {
113
113
  }
114
114
  ```
115
115
 
116
+ ### Tracking
117
+
118
+ `track()` follows objects across video frames like Ultralytics `model.track(persist=True)`. Each call takes one frame,
119
+ in any form `predict()` accepts, and the tracker lives in the model between calls, so every tracked box gets an `id` that
120
+ carries over from frame to frame. It works for ONNX and LiteRT detection, segmentation, pose and OBB models, on a
121
+ webcam, a video or any other frame source:
122
+
123
+ ```ts
124
+ const model = await YOLO.load("/models/yolo26n.onnx");
125
+ video.srcObject = await navigator.mediaDevices.getUserMedia({ video: true }); // or video.src = "clip.mp4"
126
+ await video.play();
127
+
128
+ async function frame() {
129
+ const image = await createImageBitmap(video); // draw the same frame that was tracked
130
+ const results = await model.track(image, { tracker: "tracktrack.yaml" });
131
+ console.log(results.boxes.map((box) => box.id));
132
+ await annotate(canvas, image, results); // labels read "id:1 person 87%"
133
+ image.close();
134
+ requestAnimationFrame(frame);
135
+ }
136
+ frame();
137
+ ```
138
+
139
+ - `tracker` is `botsort.yaml`, `bytetrack.yaml`, `ocsort.yaml`, `deepocsort.yaml`, `fasttrack.yaml` or
140
+ `tracktrack.yaml` (default), each with its Ultralytics default settings. Switching to another tracker starts new tracks.
141
+ - The other options are those of `predict()`, except that `conf` defaults to `0.1` as in Ultralytics, so low-confidence
142
+ boxes can keep a track alive. A new track needs a box above the tracker's `new_track_thresh`: `0.25`, or `0.3` for
143
+ `deepocsort.yaml` and `0.7` for `tracktrack.yaml`.
144
+ - Only boxes that belong to a track are returned, except that a frame with no track to show keeps its boxes without
145
+ `id`, as in Ultralytics. `obb` gets `id` the same way, and segmentation masks and pose
146
+ keypoints follow the kept boxes.
147
+ - `model.resetTracker()` forgets every track. Call it before a new video, and between unrelated images: a single image
148
+ works too, but on its own it only numbers the objects `1..N`.
149
+ - Semantic segmentation, depth and classification models have nothing to track and return what `predict()` returns.
150
+ - `botsort.yaml` and `tracktrack.yaml` (the default) estimate camera motion with sparse optical flow, which adds about 6
151
+ to 9 ms per frame in wasm. The other trackers add under 0.1 ms, so `bytetrack.yaml` is the lightest choice for a live
152
+ webcam.
153
+ - ReID appearance matching runs only in the native crate, and is off by default in Ultralytics too. Custom tracker YAML
154
+ files are native only as well.
155
+
116
156
  ## ✨ Models
117
157
 
118
158
  <a href="https://docs.ultralytics.com/tasks" target="_blank">
@@ -142,15 +182,15 @@ GitHub release assets send no `Access-Control-Allow-Origin`, so a browser cannot
142
182
 
143
183
  ## 📐 Results Shape
144
184
 
145
- `predict()` resolves to a `Results` object whose field names match the
146
- Rust/Ultralytics `Results` API one-to-one:
185
+ `predict()` and `track()` resolve to a `Results` object whose field names match the
186
+ Rust/Ultralytics `Results` API one-to-one, with `id` set by `track()`:
147
187
 
148
188
  | Field | Type | Tasks |
149
189
  | ------------------ | -------------------------------------------------------------------- | --------------------- |
150
190
  | `task` | `string` | all |
151
191
  | `width` / `height` | `number` | all |
152
- | `boxes` | `{ x1, y1, x2, y2, conf, cls, name, color }[]` | detect, segment, pose |
153
- | `obb` | `{ x, y, w, h, angle, conf, cls, name, color }[]` | obb |
192
+ | `boxes` | `{ x1, y1, x2, y2, id?, conf, cls, name, color }[]` | detect, segment, pose |
193
+ | `obb` | `{ x, y, w, h, angle, id?, conf, cls, name, color }[]` | obb |
154
194
  | `keypoints` | `{ points: [x, y, conf][], color }[]` | pose |
155
195
  | `probs` | `{ top1, top5, top1conf, top5conf, name, top5names, color } \| null` | classify |
156
196
  | `masks` | `Uint8Array` (RGBA overlay, `width*height*4`) | segment, semantic |
package/README.zh-CN.md CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
  </div>
34
34
 
35
- 直接在浏览器中运行 [Ultralytics](https://www.ultralytics.com) YOLO 模型,无需服务器,也无需 Python。本库基于 **WebGPU**(并自动回退到 CPU/wasm),支持[目标检测](https://docs.ultralytics.com/tasks/detect)、[实例分割](https://docs.ultralytics.com/tasks/segment)、[语义分割](https://docs.ultralytics.com/tasks/semantic)、[深度估计](https://docs.ultralytics.com/tasks/depth)、[图像分类](https://docs.ultralytics.com/tasks/classify)、[姿态估计](https://docs.ultralytics.com/tasks/pose)和[旋转边界框](https://docs.ultralytics.com/tasks/obb),接口是一个小巧的 TypeScript API,内置的 `annotate()` 可直接把结果绘制到 canvas 上。
35
+ 直接在浏览器中运行 [Ultralytics](https://www.ultralytics.com) YOLO 模型,无需服务器,也无需 Python。本库基于 **WebGPU**(并自动回退到 CPU/wasm),支持[目标检测](https://docs.ultralytics.com/tasks/detect)、[实例分割](https://docs.ultralytics.com/tasks/segment)、[语义分割](https://docs.ultralytics.com/tasks/semantic)、[深度估计](https://docs.ultralytics.com/tasks/depth)、[图像分类](https://docs.ultralytics.com/tasks/classify)、[姿态估计](https://docs.ultralytics.com/tasks/pose)和[定向目标检测](https://docs.ultralytics.com/tasks/obb),并可在视频帧间[跟踪](https://docs.ultralytics.com/modes/track)已检测到的目标,接口是一个小巧的 TypeScript API,内置的 `annotate()` 可直接把结果绘制到 canvas 上。
36
36
 
37
37
  ```ts
38
38
  import { YOLO, annotate } from "@ultralytics/yolo";
@@ -109,6 +109,40 @@ async function frame() {
109
109
  }
110
110
  ```
111
111
 
112
+ ### 目标跟踪
113
+
114
+ `track()` 像 Ultralytics 的 `model.track(persist=True)` 一样跨视频帧跟踪目标。每次调用处理一帧,输入形式与 `predict()`
115
+ 相同;跟踪器在多次调用之间保存在模型中,因此每个被跟踪的框都会获得一个跨帧延续的 `id`。它适用于 ONNX 和 LiteRT
116
+ 的检测、分割、姿态和 OBB 模型,可用于摄像头、视频或任何其他帧来源:
117
+
118
+ ```ts
119
+ const model = await YOLO.load("/models/yolo26n.onnx");
120
+ video.srcObject = await navigator.mediaDevices.getUserMedia({ video: true }); // 或 video.src = "clip.mp4"
121
+ await video.play();
122
+
123
+ async function frame() {
124
+ const image = await createImageBitmap(video); // 绘制的正是被跟踪的那一帧
125
+ const results = await model.track(image, { tracker: "tracktrack.yaml" });
126
+ console.log(results.boxes.map((box) => box.id));
127
+ await annotate(canvas, image, results); // 标签显示为 "id:1 person 87%"
128
+ image.close();
129
+ requestAnimationFrame(frame);
130
+ }
131
+ frame();
132
+ ```
133
+
134
+ - `tracker` 可选 `botsort.yaml`、`bytetrack.yaml`、`ocsort.yaml`、`deepocsort.yaml`、`fasttrack.yaml` 或
135
+ `tracktrack.yaml`(默认),均使用 Ultralytics 的默认设置。切换到其他跟踪器会开始新的轨迹。
136
+ - 其他选项与 `predict()` 相同,但 `conf` 与 Ultralytics 一样默认为 `0.1`,使低置信度的框也能维持已有轨迹。新轨迹需要框的
137
+ 置信度高于跟踪器的 `new_track_thresh`:`0.25`,`deepocsort.yaml` 为 `0.3`,`tracktrack.yaml` 为 `0.7`。
138
+ - 只返回属于某条轨迹的框;与 Ultralytics 一样,没有可显示轨迹的帧会保留其框但不带 `id`。`obb` 同样带有 `id`,分割掩码和姿态关键点跟随保留的框。
139
+ - `model.resetTracker()` 会清除所有轨迹。处理新视频前,以及在互不相关的图片之间请调用它:单张图片也可以跟踪,但单独使用时
140
+ 只会把目标编号为 `1..N`。
141
+ - 语义分割、深度和分类模型没有可跟踪的目标,返回与 `predict()` 相同的结果。
142
+ - `botsort.yaml` 和 `tracktrack.yaml`(默认)用稀疏光流估计相机运动,在 wasm 中每帧增加约 6 到 9 ms。
143
+ 其他跟踪器增加不到 0.1 ms,因此实时摄像头最轻量的选择是 `bytetrack.yaml`。
144
+ - ReID 外观匹配只在原生 crate 中运行,在 Ultralytics 中也默认关闭。自定义跟踪器 YAML 文件同样只支持原生 crate。
145
+
112
146
  ## ✨ 模型
113
147
 
114
148
  <a href="https://docs.ultralytics.com/tasks" target="_blank">
@@ -138,14 +172,14 @@ GitHub release 资源不会返回 `Access-Control-Allow-Origin`,因此浏览
138
172
 
139
173
  ## 📐 结果结构
140
174
 
141
- `predict()` 返回的 `Results` 对象,其字段名与 Rust/Ultralytics 的 `Results` API 一一对应:
175
+ `predict()` 和 `track()` 返回的 `Results` 对象,其字段名与 Rust/Ultralytics 的 `Results` API 一一对应,`id` 由 `track()` 设置:
142
176
 
143
177
  | 字段 | 类型 | 任务 |
144
178
  | ------------------ | -------------------------------------------------------------------- | --------------------- |
145
179
  | `task` | `string` | 全部 |
146
180
  | `width` / `height` | `number` | 全部 |
147
- | `boxes` | `{ x1, y1, x2, y2, conf, cls, name, color }[]` | detect、segment、pose |
148
- | `obb` | `{ x, y, w, h, angle, conf, cls, name, color }[]` | obb |
181
+ | `boxes` | `{ x1, y1, x2, y2, id?, conf, cls, name, color }[]` | detect、segment、pose |
182
+ | `obb` | `{ x, y, w, h, angle, id?, conf, cls, name, color }[]` | obb |
149
183
  | `keypoints` | `{ points: [x, y, conf][], color }[]` | pose |
150
184
  | `probs` | `{ top1, top5, top1conf, top5conf, name, top5names, color } \| null` | classify |
151
185
  | `masks` | `Uint8Array`(RGBA 叠加层,`width*height*4`) | segment、semantic |
package/dist/index.d.ts CHANGED
@@ -4,6 +4,8 @@ export interface Box {
4
4
  y1: number;
5
5
  x2: number;
6
6
  y2: number;
7
+ /** Track id, set by {@link YOLO.track}. */
8
+ id?: number;
7
9
  conf: number;
8
10
  cls: number;
9
11
  name: string;
@@ -16,6 +18,8 @@ export interface Obb {
16
18
  w: number;
17
19
  h: number;
18
20
  angle: number;
21
+ /** Track id, set by {@link YOLO.track}. */
22
+ id?: number;
19
23
  conf: number;
20
24
  cls: number;
21
25
  name: string;
@@ -131,13 +135,21 @@ export interface PredictOptions {
131
135
  */
132
136
  depthViz?: "metric" | "disparity";
133
137
  }
138
+ /** Options for {@link YOLO.track}. */
139
+ export interface TrackOptions extends PredictOptions {
140
+ /**
141
+ * Tracker: `"botsort.yaml"`, `"bytetrack.yaml"`, `"ocsort.yaml"`, `"deepocsort.yaml"`, `"fasttrack.yaml"` or
142
+ * `"tracktrack.yaml"` (default, like Ultralytics). Changing it starts new tracks.
143
+ */
144
+ tracker?: string;
145
+ }
134
146
  /** Options for {@link annotate}. */
135
147
  export interface AnnotateOptions {
136
148
  /** Box/line width in pixels. Defaults to a value scaled to the image size. */
137
149
  lineWidth?: number;
138
150
  /** Font CSS string. Defaults to a size scaled to the image. */
139
151
  font?: string;
140
- /** Draw `class_name confidence%` labels. Default `true`. */
152
+ /** Draw `id:track_id class_name confidence%` labels. Default `true`. */
141
153
  labels?: boolean;
142
154
  /** Draw pose keypoints and skeleton. Default `true`. */
143
155
  keypoints?: boolean;
@@ -207,6 +219,20 @@ export declare class YOLO {
207
219
  * @param options Confidence/IoU thresholds, class filter, and depth colorizing.
208
220
  */
209
221
  predict(image: ImageInput, options?: PredictOptions): Promise<Results>;
222
+ /**
223
+ * Run inference on the next frame of a video and track its objects, like Ultralytics
224
+ * `model.track(persist=True)`: tracks carry over between calls and every tracked box gets an
225
+ * `id` (a frame with no track to show keeps its boxes without one, as in Ultralytics). Confidence defaults to `0.1` here, as in Ultralytics. Call {@link resetTracker}
226
+ * before a new video.
227
+ *
228
+ * @param image The frame to run on, as in {@link predict}.
229
+ * @param options The {@link predict} options and the tracker.
230
+ */
231
+ track(image: ImageInput, options?: TrackOptions): Promise<Results>;
232
+ /** Forget the tracks of {@link track}, so the next frame starts a new video. */
233
+ resetTracker(): void;
234
+ /** Run one prediction in turn, tracked by `tracker` when given. */
235
+ private run;
210
236
  /** Release the underlying wasm model/engine. Call when you are done with it. */
211
237
  free(): void;
212
238
  }
package/dist/index.js CHANGED
@@ -15,6 +15,10 @@
15
15
  * for (const box of results.boxes) {
16
16
  * console.log(box.name, box.conf, box.x1, box.y1, box.x2, box.y2);
17
17
  * }
18
+ *
19
+ * // Tracks carry over between calls, like `model.track(persist=True)` in Ultralytics.
20
+ * const tracked = await model.track(videoElement, { tracker: "tracktrack.yaml" });
21
+ * console.log(tracked.boxes.map((box) => box.id));
18
22
  * ```
19
23
  */
20
24
  import init, { YoloModel, YoloPipeline, start, pose_palette, bidi_runs } from "../pkg/ultralytics_inference_web.js";
@@ -295,10 +299,13 @@ class OrtEngine {
295
299
  return this.model.names;
296
300
  }
297
301
  predictDrawable(data, width, height, p) {
298
- return this.model.predict_rgba(data, width, height, p.conf, p.iou, p.classes, p.colormap, p.depthViz);
302
+ return this.model.predict_rgba(data, width, height, p.conf, p.iou, p.classes, p.colormap, p.depthViz, p.tracker);
299
303
  }
300
304
  predictEncoded(bytes, p) {
301
- return this.model.predict(bytes, p.conf, p.iou, p.classes, p.colormap, p.depthViz);
305
+ return this.model.predict(bytes, p.conf, p.iou, p.classes, p.colormap, p.depthViz, p.tracker);
306
+ }
307
+ resetTracker() {
308
+ this.model.reset_tracker();
302
309
  }
303
310
  free() {
304
311
  this.model.free();
@@ -335,7 +342,10 @@ class LiteRtEngine {
335
342
  async predictDrawable(data, width, height, p) {
336
343
  const input = this.pipeline.preprocess_rgba(data, width, height);
337
344
  const { outputs, shapes, inferenceMs } = await this.backend.run(input, Array.from(this.pipeline.inputShape));
338
- return this.pipeline.postprocess(outputs, shapes.map((s) => new Uint32Array(s)), inferenceMs, p.conf, p.iou, p.classes, p.colormap, p.depthViz);
345
+ return this.pipeline.postprocess(outputs, shapes.map((s) => new Uint32Array(s)), inferenceMs, p.conf, p.iou, p.classes, p.colormap, p.depthViz, p.tracker);
346
+ }
347
+ resetTracker() {
348
+ this.pipeline.reset_tracker();
339
349
  }
340
350
  free() {
341
351
  this.pipeline.free();
@@ -415,6 +425,26 @@ export class YOLO {
415
425
  * @param options Confidence/IoU thresholds, class filter, and depth colorizing.
416
426
  */
417
427
  async predict(image, options) {
428
+ return this.run(image, options);
429
+ }
430
+ /**
431
+ * Run inference on the next frame of a video and track its objects, like Ultralytics
432
+ * `model.track(persist=True)`: tracks carry over between calls and every tracked box gets an
433
+ * `id` (a frame with no track to show keeps its boxes without one, as in Ultralytics). Confidence defaults to `0.1` here, as in Ultralytics. Call {@link resetTracker}
434
+ * before a new video.
435
+ *
436
+ * @param image The frame to run on, as in {@link predict}.
437
+ * @param options The {@link predict} options and the tracker.
438
+ */
439
+ async track(image, options) {
440
+ return this.run(image, options, options?.tracker ?? "tracktrack.yaml");
441
+ }
442
+ /** Forget the tracks of {@link track}, so the next frame starts a new video. */
443
+ resetTracker() {
444
+ this.queue = this.queue.then(() => this.engine.resetTracker());
445
+ }
446
+ /** Run one prediction in turn, tracked by `tracker` when given. */
447
+ async run(image, options, tracker) {
418
448
  const p = {
419
449
  // Unset thresholds fall back to the Rust `InferenceConfig` defaults.
420
450
  conf: options?.conf,
@@ -424,6 +454,7 @@ export class YOLO {
424
454
  // defaults, so the default lives in exactly one place.
425
455
  colormap: options?.colormap ?? "",
426
456
  depthViz: options?.depthViz ?? "",
457
+ tracker,
427
458
  };
428
459
  let predict;
429
460
  if (isDrawable(image)) {
@@ -536,6 +567,7 @@ export async function annotate(canvas, image, results, options) {
536
567
  x += run.width;
537
568
  }
538
569
  };
570
+ const caption = (d) => `${d.id === undefined ? "" : `id:${d.id} `}${d.name} ${(d.conf * 100).toFixed(0)}%`;
539
571
  const label = (text, x, y, color) => {
540
572
  if (!showLabels)
541
573
  return;
@@ -553,7 +585,7 @@ export async function annotate(canvas, image, results, options) {
553
585
  for (const b of results.boxes) {
554
586
  ctx.strokeStyle = b.color;
555
587
  ctx.strokeRect(b.x1, b.y1, b.x2 - b.x1, b.y2 - b.y1);
556
- label(`${b.name} ${(b.conf * 100).toFixed(0)}%`, b.x1, b.y1, b.color);
588
+ label(caption(b), b.x1, b.y1, b.color);
557
589
  }
558
590
  // Oriented boxes (obb): draw the rotated rectangle.
559
591
  for (const o of results.obb) {
@@ -576,7 +608,7 @@ export async function annotate(canvas, image, results, options) {
576
608
  ctx.lineTo(corners[i][0], corners[i][1]);
577
609
  ctx.closePath();
578
610
  ctx.stroke();
579
- label(`${o.name} ${(o.conf * 100).toFixed(0)}%`, corners[0][0], corners[0][1], color);
611
+ label(caption(o), corners[0][0], corners[0][1], color);
580
612
  }
581
613
  // Pose keypoints + skeleton, colored with the engine's pose palette (per-limb
582
614
  // and per-keypoint), matching the native/Python renderer.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultralytics/yolo",
3
- "version": "0.0.59",
3
+ "version": "0.0.60",
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.59",
5
+ "version": "0.0.60",
6
6
  "license": "AGPL-3.0",
7
7
  "repository": {
8
8
  "type": "git",
@@ -36,12 +36,15 @@ export class YoloModel {
36
36
  * `conf` and `iou` are the confidence and NMS IoU thresholds (omit them for the
37
37
  * Ultralytics defaults 0.25 / 0.5); `classes` optionally keeps only
38
38
  * the given class ids (for semantic, other pixels become background).
39
+ * `tracker` (`"tracktrack.yaml"`, `"botsort.yaml"`, ...) tracks the detections across
40
+ * calls like Ultralytics `model.track(persist=True)`, starting anew when it changes.
39
41
  * Returns a plain JS object whose shape mirrors the Ultralytics `Results` API.
40
42
  *
41
43
  * # Errors
42
- * Returns a JS error if the image cannot be decoded or inference fails.
44
+ * Returns a JS error if the image cannot be decoded, the tracker is unknown or
45
+ * inference fails.
43
46
  */
44
- predict(image: Uint8Array, conf: number | null | undefined, iou: number | null | undefined, classes: Uint32Array | null | undefined, colormap: string, depth_viz: string): Promise<any>;
47
+ predict(image: Uint8Array, conf: number | null | undefined, iou: number | null | undefined, classes: Uint32Array | null | undefined, colormap: string, depth_viz: string, tracker?: string | null): Promise<any>;
45
48
  /**
46
49
  * Run inference on raw `RGBA` pixels (e.g. a canvas/webcam `ImageData`).
47
50
  *
@@ -51,7 +54,11 @@ export class YoloModel {
51
54
  * # Errors
52
55
  * Returns a JS error if the buffer size is wrong or inference fails.
53
56
  */
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>;
57
+ 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, tracker?: string | null): Promise<any>;
58
+ /**
59
+ * Forget the tracks, so the next frame starts a new video.
60
+ */
61
+ reset_tracker(): void;
55
62
  /**
56
63
  * The active device: `"webgpu"` or `"cpu"` (the fallback when WebGPU is
57
64
  * unavailable). Mirrors the native `Device` display.
@@ -103,14 +110,15 @@ export class YoloPipeline {
103
110
  * segmentation: detection head + mask prototypes), with one entry of dims per
104
111
  * output in `shapes`. `inference_ms`
105
112
  * is the time the JS engine reported, used only for the `speed` breakdown.
113
+ * `tracker` tracks the detections as in [`YoloModel::predict`].
106
114
  * Consumes the frame stashed by the preceding
107
115
  * [`preprocess_rgba`](Self::preprocess_rgba).
108
116
  *
109
117
  * # Errors
110
118
  * Returns a JS error if called before `preprocess_rgba`, if `shapes` does not
111
- * have one entry per output, or on serialization failure.
119
+ * have one entry per output, if the tracker is unknown, or on serialization failure.
112
120
  */
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;
121
+ 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, tracker?: string | null): any;
114
122
  /**
115
123
  * Preprocess raw RGBA pixels (e.g. a webcam `ImageData`) into the NCHW f32
116
124
  * input tensor an Ultralytics LiteRT/TFLite model expects, normalized to
@@ -124,6 +132,10 @@ export class YoloPipeline {
124
132
  * Returns a JS error if the buffer size is not `width * height * 4`.
125
133
  */
126
134
  preprocess_rgba(rgba: Uint8Array, width: number, height: number): Float32Array;
135
+ /**
136
+ * Forget the tracks, so the next frame starts a new video.
137
+ */
138
+ reset_tracker(): void;
127
139
  /**
128
140
  * Adopt the input shape the engine reports for the compiled model.
129
141
  *
@@ -193,20 +205,22 @@ export interface InitOutput {
193
205
  readonly yolomodel_device: (a: number, b: number) => void;
194
206
  readonly yolomodel_load_bytes: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
195
207
  readonly yolomodel_names: (a: number, b: number) => void;
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;
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;
208
+ 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, l: number, m: number) => number;
209
+ 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, n: number, o: number) => number;
210
+ readonly yolomodel_reset_tracker: (a: number) => void;
198
211
  readonly yolomodel_task: (a: number, b: number) => void;
199
212
  readonly yolopipeline_inputShape: (a: number, b: number) => void;
200
213
  readonly yolopipeline_names: (a: number, b: number) => void;
201
214
  readonly yolopipeline_new: (a: number, b: number, c: number) => void;
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;
215
+ 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, p: number, q: number) => void;
203
216
  readonly yolopipeline_preprocess_rgba: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
217
+ readonly yolopipeline_reset_tracker: (a: number) => void;
204
218
  readonly yolopipeline_setInputShape: (a: number, b: number, c: number) => void;
205
219
  readonly yolopipeline_task: (a: number, b: number) => void;
206
- readonly __wasm_bindgen_func_elem_1236: (a: number, b: number, c: number, d: number) => void;
207
- readonly __wasm_bindgen_func_elem_1867: (a: number, b: number, c: number, d: number) => void;
208
- readonly __wasm_bindgen_func_elem_1891: (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;
220
+ readonly __wasm_bindgen_func_elem_1320: (a: number, b: number, c: number, d: number) => void;
221
+ readonly __wasm_bindgen_func_elem_1951: (a: number, b: number, c: number, d: number) => void;
222
+ readonly __wasm_bindgen_func_elem_1975: (a: number, b: number, c: number, d: number) => void;
223
+ readonly __wasm_bindgen_func_elem_390: (a: number, b: number, c: number, d: number) => void;
210
224
  readonly __wbindgen_export: (a: number, b: number) => number;
211
225
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
212
226
  readonly __wbindgen_export3: (a: number) => void;
@@ -107,19 +107,23 @@ export class YoloModel {
107
107
  * `conf` and `iou` are the confidence and NMS IoU thresholds (omit them for the
108
108
  * Ultralytics defaults 0.25 / 0.5); `classes` optionally keeps only
109
109
  * the given class ids (for semantic, other pixels become background).
110
+ * `tracker` (`"tracktrack.yaml"`, `"botsort.yaml"`, ...) tracks the detections across
111
+ * calls like Ultralytics `model.track(persist=True)`, starting anew when it changes.
110
112
  * Returns a plain JS object whose shape mirrors the Ultralytics `Results` API.
111
113
  *
112
114
  * # Errors
113
- * Returns a JS error if the image cannot be decoded or inference fails.
115
+ * Returns a JS error if the image cannot be decoded, the tracker is unknown or
116
+ * inference fails.
114
117
  * @param {Uint8Array} image
115
118
  * @param {number | null | undefined} conf
116
119
  * @param {number | null | undefined} iou
117
120
  * @param {Uint32Array | null | undefined} classes
118
121
  * @param {string} colormap
119
122
  * @param {string} depth_viz
123
+ * @param {string | null} [tracker]
120
124
  * @returns {Promise<any>}
121
125
  */
122
- predict(image, conf, iou, classes, colormap, depth_viz) {
126
+ predict(image, conf, iou, classes, colormap, depth_viz, tracker) {
123
127
  const ptr0 = passArray8ToWasm0(image, wasm.__wbindgen_export);
124
128
  const len0 = WASM_VECTOR_LEN;
125
129
  var ptr1 = isLikeNone(classes) ? 0 : passArray32ToWasm0(classes, wasm.__wbindgen_export);
@@ -128,7 +132,9 @@ export class YoloModel {
128
132
  const len2 = WASM_VECTOR_LEN;
129
133
  const ptr3 = passStringToWasm0(depth_viz, wasm.__wbindgen_export, wasm.__wbindgen_export2);
130
134
  const len3 = WASM_VECTOR_LEN;
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);
135
+ var ptr4 = isLikeNone(tracker) ? 0 : passStringToWasm0(tracker, wasm.__wbindgen_export, wasm.__wbindgen_export2);
136
+ var len4 = WASM_VECTOR_LEN;
137
+ 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, ptr4, len4);
132
138
  return takeObject(ret);
133
139
  }
134
140
  /**
@@ -147,9 +153,10 @@ export class YoloModel {
147
153
  * @param {Uint32Array | null | undefined} classes
148
154
  * @param {string} colormap
149
155
  * @param {string} depth_viz
156
+ * @param {string | null} [tracker]
150
157
  * @returns {Promise<any>}
151
158
  */
152
- predict_rgba(rgba, width, height, conf, iou, classes, colormap, depth_viz) {
159
+ predict_rgba(rgba, width, height, conf, iou, classes, colormap, depth_viz, tracker) {
153
160
  const ptr0 = passArray8ToWasm0(rgba, wasm.__wbindgen_export);
154
161
  const len0 = WASM_VECTOR_LEN;
155
162
  var ptr1 = isLikeNone(classes) ? 0 : passArray32ToWasm0(classes, wasm.__wbindgen_export);
@@ -158,9 +165,17 @@ export class YoloModel {
158
165
  const len2 = WASM_VECTOR_LEN;
159
166
  const ptr3 = passStringToWasm0(depth_viz, wasm.__wbindgen_export, wasm.__wbindgen_export2);
160
167
  const len3 = WASM_VECTOR_LEN;
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);
168
+ var ptr4 = isLikeNone(tracker) ? 0 : passStringToWasm0(tracker, wasm.__wbindgen_export, wasm.__wbindgen_export2);
169
+ var len4 = WASM_VECTOR_LEN;
170
+ 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, ptr4, len4);
162
171
  return takeObject(ret);
163
172
  }
173
+ /**
174
+ * Forget the tracks, so the next frame starts a new video.
175
+ */
176
+ reset_tracker() {
177
+ wasm.yolomodel_reset_tracker(this.__wbg_ptr);
178
+ }
164
179
  /**
165
180
  * The model's task (`"detect"`, `"segment"`, `"semantic"`, `"depth"`,
166
181
  * `"classify"`, `"pose"`, or `"obb"`).
@@ -285,12 +300,13 @@ export class YoloPipeline {
285
300
  * segmentation: detection head + mask prototypes), with one entry of dims per
286
301
  * output in `shapes`. `inference_ms`
287
302
  * is the time the JS engine reported, used only for the `speed` breakdown.
303
+ * `tracker` tracks the detections as in [`YoloModel::predict`].
288
304
  * Consumes the frame stashed by the preceding
289
305
  * [`preprocess_rgba`](Self::preprocess_rgba).
290
306
  *
291
307
  * # Errors
292
308
  * Returns a JS error if called before `preprocess_rgba`, if `shapes` does not
293
- * have one entry per output, or on serialization failure.
309
+ * have one entry per output, if the tracker is unknown, or on serialization failure.
294
310
  * @param {Float32Array[]} outputs
295
311
  * @param {Uint32Array[]} shapes
296
312
  * @param {number} inference_ms
@@ -299,9 +315,10 @@ export class YoloPipeline {
299
315
  * @param {Uint32Array | null | undefined} classes
300
316
  * @param {string} colormap
301
317
  * @param {string} depth_viz
318
+ * @param {string | null} [tracker]
302
319
  * @returns {any}
303
320
  */
304
- postprocess(outputs, shapes, inference_ms, conf, iou, classes, colormap, depth_viz) {
321
+ postprocess(outputs, shapes, inference_ms, conf, iou, classes, colormap, depth_viz, tracker) {
305
322
  try {
306
323
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
307
324
  const ptr0 = passArrayJsValueToWasm0(outputs, wasm.__wbindgen_export);
@@ -314,7 +331,9 @@ export class YoloPipeline {
314
331
  const len3 = WASM_VECTOR_LEN;
315
332
  const ptr4 = passStringToWasm0(depth_viz, wasm.__wbindgen_export, wasm.__wbindgen_export2);
316
333
  const len4 = WASM_VECTOR_LEN;
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);
334
+ var ptr5 = isLikeNone(tracker) ? 0 : passStringToWasm0(tracker, wasm.__wbindgen_export, wasm.__wbindgen_export2);
335
+ var len5 = WASM_VECTOR_LEN;
336
+ 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, ptr5, len5);
318
337
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
319
338
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
320
339
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -359,6 +378,12 @@ export class YoloPipeline {
359
378
  wasm.__wbindgen_add_to_stack_pointer(16);
360
379
  }
361
380
  }
381
+ /**
382
+ * Forget the tracks, so the next frame starts a new video.
383
+ */
384
+ reset_tracker() {
385
+ wasm.yolopipeline_reset_tracker(this.__wbg_ptr);
386
+ }
362
387
  /**
363
388
  * Adopt the input shape the engine reports for the compiled model.
364
389
  *
@@ -764,7 +789,7 @@ function __wbg_get_imports() {
764
789
  const a = state0.a;
765
790
  state0.a = 0;
766
791
  try {
767
- return __wasm_bindgen_func_elem_1891(a, state0.b, arg0, arg1);
792
+ return __wasm_bindgen_func_elem_1975(a, state0.b, arg0, arg1);
768
793
  } finally {
769
794
  state0.a = a;
770
795
  }
@@ -956,18 +981,18 @@ function __wbg_get_imports() {
956
981
  return addHeapObject(ret);
957
982
  },
958
983
  __wbindgen_generic_0000000000000001: function(arg0, arg1) {
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_1236);
984
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 377, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
985
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1320);
961
986
  return addHeapObject(ret);
962
987
  },
963
988
  __wbindgen_generic_0000000000000002: function(arg0, arg1) {
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_1867);
989
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 661, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
990
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1951);
966
991
  return addHeapObject(ret);
967
992
  },
968
993
  __wbindgen_generic_0000000000000003: function(arg0, arg1) {
969
994
  // 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`.
970
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_382);
995
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_390);
971
996
  return addHeapObject(ret);
972
997
  },
973
998
  __wbindgen_generic_0000000000000004: function(arg0) {
@@ -1054,14 +1079,14 @@ function __wbg_get_imports() {
1054
1079
  };
1055
1080
  }
1056
1081
 
1057
- function __wasm_bindgen_func_elem_1891(arg0, arg1, arg2, arg3) {
1058
- wasm.__wasm_bindgen_func_elem_1891(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1082
+ function __wasm_bindgen_func_elem_1975(arg0, arg1, arg2, arg3) {
1083
+ wasm.__wasm_bindgen_func_elem_1975(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1059
1084
  }
1060
1085
 
1061
- function __wasm_bindgen_func_elem_1236(arg0, arg1, arg2) {
1086
+ function __wasm_bindgen_func_elem_1320(arg0, arg1, arg2) {
1062
1087
  try {
1063
1088
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1064
- wasm.__wasm_bindgen_func_elem_1236(retptr, arg0, arg1, addHeapObject(arg2));
1089
+ wasm.__wasm_bindgen_func_elem_1320(retptr, arg0, arg1, addHeapObject(arg2));
1065
1090
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1066
1091
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1067
1092
  if (r1) {
@@ -1072,10 +1097,10 @@ function __wasm_bindgen_func_elem_1236(arg0, arg1, arg2) {
1072
1097
  }
1073
1098
  }
1074
1099
 
1075
- function __wasm_bindgen_func_elem_1867(arg0, arg1, arg2) {
1100
+ function __wasm_bindgen_func_elem_1951(arg0, arg1, arg2) {
1076
1101
  try {
1077
1102
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1078
- wasm.__wasm_bindgen_func_elem_1867(retptr, arg0, arg1, addHeapObject(arg2));
1103
+ wasm.__wasm_bindgen_func_elem_1951(retptr, arg0, arg1, addHeapObject(arg2));
1079
1104
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1080
1105
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1081
1106
  if (r1) {
@@ -1086,10 +1111,10 @@ function __wasm_bindgen_func_elem_1867(arg0, arg1, arg2) {
1086
1111
  }
1087
1112
  }
1088
1113
 
1089
- function __wasm_bindgen_func_elem_382(arg0, arg1, arg2) {
1114
+ function __wasm_bindgen_func_elem_390(arg0, arg1, arg2) {
1090
1115
  try {
1091
1116
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1092
- wasm.__wasm_bindgen_func_elem_382(retptr, arg0, arg1, addHeapObject(arg2));
1117
+ wasm.__wasm_bindgen_func_elem_390(retptr, arg0, arg1, addHeapObject(arg2));
1093
1118
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1094
1119
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1095
1120
  if (r1) {
@@ -9,20 +9,22 @@ export const start: () => void;
9
9
  export const yolomodel_device: (a: number, b: number) => void;
10
10
  export const yolomodel_load_bytes: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
11
11
  export const yolomodel_names: (a: number, b: number) => void;
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;
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;
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, l: number, m: number) => number;
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, n: number, o: number) => number;
14
+ export const yolomodel_reset_tracker: (a: number) => void;
14
15
  export const yolomodel_task: (a: number, b: number) => void;
15
16
  export const yolopipeline_inputShape: (a: number, b: number) => void;
16
17
  export const yolopipeline_names: (a: number, b: number) => void;
17
18
  export const yolopipeline_new: (a: number, b: number, c: number) => void;
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
+ 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, p: number, q: number) => void;
19
20
  export const yolopipeline_preprocess_rgba: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
21
+ export const yolopipeline_reset_tracker: (a: number) => void;
20
22
  export const yolopipeline_setInputShape: (a: number, b: number, c: number) => void;
21
23
  export const yolopipeline_task: (a: number, b: number) => void;
22
- export const __wasm_bindgen_func_elem_1236: (a: number, b: number, c: number, d: number) => void;
23
- export const __wasm_bindgen_func_elem_1867: (a: number, b: number, c: number, d: number) => void;
24
- export const __wasm_bindgen_func_elem_1891: (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;
24
+ export const __wasm_bindgen_func_elem_1320: (a: number, b: number, c: number, d: number) => void;
25
+ export const __wasm_bindgen_func_elem_1951: (a: number, b: number, c: number, d: number) => void;
26
+ export const __wasm_bindgen_func_elem_1975: (a: number, b: number, c: number, d: number) => void;
27
+ export const __wasm_bindgen_func_elem_390: (a: number, b: number, c: number, d: number) => void;
26
28
  export const __wbindgen_export: (a: number, b: number) => number;
27
29
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
28
30
  export const __wbindgen_export3: (a: number) => void;