Skip to content

Backends

Vladimir Mandic edited this page Jul 29, 2021 · 12 revisions

Backends

Human library includes pre-bundled CPU, WASM and WebGL backends, there is no need to load them externally.


WebGL Backend

WebGL backend usage is fastest on systems with modern GPU
although startup speed is a bit slower

CPU Backend

CPU backend usage is not recommended for performance reasons
as TensorFlow implementation in JavaScript is by far the slowest

WASM Backend

WASM backend has good resuts under specific conditions:

  • Enable WASM SIMD support in your browser
    (CPU parallel processing instructions)
  • Reduce size of input image (e.g. webcam)
    as WASM does not have optimized image extraction methods

Loading WASM Files

WASM backend requires access to wasm files which are part of @tensorflow/tfjs-backend-wasm package and included in
node_modules/@tensorflow/tfjs-backend-wasm/dist/*.wasm (different WASM file is loaded depending on detected capabilities)

Also, to be able to load WASM files your web server, web server has to set appropriate HTTP headers:

Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

Or configure Human load WASM files directly from a CDN:

wasmPath: 'https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.8.0/dist/'

Note that version of WASM binaries must match version of TFJS used by Human library


How to enable WASM SIMD support

Chrome:

  • Navigate to chrome://flags
  • WebAssembly SIMD support set to Enabled

Edge:

  • Navigate to chrome://flags
  • WebAssembly SIMD support set to Enabled

Firefox:

  • Navigate to about:config
  • javascript.options.wasm_simd set to True

Known Issues

See <TODO.md>


Clone this wiki locally