/* tslint:disable */ /* eslint-disable */ /** * A loaded ONNX model that runs end to end in wasm (preprocess, inference on * ONNX Runtime Web, and postprocess), for the `.onnx` path. * * Created via [`YoloModel::load_bytes`]; run with [`YoloModel::predict`]. The * TypeScript `YOLO` class wraps this for ONNX models, and [`YoloPipeline`] for * `.tflite` ones. */ export class YoloModel { private constructor(); free(): void; [Symbol.dispose](): void; /** * Load a model from raw ONNX bytes (fetched by the JS wrapper). * * Initializes the accelerated backend on first use, reads the embedded * Ultralytics metadata from the model bytes, then commits an ONNX Runtime * session on the requested execution provider. * * `device` is `"webgpu"` or `"cpu"` (the browser picks the GPU adapter * automatically). WebGPU is registered with `error_on_failure`, so if the * session cannot commit on it the load falls back to CPU and * [`device`](Self::device) reports what actually ran. * * # Errors * Returns a JS error if the backend cannot start, the bytes are not a valid * model, or the model lacks Ultralytics metadata. */ static load_bytes(bytes: Uint8Array, ort_base_url: string | null | undefined, device: string): Promise; /** * Run inference on a single encoded image (JPEG or PNG bytes). * * `conf` and `iou` are the confidence and NMS IoU thresholds (pass the model * defaults 0.25 / 0.7 to match Ultralytics); `classes` optionally keeps only * the given class ids (for semantic, other pixels become background). * Returns a plain JS object whose shape mirrors the Ultralytics `Results` API. * * # Errors * Returns a JS error if the image cannot be decoded or inference fails. */ predict(image: Uint8Array, conf: number, iou: number, classes: Uint32Array | null | undefined, colormap: string, depth_viz: string): Promise; /** * Run inference on raw `RGBA` pixels (e.g. a canvas/webcam `ImageData`). * * Skips image encoding/decoding entirely, so it is the fast path for live * video. `rgba` is `width * height * 4` bytes, row-major. * * # Errors * Returns a JS error if the buffer size is wrong or inference fails. */ predict_rgba(rgba: Uint8Array, width: number, height: number, conf: number, iou: number, classes: Uint32Array | null | undefined, colormap: string, depth_viz: string): Promise; /** * The active device: `"webgpu"` or `"cpu"` (the fallback when WebGPU is * unavailable). Mirrors the native `Device` display. */ readonly device: string; /** * Class id -> name map (like Ultralytics `model.names`), as a JS object. * * # Errors * Returns a JS error only if serialization fails (not expected). */ readonly names: any; /** * The model's task (`"detect"`, `"segment"`, `"pose"`, `"classify"`, * `"obb"`, `"semantic"`, or `"depth"`). */ readonly task: string; } /** * A metadata-only YOLO pre/post pipeline for use with an **external** inference * engine (e.g. LiteRT.js running a `.tflite` model in JavaScript). * * Unlike [`YoloModel`], it holds no ONNX Runtime session: JavaScript loads and * runs the model, while this struct reuses the shared Rust preprocessing and * postprocessing so results match every other path. Per frame the flow is * [`preprocess_rgba`](Self::preprocess_rgba) → (JS engine inference) → * [`postprocess`](Self::postprocess). It assumes a single prediction in flight * at a time (as the webcam render loop does). */ export class YoloPipeline { free(): void; [Symbol.dispose](): void; /** * Build a pipeline from a single-file `.tflite` model, reading the * Ultralytics metadata (task, class names, `imgsz`, ...) embedded in the * model bytes, the same way [`YoloModel::load_bytes`] reads it from an ONNX * model, so the ONNX and LiteRT paths load identically from one file. * * # Errors * Returns a JS error if the model carries no Ultralytics metadata or it * cannot be parsed. */ constructor(tflite: Uint8Array); /** * Postprocess an external engine's raw outputs into the standard `Results`. * * `outputs` are the model's output tensors (one for most tasks; two for * segmentation: detection head + mask prototypes). `shapes` encodes each * output's dims flat as `[rank0, dims0..., rank1, dims1...]`. `inference_ms` * is the time the JS engine reported, used only for the `speed` breakdown. * Consumes the frame stashed by the preceding * [`preprocess_rgba`](Self::preprocess_rgba). * * # Errors * Returns a JS error if called before `preprocess_rgba`, if `shapes` is * malformed, or on serialization failure. */ postprocess(outputs: Float32Array[], shapes: Uint32Array, inference_ms: number, conf: number, iou: number, classes: Uint32Array | null | undefined, colormap: string, depth_viz: string): any; /** * Preprocess raw RGBA pixels (e.g. a webcam `ImageData`) into the NCHW f32 * input tensor an Ultralytics LiteRT/TFLite model expects, normalized to * `[0, 1]`, the same preprocessing as the ONNX path. * * Returns the tensor as a `Float32Array` (shape `[1, 3, H, W]`); the * letterbox geometry and original image are stashed for the matching * [`postprocess`](Self::postprocess) call. * * # Errors * Returns a JS error if the buffer size is not `width * height * 4`. */ preprocess_rgba(rgba: Uint8Array, width: number, height: number): Float32Array; /** * Adopt the input shape the engine reports for the compiled model. * * Without it the size comes from the metadata, which the graph itself never has to * agree with, and [`input_shape`](Self::input_shape) is what the caller sizes its * input tensor from - so a stale `imgsz` would feed the model a tensor it rejects. * The ONNX path reads the same fact off its session; this is the LiteRT equivalent, * which only the JS engine can see. * * Expects NCHW `[N, 3, H, W]`, what `ai_edge_torch` emits, with the signed dimensions * the engine reports. Any other rank or layout (a channels-last `[N, H, W, 3]`) and any * non-positive axis, which is how a dynamic dimension is reported, is ignored and leaves * the metadata size in place. */ setInputShape(shape: Int32Array): void; /** * Whether this is an end-to-end (NMS-free) export, e.g. YOLO26. Its head runs * the NMS/top-k with `int64`/`gather_nd` ops that the LiteRT WebGPU delegate * cannot execute, so such models must run on the CPU (wasm) accelerator. */ readonly end2end: boolean; /** * The model input shape as `[1, 3, H, W]` (NCHW), for sizing the engine's * input tensor. Ultralytics LiteRT exports (`ai_edge_torch`) keep the native * NCHW layout, matching the ONNX path. */ readonly inputShape: Uint32Array; /** * Class id -> name map (like `model.names`), as a JS object. * * # Errors * Returns a JS error only if serialization fails (not expected). */ readonly names: any; /** * The model's task (`"detect"`, `"segment"`, ...). */ readonly task: string; } /** * Return the Ultralytics pose skeleton + keypoint/limb colors (constant). The * JS annotator calls this once to color pose overlays from the shared palette. * * # Errors * Returns a JS error only if serialization fails (not expected). */ export function pose_palette(): any; /** * Install a panic hook that logs Rust panics to the browser console. */ export function start(): void; export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; export interface InitOutput { readonly memory: WebAssembly.Memory; readonly __wbg_yolomodel_free: (a: number, b: number) => void; readonly __wbg_yolopipeline_free: (a: number, b: number) => void; readonly pose_palette: (a: number) => void; readonly yolomodel_device: (a: number, b: number) => void; readonly yolomodel_load_bytes: (a: number, b: number, c: number, d: number, e: number, f: number) => number; readonly yolomodel_names: (a: number, b: number) => void; 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; 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; readonly yolomodel_task: (a: number, b: number) => void; readonly yolopipeline_end2end: (a: number) => number; readonly yolopipeline_inputShape: (a: number, b: number) => void; readonly yolopipeline_names: (a: number, b: number) => void; readonly yolopipeline_new: (a: number, b: number, c: number) => void; 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; readonly yolopipeline_preprocess_rgba: (a: number, b: number, c: number, d: number, e: number, f: number) => void; readonly yolopipeline_setInputShape: (a: number, b: number, c: number) => void; readonly yolopipeline_task: (a: number, b: number) => void; readonly start: () => void; readonly __wasm_bindgen_func_elem_1984: (a: number, b: number, c: number, d: number) => void; readonly __wasm_bindgen_func_elem_2589: (a: number, b: number, c: number, d: number) => void; readonly __wasm_bindgen_func_elem_1984_2: (a: number, b: number, c: number, d: number) => void; readonly __wasm_bindgen_func_elem_2613: (a: number, b: number, c: number, d: number) => void; readonly __wbindgen_export: (a: number, b: number) => number; readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number; readonly __wbindgen_export3: (a: number) => void; readonly __wbindgen_export4: (a: number, b: number, c: number) => void; readonly __wbindgen_export5: (a: number, b: number) => void; readonly __wbindgen_add_to_stack_pointer: (a: number) => number; readonly __wbindgen_start: () => void; } export type SyncInitInput = BufferSource | WebAssembly.Module; /** * Instantiates the given `module`, which can either be bytes or * a precompiled `WebAssembly.Module`. * * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated. * * @returns {InitOutput} */ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput; /** * If `module_or_path` is {RequestInfo} or {URL}, makes a request and * for everything else, calls `WebAssembly.instantiate` directly. * * @param {{ module_or_path: InitInput | Promise }} module_or_path - Passing `InitInput` directly is deprecated. * * @returns {Promise} */ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise } | InitInput | Promise): Promise;