UNPKG

ppu-yolo-onnx-inference

Version:

Use your YOLO onnx object detection model in Typescript Bun environment easily.

104 lines (103 loc) 2.93 kB
import type { Tensor } from "onnxruntime-node"; /** * Controls verbose output and image dumps for debugging OCR. */ export interface DebuggingOptions { /** * Enable detailed logging of each processing step. * @default false */ verbose?: boolean; /** * Save intermediate image data to disk for inspection. * @default false */ debug?: boolean; /** * Directory where debug images will be written. * Relative to the current working directory. * @default "out" */ debugFolder?: string; } /** * Simple rectangle representation. */ export interface Box { /** X-coordinate of the top-left corner. */ x: number; /** Y-coordinate of the top-left corner. */ y: number; /** Width of the box in pixels. */ width: number; /** Height of the box in pixels. */ height: number; } export interface ModelOptions { onnx: ArrayBuffer; classNames: string[]; } export interface ModelThresholds { confidence?: number; iou?: number; classConfidence?: number; } export interface ModelMetadata { inputShape: [number, number]; inputTensorName: string; outputTensorName: string; } export interface YoloDetectionOptions { /** File paths to the required Onnx YOLO model and class name list. */ model: ModelOptions; /** Controls threshold for object detection. */ thresholds?: ModelThresholds; /** Controls model input output tensor metadata. */ modelMetadata?: ModelMetadata; /** Controls logging and image dump behavior for debugging. */ debug?: DebuggingOptions; } export interface PreprocessYoloResult { tensor: Float32Array; modelInputWidth: number; modelInputHeight: number; originalWidth: number; originalHeight: number; scaleRatio: number; } export interface DetectedObject { box: Box; className: string; classId: number; confidence: number; } /** * The common part of the value metadata type for both tensor and non-tensor values. */ export interface ValueMetadataBase { /** * The name of the specified input or output. */ readonly name: string; } /** * Represents the metadata of a tensor value. */ export interface TensorValueMetadata extends ValueMetadataBase { /** * Get a value indicating whether the value is a tensor. */ readonly isTensor: true; /** * Get the data type of the tensor. */ readonly type: Tensor.Type; /** * Get the shape of the tensor. * * If the shape is not defined, the value will an empty array. Otherwise, it will be an array representing the shape * of the tensor. Each element in the array can be a number or a string. If the element is a number, it represents * the corresponding dimension size. If the element is a string, it represents a symbolic dimension. */ readonly shape: ReadonlyArray<number | string>; }