From 17a8e20a535d706efe76c5c6e631f8188a9d9f49 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Wed, 11 Nov 2020 22:40:05 -0500 Subject: [PATCH] fix for conditional model loading --- demo/browser.js | 1 + src/gender/gender.js | 2 +- src/human.js | 12 ++++++------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/demo/browser.js b/demo/browser.js index eec18f52..d6b4ceff 100644 --- a/demo/browser.js +++ b/demo/browser.js @@ -387,6 +387,7 @@ async function main() { log('Human: demo starting ...'); setupMenu(); document.getElementById('log').innerText = `Human: version ${human.version} TensorFlow/JS: version ${human.tf.version_core}`; + human.tf.ENV.set('WEBGL_FORCE_F16_TEXTURES', true); // this is not required, just pre-loads all models if (ui.modelsPreload) { status('loading'); diff --git a/src/gender/gender.js b/src/gender/gender.js index a0677585..7afc7f30 100644 --- a/src/gender/gender.js +++ b/src/gender/gender.js @@ -77,7 +77,7 @@ async function predict(image, config) { const confidence = Math.trunc(200 * Math.abs((data[0] - 0.5))) / 100; if (confidence > config.face.gender.minConfidence) { obj.gender = data[0] <= 0.5 ? 'female' : 'male'; - obj.confidence = confidence; + obj.confidence = Math.min(0.99, confidence); } } } diff --git a/src/human.js b/src/human.js index 7d78a356..2d32a664 100644 --- a/src/human.js +++ b/src/human.js @@ -123,27 +123,27 @@ class Human { } if (this.config.async) { [ + this.models.facemesh, this.models.age, this.models.gender, this.models.emotion, - this.models.facemesh, this.models.posenet, this.models.handpose, ] = await Promise.all([ - this.models.age || (this.config.face.age.enabled ? age.load(this.config) : null), - this.models.gender || (this.config.face.gender.enabled ? gender.load(this.config) : null), - this.models.emotion || (this.config.face.emotion.enabled ? emotion.load(this.config) : null), this.models.facemesh || (this.config.face.enabled ? facemesh.load(this.config.face) : null), + this.models.age || ((this.config.face.enabled && this.config.face.age.enabled) ? age.load(this.config) : null), + this.models.gender || ((this.config.face.enabled && this.config.face.gender.enabled) ? gender.load(this.config) : null), + this.models.emotion || ((this.config.face.enabled && this.config.face.emotion.enabled) ? emotion.load(this.config) : null), this.models.posenet || (this.config.body.enabled ? posenet.load(this.config) : null), this.models.handpose || (this.config.hand.enabled ? handpose.load(this.config.hand) : null), ]); } else { if (this.config.face.enabled && !this.models.facemesh) this.models.facemesh = await facemesh.load(this.config.face); - if (this.config.body.enabled && !this.models.posenet) this.models.posenet = await posenet.load(this.config); - if (this.config.hand.enabled && !this.models.handpose) this.models.handpose = await handpose.load(this.config.hand); if (this.config.face.enabled && this.config.face.age.enabled && !this.models.age) this.models.age = await age.load(this.config); if (this.config.face.enabled && this.config.face.gender.enabled && !this.models.gender) this.models.gender = await gender.load(this.config); if (this.config.face.enabled && this.config.face.emotion.enabled && !this.models.emotion) this.models.emotion = await emotion.load(this.config); + if (this.config.body.enabled && !this.models.posenet) this.models.posenet = await posenet.load(this.config); + if (this.config.hand.enabled && !this.models.handpose) this.models.handpose = await handpose.load(this.config.hand); } const current = Math.trunc(now() - timeStamp); if (current > (this.perf.load || 0)) this.perf.load = current;