UNPKG

tfjs-model-facemesh

Version:

forked from @tensorflow-models/facemesh, used for local deployed tfjs models.

94 lines (93 loc) 3.98 kB
/** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ import * as blazeface from 'tfjs-model-blazeface'; import * as tfconv from '@tensorflow/tfjs-converter'; import * as tf from '@tensorflow/tfjs-core'; interface AnnotatedPredictionValues { /** Probability of the face detection. */ faceInViewConfidence: number; boundingBox: { /** The upper left-hand corner of the face. */ topLeft: [number, number]; /** The lower right-hand corner of the face. */ bottomRight: [number, number]; }; /** Facial landmark coordinates. */ mesh: Array<[number, number, number]>; /** Facial landmark coordinates normalized to input dimensions. */ scaledMesh: Array<[number, number, number]>; /** Annotated keypoints. */ annotations?: { [key: string]: Array<[number, number, number]>; }; } interface AnnotatedPredictionTensors { faceInViewConfidence: number; boundingBox: { topLeft: tf.Tensor1D; bottomRight: tf.Tensor1D; }; mesh: tf.Tensor2D; scaledMesh: tf.Tensor2D; } export declare type AnnotatedPrediction = AnnotatedPredictionValues | AnnotatedPredictionTensors; /** * Load the model. * * @param options - a configuration object with the following properties: * - `maxContinuousChecks` How many frames to go without running the bounding * box detector. Only relevant if maxFaces > 1. Defaults to 5. * - `detectionConfidence` Threshold for discarding a prediction. Defaults to * 0.9. * - `maxFaces` The maximum number of faces detected in the input. Should be * set to the minimum number for performance. Defaults to 10. * - `iouThreshold` A float representing the threshold for deciding whether * boxes overlap too much in non-maximum suppression. Must be between [0, 1]. * Defaults to 0.3. * - `scoreThreshold` A threshold for deciding when to remove boxes based * on score in non-maximum suppression. Defaults to 0.75. */ export declare function load({ maxContinuousChecks, detectionConfidence, maxFaces, iouThreshold, scoreThreshold }?: { maxContinuousChecks?: number; detectionConfidence?: number; maxFaces?: number; iouThreshold?: number; scoreThreshold?: number; }, blazefaceModelUrl?: string, facemeshModelUrl?: string): Promise<FaceMesh>; export declare class FaceMesh { private pipeline; private detectionConfidence; constructor(blazeFace: blazeface.BlazeFaceModel, blazeMeshModel: tfconv.GraphModel, maxContinuousChecks: number, detectionConfidence: number, maxFaces: number); static getAnnotations(): { [key: string]: number[]; }; /** * Returns an array of faces in an image. * * @param input The image to classify. Can be a tensor, DOM element image, * video, or canvas. * @param returnTensors (defaults to `false`) Whether to return tensors as * opposed to values. * @param flipHorizontal Whether to flip/mirror the facial keypoints * horizontally. Should be true for videos that are flipped by default (e.g. * webcams). * * @return An array of AnnotatedPrediction objects. */ estimateFaces(input: tf.Tensor3D | ImageData | HTMLVideoElement | HTMLImageElement | HTMLCanvasElement, returnTensors?: boolean, flipHorizontal?: boolean): Promise<AnnotatedPrediction[]>; } export {};