Skip to content
Vladimir Mandic edited this page Apr 3, 2023 · 29 revisions

Usage

Human library does not require special initialization
All configuration is done in a single JSON object and all model weights are dynamically loaded upon their first usage
(and only then, Human will not load weights that it doesn't need according to configuration).

Full API Specification


Basics

There is only ONE method you need:

  const human = new Human(config?)                    // create instance of human
  const result = await human.detect(input, config?)   // run single detection

or

  const human = new Human(config?)                    // create instance of human
  await human.video(input, config?)                   // run detection loop on input video
                                                      // last known results are available in human.results

Notes:

Standard workflow:

  1. Select best detected engine
  2. Use default configuration
  3. Load & compile required models
  4. Perform warmup operations
  5. Preprocess input
  6. Perform detection

Human Methods

Main

Methods exported by Human library:

  human.detect(input, config?);   // run processing on single image/frame
  human.video(input, config?);    // run processing continously on video
  human.next(result?);            // returns time-variant smoothened/interpolated result based on last known result

Additional

Methods used for face recognition and face matching:
For details, see embedding documentation

human.match.similarity(descriptor1, descriptor2); // runs similarity calculation between two provided embedding vectors
// vectors for source and target must be previously detected using
// face.description module
human.match.find(descriptor, descriptors);        // finds best match for current face in a provided list of faces

Methods used for body segmentation, background removal or background replacement
For details, see segmentation documentation

  human.segmentation(input, config?)   // runs body segmentation and returns processed image tensor 
                                       // which can be foreground-only, alpha-only or blended image

Helpers

Additiona helper namespaces that can be used to reduce amount of manual code that needs to be written, but do not have to be used
For details, see:

  human.webcam.*    // helper methods to control webcam, main properties are `start`, `stop`, `play`, `pause`
  human.draw.*      // helper methods to draw detected results to canvas, main options are `options`, `canvas`, `all`

Implicit

Methods that are typically called as part of standard workflow and do not need to be called manually

  human.validate(config?);        // validate human configuration
  human.init(config?);            // initialize human and processing backend
  human.load(config?);            // load configured models
  human.warmup(config?);          // warms up human library for faster initial execution after loading
  human.image(input);             // process input without detection and returns canvas or tensor
  human.models.*                  // namespace that serves current library ml models
                                  // main options are `load`, `list`, `loaded`, `reset`, `stats`, `validate`

Utility methods that are typically not directly used except in advanced or troubleshooting cases

human.analyze();                // check for memory leaks
human.compare();                // compare two images for pixel similarity
human.now();                    // utility wrapper for performance timestamp
human.profile();                // run function via profiler
human.reset();                  // reset configuration
human.sleep();                  // utility wrapper for sleep function
human.emit();                   // internal event emitter

Human Properties

Human library exposes several dynamically generated properties:

human.version;       // string containing version of human library
human.config;        // access to current configuration object
// normally set during call to constructor or as parameter to detect()
human.result;        // access to last known result object, normally returned via call to detect()
human.performance;   // access to current performance counters
human.state;         // <string> describing current operation in progress
// progresses through: 'config', 'check', 'backend', 'load', 'run:<model>', 'idle'
human.models;        // dynamically maintained list of loaded models
human.env;           // detected platform environment and capabilities
human.events;        // container for events dispateched by human
Human.defaults;      // static property of Human class that contains default configuration

TensorFlow

Human internally uses TensorFlow/JS for all ML processing
Access to namespace of an interal instance of tfjs used by human is possible via:

human.tf;                                              // instance of tfjs used by human, can be embedded or externally loaded

Results Caching and Smoothing

  • By default, Human uses frame change detection for results caching
  • For on-screen display best results, it is recommended to use results smoothing

For details, see <https://github.com/vladmandic/human/wiki/Caching

Demos

Human library comes with number of browser-based and nodejs-based demo apps in /demo folder
For details, see https://github.com/vladmandic/human/wiki/Demos

Clone this wiki locally