add debug logging flag

pull/280/head
Vladimir Mandic 2021-03-02 11:27:42 -05:00
parent 28d00d997f
commit 7969623849
8 changed files with 34 additions and 28 deletions

View File

@ -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

View File

@ -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",

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}

2
wiki

@ -1 +1 @@
Subproject commit c283c4a21d26dc0ba03e576dae8e6fbd3af12ac8
Subproject commit 4091054e6d325ad8e9787c4b3d93b0e4ebb9016c