From cfeac24fc2e507e1bf6c6cc79525d5ab0d200391 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Tue, 31 Aug 2021 13:00:06 -0400 Subject: [PATCH] dynamically generate default wasm path --- CHANGELOG.md | 3 ++- README.md | 2 +- demo/facematch/facematch.js | 2 +- demo/index.js | 4 +++- package.json | 38 ++++++++++++++++++------------------- src/config.ts | 3 ++- src/human.ts | 10 +++++++--- test/test-node-wasm.js | 2 +- wiki | 2 +- 9 files changed, 37 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83130ca4..36ee42c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,9 @@ Repository: **** ## Changelog -### **HEAD -> main** 2021/08/20 mandic00@live.com +### **HEAD -> main** 2021/08/23 mandic00@live.com +- implement finger poses in hand detection and gestures - implemented movenet-multipose model ### **2.1.4** 2021/08/19 mandic00@live.com diff --git a/README.md b/README.md index b6a26d2d..12ee8cfd 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ Simply load `Human` (*IIFE version*) directly from a cloud CDN in your HTML file ```html - + ``` For details, including how to use `Browser ESM` version or `NodeJS` version of `Human`, see [**Installation**](https://github.com/vladmandic/human/wiki/Install) diff --git a/demo/facematch/facematch.js b/demo/facematch/facematch.js index 4345a809..91cc721f 100644 --- a/demo/facematch/facematch.js +++ b/demo/facematch/facematch.js @@ -14,7 +14,7 @@ const userConfig = { warmup: 'none', debug: true, modelBasePath: '../../models/', - wasmPath: 'https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.8.0/dist/', + // wasmPath: 'https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.9.0/dist/', face: { enabled: true, detector: { rotation: true, return: true }, diff --git a/demo/index.js b/demo/index.js index fb316c97..81811206 100644 --- a/demo/index.js +++ b/demo/index.js @@ -32,8 +32,8 @@ let human; let userConfig = { warmup: 'none', backend: 'humangl', - wasmPath: 'https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.8.0/dist/', /* + wasmPath: 'https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.9.0/dist/', async: false, cacheSensitivity: 0, filter: { @@ -947,6 +947,8 @@ async function main() { // create instance of human human = new Human(userConfig); + log('human version:', Human.version); + log('tfjs version:', human.tf.version.tfjs); userConfig = { ...human.config, ...userConfig }; if (typeof tf !== 'undefined') { // eslint-disable-next-line no-undef diff --git a/package.json b/package.json index beed9998..a181a8a5 100644 --- a/package.json +++ b/package.json @@ -55,37 +55,37 @@ "tensorflow" ], "devDependencies": { - "@tensorflow/tfjs": "^3.8.0", - "@tensorflow/tfjs-backend-cpu": "^3.8.0", - "@tensorflow/tfjs-backend-wasm": "^3.8.0", - "@tensorflow/tfjs-backend-webgl": "^3.8.0", + "@tensorflow/tfjs": "^3.9.0", + "@tensorflow/tfjs-backend-cpu": "^3.9.0", + "@tensorflow/tfjs-backend-wasm": "^3.9.0", + "@tensorflow/tfjs-backend-webgl": "^3.9.0", "@tensorflow/tfjs-backend-webgpu": "^0.0.1-alpha.7", - "@tensorflow/tfjs-converter": "^3.8.0", - "@tensorflow/tfjs-core": "^3.8.0", - "@tensorflow/tfjs-data": "^3.8.0", - "@tensorflow/tfjs-layers": "^3.8.0", - "@tensorflow/tfjs-node": "^3.8.0", - "@tensorflow/tfjs-node-gpu": "^3.8.0", - "@types/node": "^16.7.1", - "@typescript-eslint/eslint-plugin": "^4.29.2", - "@typescript-eslint/parser": "^4.29.2", + "@tensorflow/tfjs-converter": "^3.9.0", + "@tensorflow/tfjs-core": "^3.9.0", + "@tensorflow/tfjs-data": "^3.9.0", + "@tensorflow/tfjs-layers": "^3.9.0", + "@tensorflow/tfjs-node": "^3.9.0", + "@tensorflow/tfjs-node-gpu": "^3.9.0", + "@types/node": "^16.7.8", + "@typescript-eslint/eslint-plugin": "^4.30.0", + "@typescript-eslint/parser": "^4.30.0", "@vladmandic/pilogger": "^0.2.18", "canvas": "^2.8.0", "chokidar": "^3.5.2", "dayjs": "^1.10.6", - "esbuild": "^0.12.22", + "esbuild": "^0.12.24", "eslint": "^7.32.0", "eslint-config-airbnb-base": "^14.2.1", - "eslint-plugin-import": "^2.24.1", + "eslint-plugin-import": "^2.24.2", "eslint-plugin-json": "^3.1.0", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^5.1.0", - "node-fetch": "^2.6.1", + "node-fetch": "^3.0.0", "rimraf": "^3.0.2", "seedrandom": "^3.0.5", - "simple-git": "^2.44.0", + "simple-git": "^2.45.0", "tslib": "^2.3.1", - "typedoc": "0.21.6", - "typescript": "4.3.5" + "typedoc": "0.21.9", + "typescript": "4.4.2" } } diff --git a/src/config.ts b/src/config.ts index 8ba712e0..2e05c167 100644 --- a/src/config.ts +++ b/src/config.ts @@ -216,7 +216,8 @@ const config: Config = { backend: 'webgl', // select tfjs backend to use, leave empty to use default backend // can be 'webgl', 'wasm', 'cpu', or 'humangl' which is a custom version of webgl modelBasePath: '../models/', // base path for all models - wasmPath: '../node_modules/@tensorflow/tfjs-backend-wasm/dist/', // path for wasm binaries, only used for backend: wasm + wasmPath: '', // path for wasm binaries, only used for backend: wasm + // default set to download from jsdeliv during Human class instantiation debug: true, // print additional status messages to console async: true, // execute enabled models in parallel warmup: 'full', // what to use for human.warmup(), can be 'none', 'face', 'full' diff --git a/src/human.ts b/src/human.ts index f00f936c..cb72a7e5 100644 --- a/src/human.ts +++ b/src/human.ts @@ -62,7 +62,7 @@ export type TensorFlow = typeof tf; */ export class Human { /** Current version of Human library in *semver* format */ - version: string; + static version: string; /** Current configuration * - Details: {@link Config} */ @@ -148,10 +148,12 @@ export class Human { * @param userConfig: {@link Config} */ constructor(userConfig?: Config | Record) { + Human.version = app.version; + Object.defineProperty(this, 'version', { value: app.version }); + defaults.wasmPath = `https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${tf.version_core}/dist/`; this.config = mergeDeep(defaults, userConfig || {}); this.tf = tf; this.draw = draw; - this.version = app.version; this.state = 'idle'; this.#numTensors = 0; this.#analyzeMemoryLeaks = false; @@ -188,6 +190,8 @@ export class Human { this.#lastInputSum = 1; } + // version = () => Human.version; + // helper function: measure tensor leak /** @hidden */ analyze = (...msg: string[]) => { @@ -268,7 +272,7 @@ export class Human { if (userConfig) this.config = mergeDeep(this.config, userConfig) as Config; if (this.#firstRun) { // print version info on first run and check for correct backend setup - if (this.config.debug) log(`version: ${this.version}`); + if (this.config.debug) log(`version: ${Human.version}`); if (this.config.debug) log(`tfjs version: ${this.tf.version_core}`); if (this.config.debug) log('platform:', this.sysinfo.platform); if (this.config.debug) log('agent:', this.sysinfo.agent); diff --git a/test/test-node-wasm.js b/test/test-node-wasm.js index 14bf3567..80920b6b 100644 --- a/test/test-node-wasm.js +++ b/test/test-node-wasm.js @@ -5,7 +5,7 @@ const config = { modelBasePath: 'http://localhost:10030/models/', backend: 'wasm', wasmPath: 'node_modules/@tensorflow/tfjs-backend-wasm/dist/', - // wasmPath: 'https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.6.0/dist/', + // wasmPath: 'https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.9.0/dist/', debug: false, async: false, face: { diff --git a/wiki b/wiki index e894eff5..fcc3945d 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit e894eff5aee6aeca6a7690c5a3d6a0f7404d7f2c +Subproject commit fcc3945dedd5682f06c45c32504a86a1a7e2a20b