Skip to content

Install

Vladimir Mandic edited this page Nov 7, 2020 · 24 revisions

Installation

Important
The packaged (IIFE and ESM) version of Human includes TensorFlow/JS (TFJS) 2.7.0 library which can be accessed via human.tf
You should NOT manually load another instance of tfjs, but if you do, be aware of possible version conflicts

There are multiple ways to use Human library, pick one that suits you:

Included

  • dist/human.js: IIFE format bundle with TFJS for Browsers
  • dist/human.esm.js: ESM format bundle with TFJS for Browsers
  • dist/human.esm-nobundle.js: ESM format bundle without TFJS for Browsers
  • dist/human.node.js: CommonJS format bundle with TFJS for NodeJS
  • dist/human.node-nobundle.js: CommonJS format bundle without TFJS for NodeJS

All versions include sourcemap (.map) and build manifest (.json)
While Human is in pre-release mode, all bundles are non-minified

Defaults:

  {
    "main": "dist/human.node.js",
    "module": "dist/human.esm.js",
    "browser": "dist/human.esm.js",
  }

1. IIFE script

Simplest way for usage within Browser

Simply download dist/human.js, include it in your HTML file & it's ready to use.

  <script src="dist/human.js"><script>

IIFE script auto-registers global namespace Human within global Window object
Which you can use to create instance of human library:

  const human = new Human();

This way you can also use Human library within embbedded <script> tag within your html page for all-in-one approach

2. ESM module

Recommended for usage within Browser

2.1 Using Script Module

You could use same syntax within your main JS file if it's imported with <script type="module">

  <script src="./index.js" type="module">

and then in your index.js

  import Human from 'dist/human.esm.js'; // for direct import must use path to module, not package name
  const human = new Human();

2.2 With Bundler

If you're using bundler (such as rollup, webpack, parcel, browserify, esbuild) to package your client application,
you can import ESM version of Human library which supports full tree shaking

Install with:

  npm install @vladmandic/human
  import Human from '@vladmandic/human'; // points to @vladmandic/human/dist/human.esm.js
                                         // you can also force-load specific version
                                         // for example: `@vladmandic/human/dist/human.esm-nobundle.js`
  const human = new Human();

Or if you prefer to package your version of tfjs, you can use nobundle version

Install with:

  npm install @vladmandic/human @tensorflow/tfjs-node
  import tf from '@tensorflow/tfjs'
  import Human from '@vladmandic/human/dist/human.esm-nobundle.js'; // same functionality as default import, but without tfjs bundled
  const human = new Human();

3. NPM module

Recommended for NodeJS projects that will execute in the backend

Entry point is bundle in CommonJS format dist/human.node.js
You also need to install and include tfjs-node or tfjs-node-gpu in your project so it can register an optimized backend

Install with:

  npm install @vladmandic/human @tensorflow/tfjs-node

And then use with:

  const tf = require('@tensorflow/tfjs-node'); // can also use '@tensorflow/tfjs-node-gpu' if you have environment with CUDA extensions
  const Human = require('@vladmandic/human').default; // points to @vladmandic/human/dist/human.node.js
  const human = new Human();

Since NodeJS projects load weights from local filesystem instead of using http calls, you must modify default configuration to include correct paths with file:// prefix

For example:

const config = {
  body: { enabled: true, modelPath: 'file://models/posenet/model.json' },
}

Weights

Pretrained model weights are includes in ./models
Default configuration uses relative paths to you entry script pointing to ../models
If your application resides in a different folder, modify modelPath property in configuration of each module


Clone this wiki locally