@ultralytics/yolo 0.0.25 → 0.0.26
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 +49 -18
- package/dist/index.d.ts +5 -2
- package/dist/index.js +6 -3
- package/package.json +1 -1
- package/pkg/package.json +1 -1
- package/pkg/ultralytics_inference_web.d.ts +4 -4
- package/pkg/ultralytics_inference_web.js +12 -12
- package/pkg/ultralytics_inference_web_bg.wasm +0 -0
- package/pkg/ultralytics_inference_web_bg.wasm.d.ts +4 -4
package/README.md
CHANGED
|
@@ -75,6 +75,14 @@ const results = await model.predict(canvas, { conf: 0.25, iou: 0.7 });
|
|
|
75
75
|
console.log(model.device); // "webgpu" or "cpu"
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
+
`YOLO.load` also takes a `Blob`/`File`, so you can load a model the user drops or
|
|
79
|
+
picks. The backend is detected from the bytes, so the same call handles `.onnx`
|
|
80
|
+
and `.tflite`:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const model = await YOLO.load(fileInput.files[0]); // a dropped/picked .onnx or .tflite
|
|
84
|
+
```
|
|
85
|
+
|
|
78
86
|
### Webcam / Video
|
|
79
87
|
|
|
80
88
|
Drawable sources (`<video>`, canvas, `ImageBitmap`, `ImageData`) take a
|
|
@@ -97,9 +105,9 @@ async function frame() {
|
|
|
97
105
|
<br>
|
|
98
106
|
<br>
|
|
99
107
|
|
|
100
|
-
Runs [YOLOv8](https://docs.ultralytics.com/models/yolov8),
|
|
101
|
-
[YOLO11](https://docs.ultralytics.com/models/yolo11), and
|
|
102
|
-
[YOLO26](https://docs.ultralytics.com/models/yolo26) ONNX exports for detection,
|
|
108
|
+
Runs [Ultralytics YOLOv8](https://docs.ultralytics.com/models/yolov8),
|
|
109
|
+
[Ultralytics YOLO11](https://docs.ultralytics.com/models/yolo11), and
|
|
110
|
+
[Ultralytics YOLO26](https://docs.ultralytics.com/models/yolo26) ONNX exports for detection,
|
|
103
111
|
segmentation, pose, OBB, classification, and semantic segmentation.
|
|
104
112
|
|
|
105
113
|
Pass a bare ONNX name and it is **auto-downloaded** from the
|
|
@@ -110,8 +118,8 @@ same weights the native crate and Python use):
|
|
|
110
118
|
await YOLO.load("yolo26n.onnx"); // auto-downloads from the release: .../download/v8.4.0/yolo26n.onnx
|
|
111
119
|
```
|
|
112
120
|
|
|
113
|
-
Auto-download covers **
|
|
114
|
-
with task suffixes `-seg`, `-pose`, `-cls`, `-obb`, and `-sem` (semantic,
|
|
121
|
+
Auto-download covers **Ultralytics YOLO26**, **Ultralytics YOLO11**, and **Ultralytics YOLOv8** in sizes `n/s/m/l/x`
|
|
122
|
+
with task suffixes `-seg`, `-pose`, `-cls`, `-obb`, and `-sem` (semantic, Ultralytics YOLO26
|
|
115
123
|
only). A value containing a `/` or a scheme is used as a URL/path as-is.
|
|
116
124
|
|
|
117
125
|
> **CORS note:** GitHub release assets do not send `Access-Control-Allow-Origin`,
|
|
@@ -190,27 +198,50 @@ Only the inference engine changes; the preprocessing, postprocessing, drawing,
|
|
|
190
198
|
and `Results` shape are the same shared Rust code, so output matches the `ort`
|
|
191
199
|
path.
|
|
192
200
|
|
|
193
|
-
|
|
194
|
-
`
|
|
195
|
-
only setup is
|
|
201
|
+
The backend is picked from the file extension: a `.tflite` runs on LiteRT.js, a
|
|
202
|
+
`.onnx` on ONNX Runtime Web. The LiteRT.js wasm loads from a CDN by default, so
|
|
203
|
+
the only setup is making `@litertjs/core` resolve (along with its `@litertjs/wasm-utils`
|
|
204
|
+
dependency, which npm installs automatically and the import map below lists explicitly).
|
|
205
|
+
|
|
206
|
+
**With npm (a bundler):**
|
|
196
207
|
|
|
197
208
|
```bash
|
|
198
|
-
npm install @litertjs/core
|
|
209
|
+
npm install @ultralytics/yolo @litertjs/core
|
|
199
210
|
```
|
|
200
211
|
|
|
201
212
|
```ts
|
|
202
213
|
import { YOLO, annotate } from "@ultralytics/yolo";
|
|
203
214
|
|
|
204
|
-
const model = await YOLO.load("/models/yolo26n.tflite"
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
215
|
+
const model = await YOLO.load("/models/yolo26n.tflite"); // .tflite -> LiteRT.js
|
|
216
|
+
const results = await model.predict("bus.jpg");
|
|
217
|
+
await annotate(document.querySelector("canvas"), "bus.jpg", results);
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
**Without a build step (CDN):** map the modules to a CDN, then use the exact same
|
|
221
|
+
code as above:
|
|
222
|
+
|
|
223
|
+
```html
|
|
224
|
+
<script type="importmap">
|
|
225
|
+
{
|
|
226
|
+
"imports": {
|
|
227
|
+
"@ultralytics/yolo": "https://esm.sh/@ultralytics/yolo",
|
|
228
|
+
"@litertjs/core": "https://esm.sh/@litertjs/core",
|
|
229
|
+
"@litertjs/wasm-utils": "https://esm.sh/@litertjs/wasm-utils"
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
</script>
|
|
233
|
+
```
|
|
209
234
|
|
|
210
|
-
|
|
211
|
-
|
|
235
|
+
For webcam or video, pass the `<video>` element each frame:
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
const results = await model.predict(video);
|
|
239
|
+
await annotate(canvas, video, results);
|
|
212
240
|
```
|
|
213
241
|
|
|
242
|
+
The wasm loads from the jsDelivr CDN by default; pass `litertWasmUrl: "/litert/"` to
|
|
243
|
+
`YOLO.load` to self-host it (copy `node_modules/@litertjs/core/wasm/`).
|
|
244
|
+
|
|
214
245
|
Notes:
|
|
215
246
|
|
|
216
247
|
- **Model**: export with Ultralytics to `.tflite` (float32 for WebGPU). It loads
|
|
@@ -220,8 +251,8 @@ Notes:
|
|
|
220
251
|
embedded metadata) ships in
|
|
221
252
|
[v8.4.83](https://github.com/ultralytics/ultralytics/releases/tag/v8.4.83) and
|
|
222
253
|
later. Earlier versions emit the legacy TFLite format and won't load here.
|
|
223
|
-
- **Export end2end-free models** (`end2end=False`): YOLO26
|
|
224
|
-
|
|
254
|
+
- **Export end2end-free models** (`end2end=False`): Ultralytics YOLO26 defaults to an
|
|
255
|
+
end-to-end, NMS-free head whose `int64` / `gather_nd` ops the LiteRT
|
|
225
256
|
**WebGPU** delegate cannot run, so those exports silently fall back to CPU/wasm.
|
|
226
257
|
Export them with `end2end=False` so the standard head is used and NMS runs in
|
|
227
258
|
this package's Rust, keeping inference on WebGPU:
|
package/dist/index.d.ts
CHANGED
|
@@ -92,6 +92,8 @@ export interface LoadOptions {
|
|
|
92
92
|
*/
|
|
93
93
|
litertWasmUrl?: string | URL;
|
|
94
94
|
}
|
|
95
|
+
/** A model source: a URL/path, raw bytes, or a `Blob`/`File` (e.g. a dropped file). */
|
|
96
|
+
export type ModelSource = string | URL | ArrayBuffer | Uint8Array | Blob;
|
|
95
97
|
/** Options for {@link YOLO.predict}. */
|
|
96
98
|
export interface PredictOptions {
|
|
97
99
|
/** Confidence threshold. Default `0.25` (matches Ultralytics). */
|
|
@@ -132,10 +134,11 @@ export declare class YOLO {
|
|
|
132
134
|
* The engine is chosen from the model: a `.tflite` runs on LiteRT.js, an
|
|
133
135
|
* `.onnx` on ONNX Runtime Web.
|
|
134
136
|
*
|
|
135
|
-
* @param source Model URL/path,
|
|
137
|
+
* @param source Model URL/path, raw bytes, or a `Blob`/`File` (e.g. from a file
|
|
138
|
+
* input or drag-and-drop). `.onnx` or `.tflite`.
|
|
136
139
|
* @param options Loader options.
|
|
137
140
|
*/
|
|
138
|
-
static load(source:
|
|
141
|
+
static load(source: ModelSource, options?: LoadOptions): Promise<YOLO>;
|
|
139
142
|
/** Load the LiteRT (`.tflite`) backend. Metadata (task, class names, `imgsz`)
|
|
140
143
|
* is read from the single `.tflite` file, the same as the `.onnx` path. */
|
|
141
144
|
private static loadLiteRt;
|
package/dist/index.js
CHANGED
|
@@ -61,8 +61,8 @@ function isTflite(bytes) {
|
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* Pick the inference backend from the model: `.tflite` -> `litert`, `.onnx` ->
|
|
64
|
-
* `ort`. When the source has no known extension (raw bytes,
|
|
65
|
-
* signed URL), the already-fetched `bytes` are sniffed for
|
|
64
|
+
* `ort`. When the source has no known extension (raw bytes, a `Blob`/`File`, or an
|
|
65
|
+
* extensionless/signed URL), the already-fetched `bytes` are sniffed for `TFL3`.
|
|
66
66
|
*/
|
|
67
67
|
function inferBackend(source, bytes) {
|
|
68
68
|
if (typeof source === "string" || source instanceof URL) {
|
|
@@ -337,6 +337,8 @@ async function fetchModelBytes(source) {
|
|
|
337
337
|
const resp = await fetchOk(source.toString(), "model");
|
|
338
338
|
return new Uint8Array(await resp.arrayBuffer());
|
|
339
339
|
}
|
|
340
|
+
if (source instanceof Blob)
|
|
341
|
+
return new Uint8Array(await source.arrayBuffer());
|
|
340
342
|
return source instanceof Uint8Array ? source : new Uint8Array(source);
|
|
341
343
|
}
|
|
342
344
|
/**
|
|
@@ -353,7 +355,8 @@ export class YOLO {
|
|
|
353
355
|
* The engine is chosen from the model: a `.tflite` runs on LiteRT.js, an
|
|
354
356
|
* `.onnx` on ONNX Runtime Web.
|
|
355
357
|
*
|
|
356
|
-
* @param source Model URL/path,
|
|
358
|
+
* @param source Model URL/path, raw bytes, or a `Blob`/`File` (e.g. from a file
|
|
359
|
+
* input or drag-and-drop). `.onnx` or `.tflite`.
|
|
357
360
|
* @param options Loader options.
|
|
358
361
|
*/
|
|
359
362
|
static async load(source, options) {
|
package/package.json
CHANGED
package/pkg/package.json
CHANGED
|
@@ -184,10 +184,10 @@ export interface InitOutput {
|
|
|
184
184
|
readonly yolopipeline_preprocess_rgba: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
185
185
|
readonly yolopipeline_task: (a: number, b: number) => void;
|
|
186
186
|
readonly start: () => void;
|
|
187
|
-
readonly
|
|
188
|
-
readonly
|
|
189
|
-
readonly
|
|
190
|
-
readonly
|
|
187
|
+
readonly __wasm_bindgen_func_elem_1968: (a: number, b: number, c: number, d: number) => void;
|
|
188
|
+
readonly __wasm_bindgen_func_elem_2573: (a: number, b: number, c: number, d: number) => void;
|
|
189
|
+
readonly __wasm_bindgen_func_elem_1968_2: (a: number, b: number, c: number, d: number) => void;
|
|
190
|
+
readonly __wasm_bindgen_func_elem_2583: (a: number, b: number, c: number, d: number) => void;
|
|
191
191
|
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
192
192
|
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
193
193
|
readonly __wbindgen_export3: (a: number) => void;
|
|
@@ -696,7 +696,7 @@ function __wbg_get_imports() {
|
|
|
696
696
|
const a = state0.a;
|
|
697
697
|
state0.a = 0;
|
|
698
698
|
try {
|
|
699
|
-
return
|
|
699
|
+
return __wasm_bindgen_func_elem_2583(a, state0.b, arg0, arg1);
|
|
700
700
|
} finally {
|
|
701
701
|
state0.a = a;
|
|
702
702
|
}
|
|
@@ -887,17 +887,17 @@ function __wbg_get_imports() {
|
|
|
887
887
|
},
|
|
888
888
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
889
889
|
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 689, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
890
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
890
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1968);
|
|
891
891
|
return addHeapObject(ret);
|
|
892
892
|
},
|
|
893
893
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
894
894
|
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 916, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
895
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
895
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_2573);
|
|
896
896
|
return addHeapObject(ret);
|
|
897
897
|
},
|
|
898
898
|
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
|
899
899
|
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("boolean")], shim_idx: 689, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
900
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
900
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1968_2);
|
|
901
901
|
return addHeapObject(ret);
|
|
902
902
|
},
|
|
903
903
|
__wbindgen_cast_0000000000000004: function(arg0) {
|
|
@@ -984,10 +984,10 @@ function __wbg_get_imports() {
|
|
|
984
984
|
};
|
|
985
985
|
}
|
|
986
986
|
|
|
987
|
-
function
|
|
987
|
+
function __wasm_bindgen_func_elem_1968(arg0, arg1, arg2) {
|
|
988
988
|
try {
|
|
989
989
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
990
|
-
wasm.
|
|
990
|
+
wasm.__wasm_bindgen_func_elem_1968(retptr, arg0, arg1, addHeapObject(arg2));
|
|
991
991
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
992
992
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
993
993
|
if (r1) {
|
|
@@ -998,10 +998,10 @@ function __wasm_bindgen_func_elem_1961(arg0, arg1, arg2) {
|
|
|
998
998
|
}
|
|
999
999
|
}
|
|
1000
1000
|
|
|
1001
|
-
function
|
|
1001
|
+
function __wasm_bindgen_func_elem_2573(arg0, arg1, arg2) {
|
|
1002
1002
|
try {
|
|
1003
1003
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1004
|
-
wasm.
|
|
1004
|
+
wasm.__wasm_bindgen_func_elem_2573(retptr, arg0, arg1, addHeapObject(arg2));
|
|
1005
1005
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1006
1006
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1007
1007
|
if (r1) {
|
|
@@ -1012,10 +1012,10 @@ function __wasm_bindgen_func_elem_2566(arg0, arg1, arg2) {
|
|
|
1012
1012
|
}
|
|
1013
1013
|
}
|
|
1014
1014
|
|
|
1015
|
-
function
|
|
1015
|
+
function __wasm_bindgen_func_elem_1968_2(arg0, arg1, arg2) {
|
|
1016
1016
|
try {
|
|
1017
1017
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1018
|
-
wasm.
|
|
1018
|
+
wasm.__wasm_bindgen_func_elem_1968_2(retptr, arg0, arg1, addHeapObject(arg2));
|
|
1019
1019
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1020
1020
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1021
1021
|
if (r1) {
|
|
@@ -1026,8 +1026,8 @@ function __wasm_bindgen_func_elem_1961_2(arg0, arg1, arg2) {
|
|
|
1026
1026
|
}
|
|
1027
1027
|
}
|
|
1028
1028
|
|
|
1029
|
-
function
|
|
1030
|
-
wasm.
|
|
1029
|
+
function __wasm_bindgen_func_elem_2583(arg0, arg1, arg2, arg3) {
|
|
1030
|
+
wasm.__wasm_bindgen_func_elem_2583(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
1031
1031
|
}
|
|
1032
1032
|
|
|
1033
1033
|
|
|
Binary file
|
|
@@ -18,10 +18,10 @@ export const yolopipeline_postprocess: (a: number, b: number, c: number, d: numb
|
|
|
18
18
|
export const yolopipeline_preprocess_rgba: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
19
19
|
export const yolopipeline_task: (a: number, b: number) => void;
|
|
20
20
|
export const start: () => void;
|
|
21
|
-
export const
|
|
22
|
-
export const
|
|
23
|
-
export const
|
|
24
|
-
export const
|
|
21
|
+
export const __wasm_bindgen_func_elem_1968: (a: number, b: number, c: number, d: number) => void;
|
|
22
|
+
export const __wasm_bindgen_func_elem_2573: (a: number, b: number, c: number, d: number) => void;
|
|
23
|
+
export const __wasm_bindgen_func_elem_1968_2: (a: number, b: number, c: number, d: number) => void;
|
|
24
|
+
export const __wasm_bindgen_func_elem_2583: (a: number, b: number, c: number, d: number) => void;
|
|
25
25
|
export const __wbindgen_export: (a: number, b: number) => number;
|
|
26
26
|
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
27
27
|
export const __wbindgen_export3: (a: number) => void;
|