From 4d05c4f604e12598cc5703212bd902863dfd65bb Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Tue, 2 Mar 2021 11:27:42 -0500 Subject: [PATCH] add debug logging flag --- config.js | 4 ++++ package.json | 8 ++++---- src/age/age.ts | 2 +- src/emotion/emotion.ts | 2 +- src/gender/gender.ts | 2 +- src/handpose/handpose.ts | 4 ++-- src/human.ts | 38 ++++++++++++++++++++------------------ wiki | 2 +- 8 files changed, 34 insertions(+), 28 deletions(-) diff --git a/config.js b/config.js index 181e9d74..f2c13afe 100644 --- a/config.js +++ b/config.js @@ -3,8 +3,12 @@ export default { backend: 'webgl', // select tfjs backend to use + // can be 'webgl', 'wasm', 'cpu', or 'humangl' which is a custom version of webgl + // leave as empty string to continue using default backend + // when backend is set outside of Human library wasmPath: '../assets/', // path for wasm binaries // only used for backend: wasm + debug: true, // print additional status messages to console async: true, // execute enabled models in parallel // this disables per-model performance data but // slightly increases performance diff --git a/package.json b/package.json index 750e5723..e277fdf9 100644 --- a/package.json +++ b/package.json @@ -34,12 +34,12 @@ "@tensorflow/tfjs-node": "^3.2.0", "@tensorflow/tfjs-node-gpu": "^3.2.0", "@types/node": "^14.14.31", - "@typescript-eslint/eslint-plugin": "^4.15.2", - "@typescript-eslint/parser": "^4.15.2", + "@typescript-eslint/eslint-plugin": "^4.16.1", + "@typescript-eslint/parser": "^4.16.1", "@vladmandic/pilogger": "^0.2.14", "chokidar": "^3.5.1", "dayjs": "^1.10.4", - "esbuild": "^0.8.53", + "esbuild": "^0.8.54", "eslint": "^7.21.0", "eslint-config-airbnb-base": "^14.2.1", "eslint-plugin-import": "^2.22.1", @@ -50,7 +50,7 @@ "seedrandom": "^3.0.5", "simple-git": "^2.35.2", "tslib": "^2.1.0", - "typescript": "^4.3.0-dev.20210228" + "typescript": "^4.3.0-dev.20210302" }, "scripts": { "start": "node --trace-warnings --unhandled-rejections=strict --trace-uncaught --no-deprecation src/node.js", diff --git a/src/age/age.ts b/src/age/age.ts index f3da1f43..b869e197 100644 --- a/src/age/age.ts +++ b/src/age/age.ts @@ -9,7 +9,7 @@ let skipped = Number.MAX_SAFE_INTEGER; export async function load(config) { if (!model) { model = await tf.loadGraphModel(config.face.age.modelPath); - log(`load model: ${config.face.age.modelPath.match(/\/(.*)\./)[1]}`); + if (config.debug) log(`load model: ${config.face.age.modelPath.match(/\/(.*)\./)[1]}`); } return model; } diff --git a/src/emotion/emotion.ts b/src/emotion/emotion.ts index eb6b5115..60a188ad 100644 --- a/src/emotion/emotion.ts +++ b/src/emotion/emotion.ts @@ -14,7 +14,7 @@ const scale = 1; // score multiplication factor export async function load(config) { if (!model) { model = await tf.loadGraphModel(config.face.emotion.modelPath); - log(`load model: ${config.face.emotion.modelPath.match(/\/(.*)\./)[1]}`); + if (config.debug) log(`load model: ${config.face.emotion.modelPath.match(/\/(.*)\./)[1]}`); } return model; } diff --git a/src/gender/gender.ts b/src/gender/gender.ts index d829804e..dee1e638 100644 --- a/src/gender/gender.ts +++ b/src/gender/gender.ts @@ -14,7 +14,7 @@ export async function load(config) { if (!model) { model = await tf.loadGraphModel(config.face.gender.modelPath); alternative = model.inputs[0].shape[3] === 1; - log(`load model: ${config.face.gender.modelPath.match(/\/(.*)\./)[1]}`); + if (config.debug) log(`load model: ${config.face.gender.modelPath.match(/\/(.*)\./)[1]}`); } return model; } diff --git a/src/handpose/handpose.ts b/src/handpose/handpose.ts index 3f7a475b..4595798d 100644 --- a/src/handpose/handpose.ts +++ b/src/handpose/handpose.ts @@ -57,7 +57,7 @@ export async function load(config) { const handDetector = new handdetector.HandDetector(handDetectorModel, config.hand.inputSize, anchors.anchors); const handPipeline = new handpipeline.HandPipeline(handDetector, handPoseModel, config.hand.inputSize); const handPose = new HandPose(handPipeline); - if (config.hand.enabled) log(`load model: ${config.hand.detector.modelPath.match(/\/(.*)\./)[1]}`); - if (config.hand.landmarks) log(`load model: ${config.hand.skeleton.modelPath.match(/\/(.*)\./)[1]}`); + if (config.hand.enabled && config.debug) log(`load model: ${config.hand.detector.modelPath.match(/\/(.*)\./)[1]}`); + if (config.hand.landmarks && config.debug) log(`load model: ${config.hand.skeleton.modelPath.match(/\/(.*)\./)[1]}`); return handPose; } diff --git a/src/human.ts b/src/human.ts index ed5706d9..ce30d0e4 100644 --- a/src/human.ts +++ b/src/human.ts @@ -131,11 +131,11 @@ class Human { if (userConfig) this.config = mergeDeep(this.config, userConfig); if (this.firstRun) { - log(`version: ${this.version} TensorFlow/JS version: ${this.tf.version_core}`); + if (this.config.debug) log(`version: ${this.version} TensorFlow/JS version: ${this.tf.version_core}`); await this.checkBackend(true); if (this.tf.ENV.flags.IS_BROWSER) { - log('configuration:', this.config); - log('tf flags:', this.tf.ENV.flags); + if (this.config.debug) log('configuration:', this.config); + if (this.config.debug) log('tf flags:', this.tf.ENV.flags); } } const face = this.config.face.detector.modelPath.includes('faceboxes') ? faceboxes : facemesh; @@ -168,7 +168,7 @@ class Human { } if (this.firstRun) { - log('tf engine state:', this.tf.engine().state.numBytes, 'bytes', this.tf.engine().state.numTensors, 'tensors'); + if (this.config.debug) log('tf engine state:', this.tf.engine().state.numBytes, 'bytes', this.tf.engine().state.numTensors, 'tensors'); this.firstRun = false; } @@ -191,20 +191,22 @@ class Human { } */ - log('setting backend:', this.config.backend); + if (this.config.backend && this.config.backend !== '') { + if (this.config.debug) log('setting backend:', this.config.backend); - if (this.config.backend === 'wasm') { - log('settings wasm path:', this.config.wasmPath); - this.tf.setWasmPaths(this.config.wasmPath); - const simd = await this.tf.env().getAsync('WASM_HAS_SIMD_SUPPORT'); - if (!simd) log('warning: wasm simd support is not enabled'); - } + if (this.config.backend === 'wasm') { + if (this.config.debug) log('settings wasm path:', this.config.wasmPath); + this.tf.setWasmPaths(this.config.wasmPath); + const simd = await this.tf.env().getAsync('WASM_HAS_SIMD_SUPPORT'); + if (!simd) log('warning: wasm simd support is not enabled'); + } - if (this.config.backend === 'humangl') backend.register(); - try { - await this.tf.setBackend(this.config.backend); - } catch (err) { - log('error: cannot set backend:', this.config.backend, err); + if (this.config.backend === 'humangl') backend.register(); + try { + await this.tf.setBackend(this.config.backend); + } catch (err) { + log('error: cannot set backend:', this.config.backend, err); + } } this.tf.enableProdMode(); /* debug mode is really too mcuh @@ -218,7 +220,7 @@ class Human { // this.tf.ENV.set('WEBGL_FORCE_F16_TEXTURES', true); // this.tf.ENV.set('WEBGL_PACK_DEPTHWISECONV', true); const gl = await this.tf.backend().getGPGPUContext().gl; - log(`gl version:${gl.getParameter(gl.VERSION)} renderer:${gl.getParameter(gl.RENDERER)}`); + if (this.config.debug) log(`gl version:${gl.getParameter(gl.VERSION)} renderer:${gl.getParameter(gl.RENDERER)}`); } await this.tf.ready(); this.perf.backend = Math.trunc(now() - timeStamp); @@ -528,7 +530,7 @@ class Human { else res = await this.warmupNode(); this.config.videoOptimized = video; const t1 = now(); - log('Warmup', this.config.warmup, Math.round(t1 - t0), 'ms', res); + if (this.config.debug) log('Warmup', this.config.warmup, Math.round(t1 - t0), 'ms', res); return res; } } diff --git a/wiki b/wiki index c283c4a2..4091054e 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit c283c4a21d26dc0ba03e576dae8e6fbd3af12ac8 +Subproject commit 4091054e6d325ad8e9787c4b3d93b0e4ebb9016c