human/src/config.ts

411 lines
12 KiB
TypeScript
Raw Normal View History

2020-10-16 21:04:51 +02:00
/* eslint-disable indent */
/* eslint-disable no-multi-spaces */
2021-10-25 19:09:00 +02:00
/** Generic config type inherited by all module types */
2021-10-22 22:09:52 +02:00
export interface GenericConfig {
2021-10-25 19:09:00 +02:00
/** @property is module enabled? */
2021-10-22 22:09:52 +02:00
enabled: boolean,
2021-10-25 19:09:00 +02:00
/** @property path to model json file */
2021-09-12 06:05:06 +02:00
modelPath: string,
2021-10-25 19:09:00 +02:00
/** @property how many max frames to go without re-running model if cached results are acceptable */
2021-10-22 22:09:52 +02:00
skipFrames: number,
2021-10-25 19:09:00 +02:00
/** @property how many max miliseconds to go without re-running model if cached results are acceptable */
2021-10-22 22:09:52 +02:00
skipTime: number,
}
/** Dectector part of face configuration */
export interface FaceDetectorConfig extends GenericConfig {
2021-10-25 19:09:00 +02:00
/** @property is face rotation correction performed after detecting face? */
2021-09-12 06:05:06 +02:00
rotation: boolean,
2021-10-25 19:09:00 +02:00
/** @property maximum number of detected faces */
2021-09-12 06:05:06 +02:00
maxDetected: number,
2021-10-25 19:09:00 +02:00
/** @property minimum confidence for a detected face before results are discarded */
2021-09-12 06:05:06 +02:00
minConfidence: number,
2021-10-25 19:09:00 +02:00
/** @property minimum overlap between two detected faces before one is discarded */
2021-09-12 06:05:06 +02:00
iouThreshold: number,
2021-11-12 21:07:23 +01:00
/** @property factor used to expand detected face before further analysis
* - default: 1.6
* - for high-quality inputs can be reduced to increase precision
* - for video inputs or low-quality inputs can be increased to allow for more flexible tracking
*/
cropFactor: number,
/** @property should child models perform on masked image of a face */
mask: boolean,
2021-10-25 19:09:00 +02:00
/** @property should face detection return face tensor to be used in some other extenrnal model? */
2021-09-12 06:05:06 +02:00
return: boolean,
}
2021-09-22 22:00:43 +02:00
/** Mesh part of face configuration */
2021-10-25 19:09:00 +02:00
export interface FaceMeshConfig extends GenericConfig {}
2021-09-12 06:05:06 +02:00
2021-09-22 22:00:43 +02:00
/** Iris part of face configuration */
2021-10-25 19:09:00 +02:00
export interface FaceIrisConfig extends GenericConfig {}
2021-09-12 06:05:06 +02:00
2021-09-22 22:00:43 +02:00
/** Description or face embedding part of face configuration
* - also used by age and gender detection
*/
2021-10-22 22:09:52 +02:00
export interface FaceDescriptionConfig extends GenericConfig {
2021-10-25 19:09:00 +02:00
/** @property minimum confidence for a detected face before results are discarded */
2021-09-12 06:05:06 +02:00
minConfidence: number,
}
2021-09-22 22:00:43 +02:00
/** Emotion part of face configuration */
2021-10-22 22:09:52 +02:00
export interface FaceEmotionConfig extends GenericConfig {
2021-10-25 19:09:00 +02:00
/** @property minimum confidence for a detected face before results are discarded */
2021-09-12 06:05:06 +02:00
minConfidence: number,
}
2021-10-25 19:09:00 +02:00
/** Anti-spoofing part of face configuration */
export interface FaceAntiSpoofConfig extends GenericConfig {}
2021-10-13 16:56:56 +02:00
/** Liveness part of face configuration */
export interface FaceLivenessConfig extends GenericConfig {}
2021-10-25 19:09:00 +02:00
/** Configures all face-specific options: face detection, mesh analysis, age, gender, emotion detection and face description */
export interface FaceConfig extends GenericConfig {
2021-09-12 06:05:06 +02:00
detector: Partial<FaceDetectorConfig>,
mesh: Partial<FaceMeshConfig>,
iris: Partial<FaceIrisConfig>,
description: Partial<FaceDescriptionConfig>,
emotion: Partial<FaceEmotionConfig>,
2021-10-13 16:56:56 +02:00
antispoof: Partial<FaceAntiSpoofConfig>,
liveness: Partial<FaceLivenessConfig>,
2021-09-12 05:54:35 +02:00
}
2021-10-25 19:09:00 +02:00
/** Configures all body detection specific options */
2021-10-22 22:09:52 +02:00
export interface BodyConfig extends GenericConfig {
2021-10-25 19:09:00 +02:00
/** @property maximum numboer of detected bodies */
2021-09-12 05:54:35 +02:00
maxDetected: number,
2021-10-25 19:09:00 +02:00
/** @property minimum confidence for a detected body before results are discarded */
2021-09-12 05:54:35 +02:00
minConfidence: number,
2021-09-27 19:58:13 +02:00
detector?: {
2021-10-25 19:09:00 +02:00
/** @property path to optional body detector model json file */
2021-09-27 19:58:13 +02:00
modelPath: string
},
2021-09-12 05:54:35 +02:00
}
2021-10-25 19:09:00 +02:00
/** Configures all hand detection specific options */
2021-10-22 22:09:52 +02:00
export interface HandConfig extends GenericConfig {
2021-10-25 19:09:00 +02:00
/** @property should hand rotation correction be performed after hand detection? */
2021-09-12 05:54:35 +02:00
rotation: boolean,
2021-10-25 19:09:00 +02:00
/** @property minimum confidence for a detected hand before results are discarded */
2021-09-12 05:54:35 +02:00
minConfidence: number,
2021-10-25 19:09:00 +02:00
/** @property minimum overlap between two detected hands before one is discarded */
2021-09-12 05:54:35 +02:00
iouThreshold: number,
2021-10-25 19:09:00 +02:00
/** @property maximum number of detected hands */
2021-09-12 05:54:35 +02:00
maxDetected: number,
2021-10-25 19:09:00 +02:00
/** @property should hand landmarks be detected or just return detected hand box */
2021-09-12 05:54:35 +02:00
landmarks: boolean,
detector: {
2021-10-25 19:09:00 +02:00
/** @property path to hand detector model json */
2021-09-12 05:59:41 +02:00
modelPath?: string,
2021-09-12 05:54:35 +02:00
},
skeleton: {
2021-10-25 19:09:00 +02:00
/** @property path to hand skeleton model json */
2021-09-12 05:59:41 +02:00
modelPath?: string,
2021-09-12 05:54:35 +02:00
},
}
2021-10-25 19:09:00 +02:00
/** Configures all object detection specific options */
2021-10-22 22:09:52 +02:00
export interface ObjectConfig extends GenericConfig {
2021-10-25 19:09:00 +02:00
/** @property minimum confidence for a detected objects before results are discarded */
2021-09-12 05:54:35 +02:00
minConfidence: number,
2021-10-25 19:09:00 +02:00
/** @property minimum overlap between two detected objects before one is discarded */
2021-09-12 05:54:35 +02:00
iouThreshold: number,
2021-10-25 19:09:00 +02:00
/** @property maximum number of detected objects */
2021-09-12 05:54:35 +02:00
maxDetected: number,
}
2021-10-25 19:09:00 +02:00
/** Configures all body segmentation module
2021-09-12 05:54:35 +02:00
* removes background from input containing person
* if segmentation is enabled it will run as preprocessing task before any other model
* alternatively leave it disabled and use it on-demand using human.segmentation method which can
* remove background or replace it with user-provided background
*/
2021-10-25 19:09:00 +02:00
export interface SegmentationConfig extends GenericConfig {
/** @property blur segmentation output by <number> pixels for more realistic image */
2021-09-22 21:16:14 +02:00
blur: number,
2021-09-12 05:54:35 +02:00
}
/** Run input through image filters before inference
2021-09-22 22:00:43 +02:00
* - available only in Browser environments
* - image filters run with near-zero latency as they are executed on the GPU using WebGL
2021-09-12 05:54:35 +02:00
*/
export interface FilterConfig {
2021-10-25 19:09:00 +02:00
/** @property are image filters enabled? */
2021-09-12 05:54:35 +02:00
enabled: boolean,
2021-11-06 15:21:51 +01:00
/** @property perform image histogram equalization
* - equalization is performed on input as a whole and detected face before its passed for further analysis
*/
2021-11-05 20:09:54 +01:00
equalization: boolean,
/** resize input width
2021-09-12 05:54:35 +02:00
* - if both width and height are set to 0, there is no resizing
* - if just one is set, second one is scaled automatically
* - if both are set, values are used as-is
2021-11-05 20:09:54 +01:00
* @property
2021-09-12 05:54:35 +02:00
*/
width: number,
2021-11-05 20:09:54 +01:00
/** resize input height
2021-09-12 05:54:35 +02:00
* - if both width and height are set to 0, there is no resizing
* - if just one is set, second one is scaled automatically
* - if both are set, values are used as-is
2021-11-05 20:09:54 +01:00
* @property
2021-09-12 05:54:35 +02:00
*/
height: number,
2021-10-25 19:09:00 +02:00
/** @property return processed canvas imagedata in result */
2021-09-12 05:54:35 +02:00
return: boolean,
2021-10-25 19:09:00 +02:00
/** @property flip input as mirror image */
2021-09-12 05:54:35 +02:00
flip: boolean,
2021-10-25 19:09:00 +02:00
/** @property range: -1 (darken) to 1 (lighten) */
2021-09-12 05:54:35 +02:00
brightness: number,
2021-10-25 19:09:00 +02:00
/** @property range: -1 (reduce contrast) to 1 (increase contrast) */
2021-09-12 05:54:35 +02:00
contrast: number,
2021-10-25 19:09:00 +02:00
/** @property range: 0 (no sharpening) to 1 (maximum sharpening) */
2021-09-12 05:54:35 +02:00
sharpness: number,
2021-10-25 19:09:00 +02:00
/** @property range: 0 (no blur) to N (blur radius in pixels) */
2021-09-12 05:54:35 +02:00
blur: number
2021-10-25 19:09:00 +02:00
/** @property range: -1 (reduce saturation) to 1 (increase saturation) */
2021-09-12 05:54:35 +02:00
saturation: number,
2021-10-25 19:09:00 +02:00
/** @property range: 0 (no change) to 360 (hue rotation in degrees) */
2021-09-12 05:54:35 +02:00
hue: number,
2021-10-25 19:09:00 +02:00
/** @property image negative */
2021-09-12 05:54:35 +02:00
negative: boolean,
2021-10-25 19:09:00 +02:00
/** @property image sepia colors */
2021-09-12 05:54:35 +02:00
sepia: boolean,
2021-10-25 19:09:00 +02:00
/** @property image vintage colors */
2021-09-12 05:54:35 +02:00
vintage: boolean,
2021-10-25 19:09:00 +02:00
/** @property image kodachrome colors */
2021-09-12 05:54:35 +02:00
kodachrome: boolean,
2021-10-25 19:09:00 +02:00
/** @property image technicolor colors */
2021-09-12 05:54:35 +02:00
technicolor: boolean,
2021-10-25 19:09:00 +02:00
/** @property image polaroid camera effect */
2021-09-12 05:54:35 +02:00
polaroid: boolean,
2021-10-25 19:09:00 +02:00
/** @property range: 0 (no pixelate) to N (number of pixels to pixelate) */
2021-09-12 05:54:35 +02:00
pixelate: number,
}
/** Controlls gesture detection */
export interface GestureConfig {
2021-10-25 19:09:00 +02:00
/** @property is gesture detection enabled? */
2021-09-12 05:54:35 +02:00
enabled: boolean,
}
2021-11-14 17:22:52 +01:00
export type BackendType = ['cpu', 'wasm', 'webgl', 'humangl', 'tensorflow', 'webgpu'];
export type WarmupType = ['' | 'none' | 'face' | 'full' | 'body'];
2021-09-12 06:30:11 +02:00
/**
* Configuration interface definition for **Human** library
*
* Contains all configurable parameters
* @typedef Config
2021-09-24 15:55:27 +02:00
*
2021-11-07 16:03:33 +01:00
* Defaults: [config](https://github.com/vladmandic/human/blob/main/src/config.ts#L262)
2021-09-12 06:30:11 +02:00
*/
2021-03-17 23:23:19 +01:00
export interface Config {
2021-09-24 15:55:27 +02:00
/** Backend used for TFJS operations
2021-10-29 21:55:20 +02:00
* valid build-in backends are:
* - Browser: `cpu`, `wasm`, `webgl`, `humangl`, `webgpu`
2021-09-24 15:55:27 +02:00
* - NodeJS: `cpu`, `wasm`, `tensorflow`
2021-10-29 21:55:20 +02:00
* default: `humangl` for browser and `tensorflow` for nodejs
2021-09-24 15:55:27 +02:00
*/
2021-09-13 19:28:35 +02:00
backend: '' | 'cpu' | 'wasm' | 'webgl' | 'humangl' | 'tensorflow' | 'webgpu',
2021-04-25 19:16:04 +02:00
2021-09-24 15:55:27 +02:00
/** Path to *.wasm files if backend is set to `wasm`
2021-11-07 16:03:33 +01:00
*
2021-10-29 21:55:20 +02:00
* default: auto-detects to link to CDN `jsdelivr` when running in browser
2021-09-24 15:55:27 +02:00
*/
2021-03-18 01:16:40 +01:00
wasmPath: string,
2021-04-25 19:16:04 +02:00
2021-10-29 21:55:20 +02:00
/** Print debug statements to console
2021-11-07 16:03:33 +01:00
*
2021-10-29 21:55:20 +02:00
* default: `true`
*/
2021-03-18 01:16:40 +01:00
debug: boolean,
2021-04-25 19:16:04 +02:00
2021-10-29 21:55:20 +02:00
/** Perform model loading and inference concurrently or sequentially
2021-11-07 16:03:33 +01:00
*
2021-10-29 21:55:20 +02:00
* default: `true`
*/
2021-03-18 01:16:40 +01:00
async: boolean,
2021-04-25 19:16:04 +02:00
2021-04-13 17:05:52 +02:00
/** What to use for `human.warmup()`
* - warmup pre-initializes all models for faster inference but can take significant time on startup
2021-10-29 21:55:20 +02:00
* - used by `webgl`, `humangl` and `webgpu` backends
2021-11-07 16:03:33 +01:00
*
2021-10-29 21:55:20 +02:00
* default: `full`
2021-04-13 17:05:52 +02:00
*/
2021-11-14 17:22:52 +01:00
warmup: '' | 'none' | 'face' | 'full' | 'body',
2021-09-13 19:28:35 +02:00
// warmup: string;
2021-04-25 19:16:04 +02:00
2021-04-13 17:05:52 +02:00
/** Base model path (typically starting with file://, http:// or https://) for all models
2021-04-25 19:16:04 +02:00
* - individual modelPath values are relative to this path
2021-11-07 16:03:33 +01:00
*
2021-10-29 21:55:20 +02:00
* default: `../models/` for browsers and `file://models/` for nodejs
2021-04-13 17:05:52 +02:00
*/
2021-04-09 14:07:58 +02:00
modelBasePath: string,
2021-04-25 19:16:04 +02:00
/** Cache sensitivity
* - values 0..1 where 0.01 means reset cache if input changed more than 1%
* - set to 0 to disable caching
2021-11-07 16:03:33 +01:00
*
2021-10-29 21:55:20 +02:00
* default: 0.7
*/
cacheSensitivity: number;
2021-11-06 15:21:51 +01:00
/** Perform immediate garbage collection on deallocated tensors instead of caching them */
deallocate: boolean;
2021-09-20 23:17:13 +02:00
/** Internal Variable */
2021-10-23 15:38:52 +02:00
skipAllowed: boolean;
2021-06-03 15:41:53 +02:00
2021-10-25 19:09:00 +02:00
/** {@link FilterConfig} */
2021-09-12 05:54:35 +02:00
filter: Partial<FilterConfig>,
2021-04-19 22:02:47 +02:00
2021-09-24 15:55:27 +02:00
/** {@link GestureConfig} */
2021-09-12 05:54:35 +02:00
gesture: Partial<GestureConfig>;
2021-04-25 19:16:04 +02:00
2021-09-24 15:55:27 +02:00
/** {@link FaceConfig} */
2021-09-12 05:54:35 +02:00
face: Partial<FaceConfig>,
2021-04-25 19:16:04 +02:00
2021-09-24 15:55:27 +02:00
/** {@link BodyConfig} */
2021-09-12 05:54:35 +02:00
body: Partial<BodyConfig>,
2021-04-25 19:16:04 +02:00
2021-09-24 15:55:27 +02:00
/** {@link HandConfig} */
2021-09-12 05:54:35 +02:00
hand: Partial<HandConfig>,
2021-04-25 19:16:04 +02:00
2021-09-24 15:55:27 +02:00
/** {@link ObjectConfig} */
2021-09-12 05:54:35 +02:00
object: Partial<ObjectConfig>,
2021-06-04 19:51:01 +02:00
2021-09-24 15:55:27 +02:00
/** {@link SegmentationConfig} */
2021-09-12 05:54:35 +02:00
segmentation: Partial<SegmentationConfig>,
2021-03-17 23:23:19 +01:00
}
2021-11-07 16:03:33 +01:00
/** - [See all default Config values...](https://github.com/vladmandic/human/blob/main/src/config.ts#L262) */
2021-03-17 23:23:19 +01:00
const config: Config = {
2021-10-29 21:55:20 +02:00
backend: '',
modelBasePath: '',
wasmPath: '',
debug: true,
async: true,
warmup: 'full',
cacheSensitivity: 0.70,
skipAllowed: false,
2021-11-06 15:21:51 +01:00
deallocate: false,
2021-10-29 21:55:20 +02:00
filter: {
enabled: true,
2021-11-05 20:09:54 +01:00
equalization: false,
2021-10-29 21:55:20 +02:00
width: 0,
height: 0,
flip: false,
return: true,
brightness: 0,
contrast: 0,
sharpness: 0,
blur: 0,
saturation: 0,
hue: 0,
negative: false,
sepia: false,
vintage: false,
kodachrome: false,
technicolor: false,
polaroid: false,
pixelate: 0,
2020-10-18 18:12:09 +02:00
},
2020-11-04 16:18:22 +01:00
gesture: {
2021-10-29 21:55:20 +02:00
enabled: true,
2020-11-04 16:18:22 +01:00
},
2020-10-12 01:22:43 +02:00
face: {
2021-10-29 21:55:20 +02:00
enabled: true,
2020-10-12 01:22:43 +02:00
detector: {
2021-10-29 21:55:20 +02:00
modelPath: 'blazeface.json',
rotation: true,
maxDetected: 1,
skipFrames: 99,
skipTime: 2500,
minConfidence: 0.2,
iouThreshold: 0.1,
2021-11-12 21:07:23 +01:00
cropFactor: 1.6,
mask: false,
2021-10-29 21:55:20 +02:00
return: false,
2020-10-12 01:22:43 +02:00
},
mesh: {
enabled: true,
2021-10-29 21:55:20 +02:00
modelPath: 'facemesh.json',
2020-10-12 01:22:43 +02:00
},
iris: {
enabled: true,
2021-10-29 21:55:20 +02:00
modelPath: 'iris.json',
2020-10-12 01:22:43 +02:00
},
2021-09-28 19:48:29 +02:00
emotion: {
enabled: true,
2021-10-29 21:55:20 +02:00
minConfidence: 0.1,
skipFrames: 99,
skipTime: 1500,
modelPath: 'emotion.json',
2021-09-28 19:48:29 +02:00
},
2021-03-21 19:18:51 +01:00
description: {
2021-10-29 21:55:20 +02:00
enabled: true,
modelPath: 'faceres.json',
skipFrames: 99,
skipTime: 3000,
minConfidence: 0.1,
2021-03-21 19:18:51 +01:00
},
2021-10-13 16:56:56 +02:00
antispoof: {
enabled: false,
2021-10-29 21:55:20 +02:00
skipFrames: 99,
skipTime: 4000,
modelPath: 'antispoof.json',
2021-10-13 16:56:56 +02:00
},
liveness: {
enabled: false,
skipFrames: 99,
skipTime: 4000,
modelPath: 'liveness.json',
},
2020-10-12 01:22:43 +02:00
},
body: {
enabled: true,
2021-10-29 21:55:20 +02:00
modelPath: 'movenet-lightning.json',
2021-09-27 19:58:13 +02:00
detector: {
2021-10-29 21:55:20 +02:00
modelPath: '',
2021-09-27 19:58:13 +02:00
},
2021-10-29 21:55:20 +02:00
maxDetected: -1,
minConfidence: 0.3,
skipFrames: 1,
skipTime: 200,
},
2020-10-12 01:22:43 +02:00
hand: {
enabled: true,
2021-10-29 21:55:20 +02:00
rotation: true,
skipFrames: 99,
2021-11-05 16:28:06 +01:00
skipTime: 1000,
2021-10-29 21:55:20 +02:00
minConfidence: 0.50,
iouThreshold: 0.2,
maxDetected: -1,
landmarks: true,
2020-10-12 01:22:43 +02:00
detector: {
2021-10-29 21:55:20 +02:00
modelPath: 'handtrack.json',
2020-10-12 01:22:43 +02:00
},
skeleton: {
2021-10-31 14:06:33 +01:00
modelPath: 'handlandmark-full.json',
2020-10-12 01:22:43 +02:00
},
},
object: {
enabled: false,
2021-10-29 21:55:20 +02:00
modelPath: 'mb3-centernet.json',
minConfidence: 0.2,
iouThreshold: 0.4,
maxDetected: 10,
skipFrames: 99,
2021-11-05 16:28:06 +01:00
skipTime: 2000,
},
2021-06-04 19:51:01 +02:00
segmentation: {
2021-10-29 21:55:20 +02:00
enabled: false,
modelPath: 'selfie.json',
blur: 8,
2021-06-04 19:51:01 +02:00
},
2020-10-12 01:22:43 +02:00
};
2021-09-24 15:55:27 +02:00
2021-03-17 23:23:19 +01:00
export { config as defaults };