ppu-yolo-onnx-inference
Version:
Use your YOLO onnx object detection model in Typescript Bun environment easily.
61 lines (60 loc) • 2.44 kB
TypeScript
import type { DebuggingOptions, DetectedObject, ModelThresholds, YoloDetectionOptions } from "../interface.js";
import type { CoreCanvas, PlatformProvider } from "./platform.js";
/**
* Platform-agnostic YOLOv11 Object Detection Inference Engine.
*
* Contains all business logic for image preprocessing, model inference,
* and NMS post-processing. Platform-specific behaviour (canvas creation,
* ONNX runtime, file I/O) is delegated to the injected {@link PlatformProvider}.
*/
export declare class BaseYoloDetectionInference {
private readonly model;
/** Class names for object detection labels. */
protected readonly classNames: string[];
/** Merged threshold configuration. */
protected readonly thresholds: Required<ModelThresholds>;
/** Merged debugging configuration. */
protected readonly debugging: Required<DebuggingOptions>;
/** Platform abstraction layer. */
protected readonly platform: PlatformProvider;
private modelMetadata;
private session;
private static readonly CHANNELS;
constructor(options: YoloDetectionOptions, platform: PlatformProvider);
/**
* Whether the model session has been initialised.
* @returns `true` after a successful {@link init} call.
*/
isInitialized(): boolean;
/**
* Initialize the YOLO model and prepare for inference.
*/
init(): Promise<void>;
/**
* Detect objects in an image.
* @param image - The input image as ArrayBuffer or platform canvas.
* @returns An array of detected objects with bounding boxes, class names, and confidence scores.
* @throws Error if the model is not initialized or detection fails.
*/
detect(image: ArrayBuffer | CoreCanvas): Promise<DetectedObject[]>;
private preprocessImage;
private canvasToTensor;
private runInference;
private postprocessOutput;
private extractCandidates;
private extractWithLowerThreshold;
private debugTensorData;
private applyNMS;
private scaleCandidates;
private calculateIoU;
private saveDebugImages;
private savePreprocessedImage;
private saveDetectionVisualization;
/** Log a message when verbose debugging is enabled. */
protected log(caller: string, message: string): void;
/**
* Releases the ONNX runtime session and cleans up resources.
* Safe to call even if the model was never initialised.
*/
destroy(): Promise<void>;
}