/** * WebGPU inference engine for PaddleOCR PP-OCRv6 text detection model. * * Full implementation with all dispatch functions for executing the detection model. */ import { ModelType } from './types.js'; export interface DetectionBox { points: number[][]; score: number; } export interface DetectionOptions { /** * Model size variant: 'tiny', 'small', or 'medium'. * Auto-derives modelUrl from the appropriate HuggingFace repo. */ modelType?: ModelType; /** URL to the detection ONNX model. Required unless modelType is set. */ modelUrl?: string; onProgress?: (stage: string, pct?: number) => void; } export interface DetectionResult { boxes: DetectionBox[]; shape: number[]; inferenceTimeMs: number; } export declare function dbPostProcess(pred: Float32Array, predShape: number[], threshold?: number, boxThreshold?: number, unclipRatio?: number, maxCandidates?: number, minSize?: number): DetectionBox[]; /** * Engine for PP-OCRv6 text detection model. */ export declare class TextDetectionEngine { private device; private pipelines; private initializers; private activations; private shadowShapeValues; private uniformBuffers; private inputBuffer; private convBiasFuse; private fusedAddOutputs; private parsedGraph; private modelUrl; private onProgress?; private batchedEncoder; private currentSteps; /** When true, walkGraph reads back intermediate tensors for logging. Each * readback is a blocking mapAsync that pays the Chrome→GPU IPC stall, so it * is OFF by default and the production detect() path issues zero debug * readbacks. */ debug: boolean; init(options: DetectionOptions): Promise; private compileShaders; private fetchCachedBuffer; private loadModel; private uploadAsF32; private buildConvBiasFuseMap; preprocessForDetection(canvas: HTMLCanvasElement): { shape: [number, number, number, number]; data: Float32Array; naturalW: number; naturalH: number; }; private alloc; private makeUniform; private makeZeroStorage; private resolveTensor; /** * Pass-merging command encoder. Each graph node used to open its own * beginComputePass()…end(); on Metal every WebGPU compute pass becomes a * separate command encoder + flush, so a conv-heavy detection graph paid * hundreds of pass/flush round-trips per page. This wrapper keeps a SINGLE * compute pass open and reuses it across consecutive dispatches, breaking * only for buffer copies (which cannot run inside a pass) or finish(). * WebGPU auto-inserts memory barriers between dispatches in the same pass, * so node-to-node dependencies stay correct. */ private makeRecordingEncoder; private dispatchConv; private dispatchRelu; private dispatchHardSigmoid; private dispatchHardSwish; private dispatchSigmoid; private broadcastCallCount; private dispatchBroadcastBinary; private dispatchAdd; private dispatchMul; private dispatchDiv; private dispatchMaxPool; private dispatchAveragePool; private dispatchGlobalAveragePool; private dispatchReshape; private dispatchTranspose; private dispatchConcatTwo; private dispatchConcat; private dispatchResize; private dispatchConvTranspose; private dispatchShape; private dispatchGather; private dispatchSlice; private dispatchReduceMean; private dispatchErf; private dispatchSqrt; private dispatchSub; private dispatchIdentity; private dispatchNode; private walkGraph; /** * Log statistics of an activation tensor (min, max, mean, non-zero count). */ private logActivationStats; detect(canvas: HTMLCanvasElement): Promise; } //# sourceMappingURL=engine-detect.d.ts.map