@ultralytics/yolo 0.0.20 → 0.0.22

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
@@ -1,19 +1,23 @@
1
1
  <!-- Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license -->
2
2
 
3
- # Ultralytics Inference (Browser / WebGPU)
3
+ <a href="https://www.ultralytics.com/"><img src="https://raw.githubusercontent.com/ultralytics/assets/main/logo/Ultralytics_Logotype_Original.svg" width="320" alt="Ultralytics logo"></a>
4
+
5
+ # Ultralytics YOLO npm Inference
4
6
 
5
7
  [![npm version](https://img.shields.io/npm/v/@ultralytics/yolo?logo=npm&logoColor=white&label=npm&color=CB3837)](https://www.npmjs.com/package/@ultralytics/yolo)
6
8
  [![npm downloads](https://img.shields.io/npm/dm/@ultralytics/yolo?logo=npm&logoColor=white&label=downloads&color=CB3837)](https://www.npmjs.com/package/@ultralytics/yolo)
9
+ [![CI](https://github.com/ultralytics/inference/actions/workflows/ci.yml/badge.svg)](https://github.com/ultralytics/inference/actions/workflows/ci.yml)
7
10
  [![License](https://img.shields.io/badge/license-AGPL--3.0-blue.svg)](https://github.com/ultralytics/inference/blob/main/LICENSE)
8
11
 
9
12
  [![Ultralytics Discord](https://img.shields.io/discord/1089800235347353640?logo=discord&logoColor=white&label=Discord&color=blue)](https://discord.com/invite/ultralytics)
10
13
  [![Ultralytics Forums](https://img.shields.io/discourse/users?server=https%3A%2F%2Fcommunity.ultralytics.com&logo=discourse&label=Forums&color=blue)](https://community.ultralytics.com/)
11
14
  [![Ultralytics Reddit](https://img.shields.io/reddit/subreddit-subscribers/ultralytics?style=flat&logo=reddit&logoColor=white&label=Reddit&color=blue)](https://reddit.com/r/ultralytics)
12
15
 
13
- Run [Ultralytics](https://ultralytics.com) YOLO models directly in the browser on
14
- **WebGPU**, with no server and no Python. It covers detection, segmentation,
15
- pose, classification, OBB, and semantic segmentation, with a compact
16
- TypeScript API and a built-in `annotate()` for drawing.
16
+ Run [Ultralytics](https://www.ultralytics.com/) YOLO models directly in the browser,
17
+ with no server and no Python. It runs on **WebGPU** (with an automatic CPU/wasm
18
+ fallback) and covers detection, segmentation, pose, classification, OBB, and
19
+ semantic segmentation, behind a small TypeScript API with a built-in
20
+ `annotate()` that draws results straight to a canvas.
17
21
 
18
22
  ```ts
19
23
  import { YOLO, annotate } from "@ultralytics/yolo";
@@ -30,13 +34,21 @@ via [`ort-web`](https://ort.pyke.io/backends/web), and all pre/postprocessing,
30
34
  colors, and the pose skeleton come from that shared Rust code, so results and
31
35
  visuals match the native and Python paths.
32
36
 
33
- ## Install
37
+ ## 📦 Install
34
38
 
35
39
  ```bash
36
40
  npm install @ultralytics/yolo
41
+ # or
42
+ pnpm add @ultralytics/yolo
43
+ yarn add @ultralytics/yolo
44
+ bun add @ultralytics/yolo
37
45
  ```
38
46
 
39
- ## Quick start
47
+ It ships as an ES module with TypeScript types and works in any modern bundler
48
+ (Vite, webpack, esbuild, Bun) or directly via a CDN such as
49
+ [esm.sh](https://esm.sh/@ultralytics/yolo).
50
+
51
+ ## 🚀 Quick Start
40
52
 
41
53
  ```ts
42
54
  import { YOLO, annotate } from "@ultralytics/yolo";
@@ -62,7 +74,7 @@ const results = await model.predict(canvas, { conf: 0.25, iou: 0.7 });
62
74
  console.log(model.device); // "webgpu" or "cpu"
63
75
  ```
64
76
 
65
- ### Webcam / video
77
+ ### Webcam / Video
66
78
 
67
79
  Drawable sources (`<video>`, canvas, `ImageBitmap`, `ImageData`) take a
68
80
  raw-pixel fast path with no re-encoding, so a render loop is smooth:
@@ -76,18 +88,30 @@ async function frame() {
76
88
  }
77
89
  ```
78
90
 
79
- ## Models
91
+ ## ✨ Models
92
+
93
+ <a href="https://docs.ultralytics.com/tasks" target="_blank">
94
+ <img width="100%" src="https://raw.githubusercontent.com/ultralytics/assets/main/docs/ultralytics-yolov8-tasks-banner.avif" alt="Ultralytics YOLO supported tasks">
95
+ </a>
96
+ <br>
97
+ <br>
98
+
99
+ Runs [YOLOv8](https://docs.ultralytics.com/models/yolov8),
100
+ [YOLO11](https://docs.ultralytics.com/models/yolo11), and
101
+ [YOLO26](https://docs.ultralytics.com/models/yolo26) ONNX exports for detection,
102
+ segmentation, pose, OBB, classification, and semantic segmentation.
80
103
 
81
- A bare ONNX name resolves to the
82
- [Ultralytics assets release](https://github.com/ultralytics/assets/releases):
104
+ Pass a bare ONNX name and it is **auto-downloaded** from the
105
+ [Ultralytics assets release](https://github.com/ultralytics/assets/releases) (the
106
+ same weights the native crate and Python use):
83
107
 
84
108
  ```ts
85
- await YOLO.load("yolo26n.onnx"); // resolves to the release: .../download/v8.4.0/yolo26n.onnx
109
+ await YOLO.load("yolo26n.onnx"); // auto-downloads from the release: .../download/v8.4.0/yolo26n.onnx
86
110
  ```
87
111
 
88
- Supports **yolo26**, **yolo11**, and **yolov8** in sizes `n/s/m/l/x` with task
89
- suffixes `-seg`, `-pose`, `-cls`, `-obb`, and `-sem` (semantic, yolo26 only). A
90
- value containing a `/` or a scheme is used as a URL/path as-is.
112
+ Auto-download covers **yolo26**, **yolo11**, and **yolov8** in sizes `n/s/m/l/x`
113
+ with task suffixes `-seg`, `-pose`, `-cls`, `-obb`, and `-sem` (semantic, yolo26
114
+ only). A value containing a `/` or a scheme is used as a URL/path as-is.
91
115
 
92
116
  > **CORS note:** GitHub release assets do not send `Access-Control-Allow-Origin`,
93
117
  > so a browser cannot fetch them cross-origin. Host the `.onnx` **same-origin**
@@ -95,7 +119,7 @@ value containing a `/` or a scheme is used as a URL/path as-is.
95
119
  > proxy. The bare-name shortcut is convenient when you mirror the assets on such
96
120
  > a host.
97
121
 
98
- ## Results shape
122
+ ## 📐 Results Shape
99
123
 
100
124
  `predict()` resolves to a `Results` object shaped like the Ultralytics
101
125
  `Results`:
@@ -119,15 +143,15 @@ detection carries its Ultralytics palette `color`, and `annotate()` draws the
119
143
  `masks` overlay and the pose skeleton with the same per-limb/keypoint colors as
120
144
  the native renderer. None of this is duplicated in JS.
121
145
 
122
- ## Requirements & notes
146
+ ## ⚙️ Requirements & Notes
123
147
 
124
148
  - **WebGPU** (Chrome/Edge, or Firefox with WebGPU enabled) from a **secure
125
149
  context** (`https://` or `http://localhost`) gives the fast path. Without
126
150
  WebGPU (older browsers, some phones), `YOLO.load` automatically falls back to a
127
151
  portable **CPU/wasm** build that runs everywhere. Pick the device with
128
- `YOLO.load(model, { device: "webgpu" | "cpu" })` (default `"auto"`). If WebGPU
129
- cannot engage, the load falls back to CPU; `model.device` reports what actually
130
- ran.
152
+ `YOLO.load("yolo26n.onnx", { device: "webgpu" | "cpu" })` (default `"auto"`). If
153
+ WebGPU cannot engage, the load falls back to CPU; `model.device` reports what
154
+ actually ran.
131
155
  - **Model format**: export your model to ONNX with Ultralytics so the metadata
132
156
  (task, class names, `imgsz`) is embedded:
133
157
 
@@ -151,10 +175,10 @@ the native renderer. None of this is duplicated in JS.
151
175
  creation. See the [ort-web docs](https://ort.pyke.io/backends/web) to review or
152
176
  disable it.
153
177
 
154
- ## Building from source
178
+ ## 🔨 Building From Source
155
179
 
156
180
  This package builds the wasm from the Rust crate with
157
- [`wasm-pack`](https://github.com/rustwasm/wasm-pack):
181
+ [`wasm-pack`](https://github.com/wasm-bindgen/wasm-pack):
158
182
 
159
183
  ```bash
160
184
  npm run build # wasm-pack build + tsc
@@ -163,6 +187,46 @@ npm run build # wasm-pack build + tsc
163
187
  Serve the built `dist/` + `pkg/` over `localhost` (a secure context) and open it
164
188
  in a WebGPU browser.
165
189
 
166
- ## License
190
+ ## 💡 Contributing
191
+
192
+ Ultralytics thrives on community collaboration, and we deeply value your contributions! Whether it's reporting bugs,
193
+ suggesting features, or submitting code changes, your involvement is crucial.
194
+
195
+ - **Report Issues**: Found a bug? [Open an issue](https://github.com/ultralytics/inference/issues)
196
+ - **Feature Requests**: Have an idea? [Share it](https://github.com/ultralytics/inference/issues)
197
+ - **Pull Requests**: Read our [Contributing Guide](https://docs.ultralytics.com/help/contributing) first
198
+ - **Feedback**: Take our [Survey](https://www.ultralytics.com/survey?utm_source=github&utm_medium=social&utm_campaign=Survey)
199
+
200
+ A heartfelt thank you 🙏 goes out to all our contributors! Your efforts help make Ultralytics tools better for everyone.
201
+
202
+ [![Ultralytics open-source contributors](https://raw.githubusercontent.com/ultralytics/assets/main/im/image-contributors.png)](https://github.com/ultralytics/ultralytics/graphs/contributors)
203
+
204
+ ## 📜 License
205
+
206
+ Ultralytics offers two licensing options to suit different needs:
207
+
208
+ - **AGPL-3.0 License**: This [OSI-approved](https://opensource.org/license/agpl-3.0) open-source license is perfect for students, researchers, and enthusiasts. It encourages open collaboration and knowledge sharing. See the [LICENSE](https://github.com/ultralytics/inference/blob/main/LICENSE) file for full details.
209
+ - **Ultralytics Enterprise License**: Designed for commercial use, this license allows for the seamless integration of Ultralytics software and AI models into commercial products and services, bypassing the open-source requirements of AGPL-3.0. If your use case involves commercial deployment, please contact us via [Ultralytics Licensing](https://www.ultralytics.com/license).
210
+
211
+ ## 📮 Contact
212
+
213
+ - **GitHub Issues**: [Bug reports and feature requests](https://github.com/ultralytics/inference/issues)
214
+ - **Discord**: [Join our community](https://discord.com/invite/ultralytics)
215
+ - **Documentation**: [docs.ultralytics.com](https://docs.ultralytics.com)
167
216
 
168
- AGPL-3.0. See the repository [LICENSE](https://github.com/ultralytics/inference/blob/main/LICENSE).
217
+ <br>
218
+ <div align="center">
219
+ <a href="https://github.com/ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-github.png" width="3%" alt="Ultralytics GitHub"></a>
220
+ <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
221
+ <a href="https://www.linkedin.com/company/ultralytics/"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-linkedin.png" width="3%" alt="Ultralytics LinkedIn"></a>
222
+ <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
223
+ <a href="https://twitter.com/ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-twitter.png" width="3%" alt="Ultralytics Twitter"></a>
224
+ <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
225
+ <a href="https://www.youtube.com/ultralytics?sub_confirmation=1"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-youtube.png" width="3%" alt="Ultralytics YouTube"></a>
226
+ <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
227
+ <a href="https://www.tiktok.com/@ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-tiktok.png" width="3%" alt="Ultralytics TikTok"></a>
228
+ <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
229
+ <a href="https://ultralytics.com/bilibili"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-bilibili.png" width="3%" alt="Ultralytics BiliBili"></a>
230
+ <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
231
+ <a href="https://discord.com/invite/ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-discord.png" width="3%" alt="Ultralytics Discord"></a>
232
+ </div>
package/dist/index.js CHANGED
@@ -43,6 +43,10 @@ async function resolveDevice(pref) {
43
43
  }
44
44
  /** Ultralytics model assets release (ONNX exports of yolo26 / yolo11 / yolov8). */
45
45
  const ASSETS = "https://github.com/ultralytics/assets/releases/download/v8.4.0/";
46
+ /** Ultralytics default thresholds (mirrored in the option JSDoc above). */
47
+ const DEFAULT_CONF = 0.25;
48
+ const DEFAULT_IOU = 0.7;
49
+ const DEFAULT_KEYPOINT_THRESHOLD = 0.25;
46
50
  /**
47
51
  * Resolve a model reference to a URL. A bare ONNX name (e.g. `"yolo26n.onnx"`,
48
52
  * `"yolo11s-seg.onnx"`, `"yolov8n.onnx"`) auto-downloads from the Ultralytics
@@ -77,6 +81,13 @@ function isDrawable(input) {
77
81
  input instanceof HTMLVideoElement ||
78
82
  input instanceof ImageBitmap);
79
83
  }
84
+ /** Fetch a URL and throw a clear error naming `what` if the response is not OK. */
85
+ async function fetchOk(url, what) {
86
+ const resp = await fetch(url);
87
+ if (!resp.ok)
88
+ throw new Error(`failed to fetch ${what}: ${url} (${resp.status})`);
89
+ return resp;
90
+ }
80
91
  /** Fetch/normalize an encoded image input to bytes the wasm side can decode. */
81
92
  async function toEncodedBytes(input) {
82
93
  if (input instanceof Uint8Array)
@@ -85,9 +96,7 @@ async function toEncodedBytes(input) {
85
96
  return new Uint8Array(input);
86
97
  if (input instanceof Blob)
87
98
  return new Uint8Array(await input.arrayBuffer());
88
- const resp = await fetch(input);
89
- if (!resp.ok)
90
- throw new Error(`failed to fetch image: ${input} (${resp.status})`);
99
+ const resp = await fetchOk(input, "image");
91
100
  return new Uint8Array(await resp.arrayBuffer());
92
101
  }
93
102
  /** Read a drawable source as raw RGBA pixels (the fast path, no re-encoding). */
@@ -146,9 +155,7 @@ export class YOLO {
146
155
  let bytes;
147
156
  if (typeof source === "string" || source instanceof URL) {
148
157
  const url = resolveModel(source.toString());
149
- const resp = await fetch(url);
150
- if (!resp.ok)
151
- throw new Error(`failed to fetch model: ${url} (${resp.status})`);
158
+ const resp = await fetchOk(url, "model");
152
159
  bytes = new Uint8Array(await resp.arrayBuffer());
153
160
  }
154
161
  else {
@@ -182,8 +189,8 @@ export class YOLO {
182
189
  * @param options Confidence/IoU thresholds.
183
190
  */
184
191
  async predict(image, options) {
185
- const conf = options?.conf ?? 0.25;
186
- const iou = options?.iou ?? 0.7;
192
+ const conf = options?.conf ?? DEFAULT_CONF;
193
+ const iou = options?.iou ?? DEFAULT_IOU;
187
194
  const classes = options?.classes ? new Uint32Array(options.classes) : undefined;
188
195
  if (isDrawable(image)) {
189
196
  const { data, width, height } = toImageData(image);
@@ -244,7 +251,7 @@ export async function annotate(canvas, image, results, options) {
244
251
  const font = options?.font ?? `${fontSize}px sans-serif`;
245
252
  const showLabels = options?.labels ?? true;
246
253
  const showKpts = options?.keypoints ?? true;
247
- const kptThresh = options?.keypointThreshold ?? 0.25;
254
+ const kptThresh = options?.keypointThreshold ?? DEFAULT_KEYPOINT_THRESHOLD;
248
255
  ctx.lineWidth = lineWidth;
249
256
  ctx.font = font;
250
257
  ctx.textBaseline = "top";
@@ -325,9 +332,7 @@ export async function annotate(canvas, image, results, options) {
325
332
  /** Resolve any {@link ImageInput} to something `drawImage` accepts. */
326
333
  async function resolveBitmap(input) {
327
334
  if (typeof input === "string" || input instanceof URL) {
328
- const resp = await fetch(input);
329
- if (!resp.ok)
330
- throw new Error(`failed to fetch image: ${input} (${resp.status})`);
335
+ const resp = await fetchOk(input, "image");
331
336
  return createImageBitmap(await resp.blob());
332
337
  }
333
338
  if (input instanceof Blob)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ultralytics/yolo",
3
- "version": "0.0.20",
4
- "description": "Run Ultralytics YOLO models in the browser on WebGPU (WebAssembly, ONNX Runtime Web via ort-web). Python-like API.",
3
+ "version": "0.0.22",
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",
7
7
  "module": "./dist/index.js",
@@ -43,9 +43,18 @@
43
43
  "computer-vision"
44
44
  ],
45
45
  "license": "AGPL-3.0",
46
+ "author": "Ultralytics",
47
+ "contributors": [
48
+ "Glenn Jocher <glenn.jocher@ultralytics.com>",
49
+ "Onuralp Sezer <onuralp@ultralytics.com>"
50
+ ],
46
51
  "repository": {
47
52
  "type": "git",
48
- "url": "https://github.com/ultralytics/inference"
53
+ "url": "git+https://github.com/ultralytics/inference.git",
54
+ "directory": "web"
55
+ },
56
+ "bugs": {
57
+ "url": "https://github.com/ultralytics/inference/issues"
49
58
  },
50
59
  "homepage": "https://www.ultralytics.com",
51
60
  "devDependencies": {
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.20",
5
+ "version": "0.0.22",
6
6
  "license": "AGPL-3.0",
7
7
  "repository": {
8
8
  "type": "git",
@@ -16,8 +16,7 @@ export class YoloModel {
16
16
  *
17
17
  * Initializes the accelerated backend on first use, reads the embedded
18
18
  * Ultralytics metadata from the model bytes, then commits an ONNX Runtime
19
- * session on the requested execution provider. Equivalent to Python's
20
- * `YOLO('model.onnx')`.
19
+ * session on the requested execution provider.
21
20
  *
22
21
  * `device` is `"webgpu"` or `"cpu"` (the browser picks the GPU adapter
23
22
  * automatically). WebGPU is registered with `error_on_failure`, so if the
@@ -52,8 +52,7 @@ export class YoloModel {
52
52
  *
53
53
  * Initializes the accelerated backend on first use, reads the embedded
54
54
  * Ultralytics metadata from the model bytes, then commits an ONNX Runtime
55
- * session on the requested execution provider. Equivalent to Python's
56
- * `YOLO('model.onnx')`.
55
+ * session on the requested execution provider.
57
56
  *
58
57
  * `device` is `"webgpu"` or `"cpu"` (the browser picks the GPU adapter
59
58
  * automatically). WebGPU is registered with `error_on_failure`, so if the
@@ -673,17 +672,17 @@ function __wbg_get_imports() {
673
672
  return addHeapObject(ret);
674
673
  },
675
674
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
676
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 688, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
675
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 687, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
677
676
  const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1874);
678
677
  return addHeapObject(ret);
679
678
  },
680
679
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
681
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 797, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
680
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 796, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
682
681
  const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_2272);
683
682
  return addHeapObject(ret);
684
683
  },
685
684
  __wbindgen_cast_0000000000000003: function(arg0, arg1) {
686
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("boolean")], shim_idx: 688, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
685
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("boolean")], shim_idx: 687, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
687
686
  const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1874_2);
688
687
  return addHeapObject(ret);
689
688
  },