From dc5e46adde1d31bf5a53fb1b8fc5c55950ae1ca2 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Thu, 21 Oct 2021 10:54:51 -0400 Subject: [PATCH] fix for human.draw labels and typedefs --- CHANGELOG.md | 3 ++- demo/index.js | 1 + src/face/face.ts | 20 ++++++++++---------- src/human.ts | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80fd473b..9ffe3250 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,9 @@ ## Changelog -### **HEAD -> main** 2021/10/19 mandic00@live.com +### **HEAD -> main** 2021/10/21 mandic00@live.com +- add human.custom.esm using custom tfjs build ### **2.3.5** 2021/10/19 mandic00@live.com diff --git a/demo/index.js b/demo/index.js index 5a7b125c..49b684c7 100644 --- a/demo/index.js +++ b/demo/index.js @@ -63,6 +63,7 @@ const drawOptions = { drawBoxes: true, drawGaze: true, drawLabels: true, + drawGestures: true, drawPolygons: true, drawPoints: false, fillPolygons: false, diff --git a/src/face/face.ts b/src/face/face.ts index ed91b016..add1b255 100644 --- a/src/face/face.ts +++ b/src/face/face.ts @@ -48,11 +48,11 @@ export const detectFace = async (parent /* instance of human */, input: Tensor): // run emotion, inherits face from blazeface parent.analyze('Start Emotion:'); if (parent.config.async) { - emotionRes = parent.config.face.emotion.enabled ? emotion.predict(faces[i].tensor || tf.tensor([]), parent.config, i, faces.length) : {}; + emotionRes = parent.config.face.emotion.enabled ? emotion.predict(faces[i].tensor || tf.tensor([]), parent.config, i, faces.length) : null; } else { parent.state = 'run:emotion'; timeStamp = now(); - emotionRes = parent.config.face.emotion.enabled ? await emotion.predict(faces[i].tensor || tf.tensor([]), parent.config, i, faces.length) : {}; + emotionRes = parent.config.face.emotion.enabled ? await emotion.predict(faces[i].tensor || tf.tensor([]), parent.config, i, faces.length) : null; parent.performance.emotion = Math.trunc(now() - timeStamp); } parent.analyze('End Emotion:'); @@ -60,11 +60,11 @@ export const detectFace = async (parent /* instance of human */, input: Tensor): // run antispoof, inherits face from blazeface parent.analyze('Start AntiSpoof:'); if (parent.config.async) { - antispoofRes = parent.config.face.antispoof.enabled ? antispoof.predict(faces[i].tensor || tf.tensor([]), parent.config, i, faces.length) : {}; + antispoofRes = parent.config.face.antispoof.enabled ? antispoof.predict(faces[i].tensor || tf.tensor([]), parent.config, i, faces.length) : null; } else { parent.state = 'run:antispoof'; timeStamp = now(); - antispoofRes = parent.config.face.antispoof.enabled ? await antispoof.predict(faces[i].tensor || tf.tensor([]), parent.config, i, faces.length) : {}; + antispoofRes = parent.config.face.antispoof.enabled ? await antispoof.predict(faces[i].tensor || tf.tensor([]), parent.config, i, faces.length) : null; parent.performance.antispoof = Math.trunc(now() - timeStamp); } parent.analyze('End AntiSpoof:'); @@ -86,11 +86,11 @@ export const detectFace = async (parent /* instance of human */, input: Tensor): // run emotion, inherits face from blazeface parent.analyze('Start Description:'); if (parent.config.async) { - descRes = parent.config.face.description.enabled ? faceres.predict(faces[i].tensor || tf.tensor([]), parent.config, i, faces.length) : []; + descRes = parent.config.face.description.enabled ? faceres.predict(faces[i].tensor || tf.tensor([]), parent.config, i, faces.length) : null; } else { parent.state = 'run:description'; timeStamp = now(); - descRes = parent.config.face.description.enabled ? await faceres.predict(faces[i].tensor || tf.tensor([]), parent.config, i, faces.length) : []; + descRes = parent.config.face.description.enabled ? await faceres.predict(faces[i].tensor || tf.tensor([]), parent.config, i, faces.length) : null; parent.performance.embedding = Math.trunc(now() - timeStamp); } parent.analyze('End Description:'); @@ -124,10 +124,10 @@ export const detectFace = async (parent /* instance of human */, input: Tensor): faceRes.push({ ...faces[i], id: i, - age: descRes.age, - gender: descRes.gender, - genderScore: descRes.genderScore, - embedding: descRes.descriptor, + age: descRes?.age, + gender: descRes?.gender, + genderScore: descRes?.genderScore, + embedding: descRes?.descriptor, emotion: emotionRes, real: antispoofRes, iris: irisSize !== 0 ? Math.trunc(500 / irisSize / 11.7) / 100 : 0, diff --git a/src/human.ts b/src/human.ts index 197a4aef..4854d47b 100644 --- a/src/human.ts +++ b/src/human.ts @@ -135,7 +135,7 @@ export class Human { * - canvas: draw processed canvas which is a processed copy of the input * - all: meta-function that performs: canvas, face, body, hand */ - draw: { canvas, face, body, hand, gesture, object, person, all, options: DrawOptions }; + draw: { canvas: typeof draw.canvas, face: typeof draw.face, body: typeof draw.body, hand: typeof draw.hand, gesture: typeof draw.gesture, object: typeof draw.object, person: typeof draw.person, all: typeof draw.all, options: DrawOptions }; /** Currently loaded models * @internal