UNPKG

yolo-helpers

Version:

Helper functions to use models converted from YOLO in browser and Node.js

70 lines (69 loc) 2.05 kB
import type * as tf_type from '@tensorflow/tfjs'; export type BoundingBox = { /** center x of bounding box in px */ x: number; /** center y of bounding box in px */ y: number; /** width of bounding box in px */ width: number; /** height of bounding box in px */ height: number; /** class index with highest confidence */ class_index: number; /** confidence of the class with highest confidence */ confidence: number; /** confidence of all classes */ all_confidences: number[]; }; /** * output shape: [batch, box] * * Array of batches, each containing array of detected bounding boxes * */ export type BoxResult = BoundingBox[][]; export type DecodeBoxArgs = { /** * tensorflow runtime: * - browser: `import * as tf from '@tensorflow/tfjs'` * - nodejs: `import * as tf from '@tensorflow/tfjs-node'` */ tf: typeof tf_type; /** e.g. `1` for single class */ num_classes: number; /** batched predict result, e.g. 1x84x8400 */ output: number[][][]; /** * Number of boxes to return using non-max suppression. * If not provided, all boxes will be returned * * e.g. `1` for only selecting the bounding box with highest confidence. */ maxOutputSize?: number; /** * the threshold for deciding whether boxes overlap too much with respect to IOU. * * default: `0.5` */ iouThreshold?: number; /** * the threshold for deciding whether a box is a valid detection. * * default: `-Infinity` */ scoreThreshold?: number; }; /** * tensorflow output: [batch, features, instances] * features: * - 4: x, y, width, height * - num_classes: class confidence * * e.g. 1x84x8400 for 1 batch of 8400 instances with 80 classes * * The confidence are already normalized between 0 to 1. */ export declare function decodeBox(args: DecodeBoxArgs): Promise<BoxResult>; /** * Sync version of `decodeBox`. */ export declare function decodeBoxSync(args: DecodeBoxArgs): BoxResult;