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 load WASM files from a CDN such as https://www.jsdelivr.com/package/npm/@tensorflow/tfjs-backend-wasm?path=dist

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