UNPKG

yolo-helpers

Version:

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

72 lines (71 loc) 2.15 kB
import type * as tf_type from '@tensorflow/tfjs'; import { BoundingBox } from '../yolo-box/common'; export type Keypoint = { /** x of keypoint in px */ x: number; /** y of keypoint in px */ y: number; /** confidence of keypoint */ visibility: number; }; export type BoundingBoxWithKeypoints = BoundingBox & { keypoints: Keypoint[]; }; /** * output shape: [batch, box] * * Array of batches, each containing array of detected bounding boxes with keypoints * */ export type PoseResult = BoundingBoxWithKeypoints[][]; export type DecodePoseArgs = { /** * 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; /** e.g. `17` for 17 keypoints */ num_keypoints: number; /** for each keypoints, are them {x,y} or {x,y,visibility} */ visibility: boolean; /** batched predict result, e.g. 1x17x8400 */ 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 * - num_keypoints * 3: keypoint x, y, visibility * * e.g. 1x17x8400 for 1 batch of 8400 instances with 4 keypoints and 1 class * (17 = 4 + 1 + 4 * 3) * * The confidence are already normalized between 0 to 1. */ export declare function decodePose(args: DecodePoseArgs): Promise<PoseResult>; /** * Sync version of `decodePose`. */ export declare function decodePoseSync(args: DecodePoseArgs): PoseResult;