human/src/config.ts

382 lines
19 KiB
TypeScript
Raw Normal View History

2020-10-16 21:04:51 +02:00
/* eslint-disable indent */
/* eslint-disable no-multi-spaces */
2021-03-17 23:23:19 +01:00
/**
* Configuration interface definition for **Human** library
*
* Contains all configurable parameters
*/
export interface Config {
2021-04-13 17:05:52 +02:00
/** Backend used for TFJS operations */
backend: null | '' | 'cpu' | 'wasm' | 'webgl' | 'humangl' | 'tensorflow',
/** Path to *.wasm files if backend is set to `wasm` */
2021-03-18 01:16:40 +01:00
wasmPath: string,
2021-04-13 17:05:52 +02:00
/** Print debug statements to console */
2021-03-18 01:16:40 +01:00
debug: boolean,
2021-04-13 17:05:52 +02:00
/** Perform model loading and inference concurrently or sequentially */
2021-03-18 01:16:40 +01:00
async: boolean,
2021-04-13 17:05:52 +02:00
/** Collect and print profiling data during inference operations */
2021-03-18 01:16:40 +01:00
profile: boolean,
2021-04-13 17:05:52 +02:00
/** Internal: Use aggressive GPU memory deallocator when backend is set to `webgl` or `humangl` */
2021-03-18 01:16:40 +01:00
deallocate: boolean,
2021-04-13 17:05:52 +02:00
/** Internal: Run all inference operations in an explicit local scope run to avoid memory leaks */
2021-03-18 01:16:40 +01:00
scoped: boolean,
2021-04-13 17:05:52 +02:00
/** Perform additional optimizations when input is video,
* - must be disabled for images
* - automatically disabled for Image, ImageData, ImageBitmap and Tensor inputs
* - skips boundary detection for every `skipFrames` frames specified for each model
* - while maintaining in-box detection since objects don't change definition as fast */
2021-03-18 01:16:40 +01:00
videoOptimized: boolean,
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
* - only used for `webgl` and `humangl` backends
*/
warmup: 'none' | 'face' | 'full' | 'body',
/** Base model path (typically starting with file://, http:// or https://) for all models
* - individual modelPath values are joined to this path
*/
2021-04-09 14:07:58 +02:00
modelBasePath: string,
2021-04-13 17:05:52 +02:00
/** Run input through image filters before inference
* - image filters run with near-zero latency as they are executed on the GPU
*/
2021-03-17 23:23:19 +01:00
filter: {
2021-03-18 01:16:40 +01:00
enabled: boolean,
2021-04-13 17:05:52 +02:00
/** Resize input width
* - 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-03-18 01:16:40 +01:00
width: number,
2021-04-13 17:05:52 +02:00
/** Resize input height
* - 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-03-18 01:16:40 +01:00
height: number,
2021-04-13 17:05:52 +02:00
/** Return processed canvas imagedata in result */
2021-03-18 01:16:40 +01:00
return: boolean,
2021-04-19 22:02:47 +02:00
/** Flip input as mirror image */
flip: boolean,
2021-04-13 17:05:52 +02:00
/** Range: -1 (darken) to 1 (lighten) */
2021-03-18 01:16:40 +01:00
brightness: number,
2021-04-13 17:05:52 +02:00
/** Range: -1 (reduce contrast) to 1 (increase contrast) */
2021-03-18 01:16:40 +01:00
contrast: number,
2021-04-13 17:05:52 +02:00
/** Range: 0 (no sharpening) to 1 (maximum sharpening) */
2021-03-18 01:16:40 +01:00
sharpness: number,
2021-04-13 17:05:52 +02:00
/** Range: 0 (no blur) to N (blur radius in pixels) */
2021-03-18 01:16:40 +01:00
blur: number
2021-04-13 17:05:52 +02:00
/** Range: -1 (reduce saturation) to 1 (increase saturation) */
2021-03-18 01:16:40 +01:00
saturation: number,
2021-04-13 17:05:52 +02:00
/** Range: 0 (no change) to 360 (hue rotation in degrees) */
2021-03-18 01:16:40 +01:00
hue: number,
2021-04-13 17:05:52 +02:00
/** Image negative */
2021-03-18 01:16:40 +01:00
negative: boolean,
2021-04-13 17:05:52 +02:00
/** Image sepia colors */
2021-03-18 01:16:40 +01:00
sepia: boolean,
2021-04-13 17:05:52 +02:00
/** Image vintage colors */
2021-03-18 01:16:40 +01:00
vintage: boolean,
2021-04-13 17:05:52 +02:00
/** Image kodachrome colors */
2021-03-18 01:16:40 +01:00
kodachrome: boolean,
2021-04-13 17:05:52 +02:00
/** Image technicolor colors */
2021-03-18 01:16:40 +01:00
technicolor: boolean,
2021-04-13 17:05:52 +02:00
/** Image polaroid camera effect */
2021-03-18 01:16:40 +01:00
polaroid: boolean,
2021-04-13 17:05:52 +02:00
/** Range: 0 (no pixelate) to N (number of pixels to pixelate) */
2021-03-18 01:16:40 +01:00
pixelate: number,
2021-03-17 23:23:19 +01:00
},
2021-04-19 22:02:47 +02:00
// type definition end
2021-04-13 17:05:52 +02:00
/** Controlls gesture detection */
2021-03-17 23:23:19 +01:00
gesture: {
2021-03-18 01:16:40 +01:00
enabled: boolean,
2021-03-17 23:23:19 +01:00
},
2021-04-13 17:05:52 +02:00
/** Controlls and configures all face-specific options:
* - face detection, face mesh detection, age, gender, emotion detection and face description
* Parameters:
* - enabled: true/false
* - modelPath: path for individual face model
* - rotation: use calculated rotated face image or just box with rotation as-is, false means higher performance, but incorrect mesh mapping on higher face angles
* - maxFaces: maximum number of faces detected in the input, should be set to the minimum number for performance
* - skipFrames: how many frames to go without re-running the face detector and just run modified face mesh analysis, only valid if videoOptimized is set to true
* - skipInitial: if previous detection resulted in no faces detected, should skipFrames be reset immediately to force new detection cycle
* - minConfidence: threshold for discarding a prediction
* - iouThreshold: threshold for deciding whether boxes overlap too much in non-maximum suppression
* - scoreThreshold: threshold for deciding when to remove boxes based on score in non-maximum suppression
* - return extracted face as tensor for futher user processing
*/
2021-03-17 23:23:19 +01:00
face: {
2021-03-18 01:16:40 +01:00
enabled: boolean,
2021-03-17 23:23:19 +01:00
detector: {
2021-03-18 01:16:40 +01:00
modelPath: string,
rotation: boolean,
maxFaces: number,
skipFrames: number,
skipInitial: boolean,
minConfidence: number,
iouThreshold: number,
scoreThreshold: number,
return: boolean,
2021-03-17 23:23:19 +01:00
},
mesh: {
2021-03-18 01:16:40 +01:00
enabled: boolean,
modelPath: string,
2021-03-17 23:23:19 +01:00
},
iris: {
2021-03-18 01:16:40 +01:00
enabled: boolean,
modelPath: string,
2021-03-17 23:23:19 +01:00
},
2021-03-21 19:18:51 +01:00
description: {
enabled: boolean,
modelPath: string,
skipFrames: number,
2021-03-18 01:16:40 +01:00
minConfidence: number,
2021-03-17 23:23:19 +01:00
},
emotion: {
2021-03-18 01:16:40 +01:00
enabled: boolean,
minConfidence: number,
skipFrames: number,
modelPath: string,
2021-03-17 23:23:19 +01:00
},
},
2021-04-13 17:05:52 +02:00
/** Controlls and configures all body detection specific options
* - enabled: true/false
* - modelPath: paths for both hand detector model and hand skeleton model
* - maxDetections: maximum number of people detected in the input, should be set to the minimum number for performance
* - scoreThreshold: threshold for deciding when to remove people based on score in non-maximum suppression
* - nmsRadius: threshold for deciding whether body parts overlap too much in non-maximum suppression
*/
2021-03-17 23:23:19 +01:00
body: {
2021-03-18 01:16:40 +01:00
enabled: boolean,
modelPath: string,
maxDetections: number,
scoreThreshold: number,
nmsRadius: number,
2021-03-17 23:23:19 +01:00
},
2021-04-13 17:05:52 +02:00
/** Controlls and configures all hand detection specific options
* - enabled: true/false
* - modelPath: paths for both hand detector model and hand skeleton model
* - rotation: use best-guess rotated hand image or just box with rotation as-is, false means higher performance, but incorrect finger mapping if hand is inverted
* - skipFrames: how many frames to go without re-running the hand bounding box detector and just run modified hand skeleton detector, only valid if videoOptimized is set to true
* - skipInitial: if previous detection resulted in no hands detected, should skipFrames be reset immediately to force new detection cycle
* - minConfidence: threshold for discarding a prediction
* - iouThreshold: threshold for deciding whether boxes overlap too much in non-maximum suppression
* - scoreThreshold: threshold for deciding when to remove boxes based on score in non-maximum suppression
* - maxHands: maximum number of hands detected in the input, should be set to the minimum number for performance
* - landmarks: detect hand landmarks or just hand boundary box
*/
2021-03-17 23:23:19 +01:00
hand: {
2021-03-18 01:16:40 +01:00
enabled: boolean,
rotation: boolean,
skipFrames: number,
skipInitial: boolean,
minConfidence: number,
iouThreshold: number,
scoreThreshold: number,
maxHands: number,
landmarks: boolean,
2021-03-17 23:23:19 +01:00
detector: {
2021-03-18 01:16:40 +01:00
modelPath: string,
2021-03-17 23:23:19 +01:00
},
skeleton: {
2021-03-18 01:16:40 +01:00
modelPath: string,
2021-03-17 23:23:19 +01:00
},
},
2021-04-13 17:05:52 +02:00
/** Controlls and configures all object detection specific options
* - minConfidence: minimum score that detection must have to return as valid object
* - iouThreshold: ammount of overlap between two detected objects before one object is removed
* - maxResults: maximum number of detections to return
* - skipFrames: run object detection every n input frames, only valid if videoOptimized is set to true
*/
2021-03-17 23:23:19 +01:00
object: {
2021-03-18 01:16:40 +01:00
enabled: boolean,
modelPath: string,
minConfidence: number,
iouThreshold: number,
maxResults: number,
skipFrames: number,
2021-03-17 23:23:19 +01:00
},
}
const config: Config = {
2020-10-16 21:04:51 +02:00
backend: 'webgl', // select tfjs backend to use
2021-03-02 17:27:42 +01:00
// can be 'webgl', 'wasm', 'cpu', or 'humangl' which is a custom version of webgl
// leave as empty string to continue using default backend
// when backend is set outside of Human library
2021-04-09 14:07:58 +02:00
modelBasePath: '../models/', // base path for all models
2020-12-13 00:34:30 +01:00
wasmPath: '../assets/', // path for wasm binaries
2020-11-10 02:13:38 +01:00
// only used for backend: wasm
2021-03-02 17:27:42 +01:00
debug: true, // print additional status messages to console
2020-11-06 17:39:39 +01:00
async: true, // execute enabled models in parallel
2020-11-08 18:26:45 +01:00
// this disables per-model performance data but
// slightly increases performance
// cannot be used if profiling is enabled
2021-04-13 17:05:52 +02:00
profile: false, // internal: enable tfjs profiling
2020-11-08 18:26:45 +01:00
// this has significant performance impact
// only enable for debugging purposes
2020-11-01 19:07:53 +01:00
// currently only implemented for age,gender,emotion models
2021-04-13 17:05:52 +02:00
deallocate: false, // internal: aggresively deallocate gpu memory after each usage
// only valid for webgl and humangl backend and only during first call
2020-11-08 18:26:45 +01:00
// cannot be changed unless library is reloaded
// this has significant performance impact
// only enable on low-memory devices
2021-04-13 17:05:52 +02:00
scoped: false, // internal: enable scoped runs
2020-11-08 18:26:45 +01:00
// some models *may* have memory leaks,
// this wrapps everything in a local scope at a cost of performance
// typically not needed
2020-11-08 18:26:45 +01:00
videoOptimized: true, // perform additional optimizations when input is video,
// must be disabled for images
2021-04-12 23:48:59 +02:00
// automatically disabled for Image, ImageData, ImageBitmap and Tensor inputs
// skips boundary detection for every n frames
2020-11-01 19:10:22 +01:00
// while maintaining in-box detection since objects cannot move that fast
2020-12-13 00:34:30 +01:00
warmup: 'face', // what to use for human.warmup(), can be 'none', 'face', 'full'
2020-12-11 16:11:49 +01:00
// warmup pre-initializes all models for faster inference but can take
// significant time on startup
2021-04-13 17:05:52 +02:00
// only used for `webgl` and `humangl` backends
filter: { // run input through image filters before inference
// image filters run with near-zero latency as they are executed on the GPU
2020-10-18 18:12:09 +02:00
enabled: true, // enable image pre-processing filters
2020-10-27 15:06:01 +01:00
width: 0, // resize input width
height: 0, // resize input height
// 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-04-19 22:02:47 +02:00
flip: false, // flip input as mirror image
2020-10-18 18:12:09 +02:00
return: true, // return processed canvas imagedata in result
brightness: 0, // range: -1 (darken) to 1 (lighten)
contrast: 0, // range: -1 (reduce contrast) to 1 (increase contrast)
sharpness: 0, // range: 0 (no sharpening) to 1 (maximum sharpening)
blur: 0, // range: 0 (no blur) to N (blur radius in pixels)
saturation: 0, // range: -1 (reduce saturation) to 1 (increase saturation)
hue: 0, // range: 0 (no change) to 360 (hue rotation in degrees)
negative: false, // image negative
sepia: false, // image sepia colors
vintage: false, // image vintage colors
kodachrome: false, // image kodachrome colors
technicolor: false, // image technicolor colors
polaroid: false, // image polaroid camera effect
pixelate: 0, // range: 0 (no pixelate) to N (number of pixels to pixelate)
},
2020-11-08 18:26:45 +01:00
2020-11-04 16:18:22 +01:00
gesture: {
enabled: true, // enable simple gesture recognition
},
2020-11-08 18:26:45 +01:00
2020-10-12 01:22:43 +02:00
face: {
2020-10-16 21:04:51 +02:00
enabled: true, // controls if specified modul is enabled
2020-11-08 18:26:45 +01:00
// face.enabled is required for all face models:
// detector, mesh, iris, age, gender, emotion
2020-10-16 21:04:51 +02:00
// (note: module is not loaded until it is required)
2020-10-12 01:22:43 +02:00
detector: {
2021-04-09 14:07:58 +02:00
modelPath: 'blazeface-back.json', // detector model
// can be either absolute path or relative to modelBasePath
2021-03-12 04:04:44 +01:00
rotation: false, // use best-guess rotated face image or just box with rotation as-is
2020-12-10 20:47:53 +01:00
// false means higher performance, but incorrect mesh mapping if face angle is above 20 degrees
2021-03-10 00:32:35 +01:00
// this parameter is not valid in nodejs
2020-11-08 18:26:45 +01:00
maxFaces: 10, // maximum number of faces detected in the input
// should be set to the minimum number for performance
skipFrames: 21, // how many frames to go without re-running the face bounding box detector
2020-11-08 18:26:45 +01:00
// only used for video inputs
// e.g., if model is running st 25 FPS, we can re-use existing bounding
// box for updated face analysis as the head probably hasn't moved much
// in short time (10 * 1/25 = 0.25 sec)
2021-03-01 23:20:02 +01:00
skipInitial: false, // if previous detection resulted in no faces detected,
2021-04-13 17:05:52 +02:00
// should skipFrames be reset immediately to force new detection cycle
minConfidence: 0.2, // threshold for discarding a prediction
2021-03-03 15:59:04 +01:00
iouThreshold: 0.1, // threshold for deciding whether boxes overlap too much in
2020-11-08 18:26:45 +01:00
// non-maximum suppression (0.1 means drop if overlap 10%)
scoreThreshold: 0.2, // threshold for deciding when to remove boxes based on score
2020-11-08 18:26:45 +01:00
// in non-maximum suppression,
// this is applied on detection objects only and before minConfidence
2021-03-12 04:04:44 +01:00
return: false, // return extracted face as tensor
2020-10-12 01:22:43 +02:00
},
2020-11-08 18:26:45 +01:00
2020-10-12 01:22:43 +02:00
mesh: {
enabled: true,
2021-04-09 14:07:58 +02:00
modelPath: 'facemesh.json', // facemesh model
// can be either absolute path or relative to modelBasePath
2020-10-12 01:22:43 +02:00
},
2020-11-08 18:26:45 +01:00
2020-10-12 01:22:43 +02:00
iris: {
enabled: true,
2021-04-09 14:07:58 +02:00
modelPath: 'iris.json', // face iris model
// can be either absolute path or relative to modelBasePath
2020-10-12 01:22:43 +02:00
},
2020-11-08 18:26:45 +01:00
2021-03-21 19:18:51 +01:00
description: {
2021-03-24 16:08:49 +01:00
enabled: true, // to improve accuracy of face description extraction it is
2021-03-21 19:18:51 +01:00
// recommended to enable detector.rotation and mesh.enabled
2021-04-09 14:07:58 +02:00
modelPath: 'faceres.json', // face description model
// can be either absolute path or relative to modelBasePath
2021-03-21 19:18:51 +01:00
skipFrames: 31, // how many frames to go without re-running the detector
// only used for video inputs
2021-04-25 00:43:59 +02:00
minConfidence: 0.1, // threshold for discarding a prediction
2021-03-21 19:18:51 +01:00
},
emotion: {
2020-10-12 01:22:43 +02:00
enabled: true,
2021-03-21 19:18:51 +01:00
minConfidence: 0.1, // threshold for discarding a prediction
2021-03-23 19:46:44 +01:00
skipFrames: 32, // how many frames to go without re-running the detector
2021-04-09 14:07:58 +02:00
modelPath: 'emotion.json', // face emotion model
// can be either absolute path or relative to modelBasePath
2021-03-21 19:18:51 +01:00
},
2020-10-12 01:22:43 +02:00
},
2020-11-08 18:26:45 +01:00
2020-10-12 01:22:43 +02:00
body: {
enabled: true,
2021-04-09 14:07:58 +02:00
modelPath: 'posenet.json', // body model
// can be either absolute path or relative to modelBasePath
// can be 'posenet', 'blazepose' or 'efficientpose'
2021-03-29 20:40:34 +02:00
// 'blazepose' and 'efficientpose' are experimental
2021-04-24 17:49:26 +02:00
maxDetections: 1, // maximum number of people detected in the input
2020-11-08 18:26:45 +01:00
// should be set to the minimum number for performance
2021-03-04 16:33:08 +01:00
// only valid for posenet as blazepose only detects single pose
2021-04-24 22:04:49 +02:00
scoreThreshold: 0.2, // threshold for deciding when to remove boxes based on score
2020-11-08 18:26:45 +01:00
// in non-maximum suppression
2021-03-04 16:33:08 +01:00
// only valid for posenet as blazepose only detects single pose
2020-10-16 21:04:51 +02:00
nmsRadius: 20, // radius for deciding points are too close in non-maximum suppression
2021-03-04 16:33:08 +01:00
// only valid for posenet as blazepose only detects single pose
2020-10-12 01:22:43 +02:00
},
2020-11-08 18:26:45 +01:00
2020-10-12 01:22:43 +02:00
hand: {
enabled: true,
2020-12-10 21:46:45 +01:00
rotation: false, // use best-guess rotated hand image or just box with rotation as-is
// false means higher performance, but incorrect finger mapping if hand is inverted
2020-12-11 16:11:49 +01:00
skipFrames: 12, // how many frames to go without re-running the hand bounding box detector
2020-11-08 18:26:45 +01:00
// only used for video inputs
// e.g., if model is running st 25 FPS, we can re-use existing bounding
// box for updated hand skeleton analysis as the hand probably
// hasn't moved much in short time (10 * 1/25 = 0.25 sec)
2021-04-13 17:05:52 +02:00
skipInitial: false, // if previous detection resulted in no hands detected,
// should skipFrames be reset immediately to force new detection cycle
2020-12-10 20:47:53 +01:00
minConfidence: 0.1, // threshold for discarding a prediction
2020-11-08 18:26:45 +01:00
iouThreshold: 0.1, // threshold for deciding whether boxes overlap too much
// in non-maximum suppression
2020-12-10 20:47:53 +01:00
scoreThreshold: 0.5, // threshold for deciding when to remove boxes based on
2020-11-08 18:26:45 +01:00
// score in non-maximum suppression
maxHands: 1, // maximum number of hands detected in the input
// should be set to the minimum number for performance
2020-11-08 15:56:02 +01:00
landmarks: true, // detect hand landmarks or just hand boundary box
2020-10-12 01:22:43 +02:00
detector: {
2021-04-09 14:07:58 +02:00
modelPath: 'handdetect.json', // hand detector model
// can be either absolute path or relative to modelBasePath
2020-10-12 01:22:43 +02:00
},
skeleton: {
2021-04-09 14:07:58 +02:00
modelPath: 'handskeleton.json', // hand skeleton model
// can be either absolute path or relative to modelBasePath
2020-10-12 01:22:43 +02:00
},
},
object: {
enabled: false,
2021-04-09 14:07:58 +02:00
modelPath: 'nanodet.json', // object detection model
// can be either absolute path or relative to modelBasePath
2021-03-29 20:40:34 +02:00
// 'nanodet' is experimental
2021-03-23 19:46:44 +01:00
minConfidence: 0.20, // threshold for discarding a prediction
iouThreshold: 0.40, // threshold for deciding whether boxes overlap too much
// in non-maximum suppression
maxResults: 10, // maximum number of objects detected in the input
2021-03-23 19:46:44 +01:00
skipFrames: 41, // how many frames to go without re-running the detector
},
2020-10-12 01:22:43 +02:00
};
2021-03-17 23:23:19 +01:00
export { config as defaults };