vladmandic / human

Human: AI-powered 3D Face Detection & Rotation Tracking, Face Description & Recognition, Body Pose Tracking, 3D Hand & Finger Tracking, Iris Analysis, Age & Gender & Emotion Prediction, Gaze Tracking, Gesture Recognition
https://vladmandic.github.io/human/demo/index.html
MIT License
2.37k stars 323 forks source link

Face detect issue, detects same result #96

Closed okeoke85 closed 3 years ago

okeoke85 commented 3 years ago

Result is always same

When i tried the detection detection result is always same as first one, when i detect 'baseImage' image first result is same as 'image' result and vice versa,

  let baseImageDetection: any = await HumanInstance.detect(baseImage);
  let imageDetection: any = await HumanInstance.detect(image);

I tried to make second detection with another instance, i thought maybe smthing is not garbage collected in 'HumanInstance', but i got this error :

human.esm.js:4166 Uncaught (in promise) TypeError: Cannot read property 'getBoundingBoxes' of null at Z2.predict (human.esm.js:4166) at J2.estimateFaces (human.esm.js:4166) at H2 (human.esm.js:4166) at human.esm.js:4892

Thanks in advance.

vladmandic commented 3 years ago

When i tried the detection detection result is always same as first one, when i detect 'baseImage' image first result is same as 'image' result and vice versa,

You probably missing videoOptimized: false in your config
Since most users use Human to detect video input, default is to run with video optimizations which causes some values to be cached between frames for performance reasons (which can be tuned for each model using config skipFrames property).

What is the type of your baseImage? I can try to add auto-detect to automatically disable video optimizations on static image inputs.

I tried to make second detection with another instance, i thought maybe smthing is not garbage collected in 'HumanInstance', but i got this error

Interesting. Tests don't try with multiple instances, but I'll check it manually. Although there is no reason to have multiple instances, I'd still like to make it work - I'll mark this as bug for now.

vladmandic commented 3 years ago

i've added check and if input is HTMLImageElement, ImageData, ImageBitmap or Tensor
then videoOptimization will be auto-disabled

For HTMLVideoElement, HMTLMediaElement, HTMLCanvasElement or OffscreenCanvas
it will stay as user-provided configuration
(cannot disable for Canvas as its often used to snapshot state of a running video)

also, i've fixed running multiple instances of Human, issue was that even for multiple instances
Human attempts to cache already loaded models to avoid unnecessary loading twice,
but order was not preserved
(of course, configuration can be different between instances),

2021-04-12 08:15:32 INFO:  testing instance#1
2021-04-12 08:15:32 STATE:  passed: create human
2021-04-12 08:15:32 INFO:  human version: 1.4.1
2021-04-12 08:15:32 INFO:  tfjs version: 3.3.0
2021-04-12 08:15:32 INFO:  platform: linux x64
2021-04-12 08:15:32 INFO:  agent: NodeJS v15.7.0
08:15:32.421 Human: version: 1.4.1
08:15:32.422 Human: tfjs version: 3.3.0
08:15:32.422 Human: platform: linux x64
08:15:32.422 Human: agent: NodeJS v15.7.0
08:15:32.422 Human: setting backend: tensorflow
08:15:32.467 Human: load model: file://models/blazeface-back.json
08:15:32.515 Human: load model: file://models/facemesh.json
08:15:32.516 Human: load model: file://models/iris.json
08:15:32.526 Human: load model: file://models/emotion.json
08:15:32.620 Human: load model: file://models/handdetect.json
08:15:32.620 Human: load model: file://models/handskeleton.json
08:15:32.709 Human: load model: file://models/posenet.json
08:15:32.818 Human: load model: file://models/nanodet.json
08:15:32.890 Human: load model: file://models/faceres.json
08:15:32.890 Human: tf engine state: 61838340 bytes 1164 tensors
2021-04-12 08:15:32 STATE:  passed: load models
2021-04-12 08:15:32 DATA:   result: defined models: 12 loaded models: 6
2021-04-12 08:15:34 STATE:  passed: warmup: face
2021-04-12 08:15:34 DATA:   result: face: 1 body: 0 hand: 0 gesture: 2 object: 1
2021-04-12 08:15:34 DATA:   result: performance: load: 470 total: 1272
2021-04-12 08:15:35 STATE:  passed: detect: random
2021-04-12 08:15:35 DATA:   result: face: 0 body: 0 hand: 0 gesture: 0 object: 0
2021-04-12 08:15:35 DATA:   result: performance: load: 470 total: 767

2021-04-12 08:15:35 INFO:  testing instance#2
2021-04-12 08:15:35 STATE:  passed: create human
2021-04-12 08:15:35 INFO:  human version: 1.4.1
2021-04-12 08:15:35 INFO:  tfjs version: 3.3.0
2021-04-12 08:15:35 INFO:  platform: linux x64
2021-04-12 08:15:35 INFO:  agent: NodeJS v15.7.0
08:15:35.127 Human: version: 1.4.1
08:15:35.127 Human: tfjs version: 3.3.0
08:15:35.127 Human: platform: linux x64
08:15:35.127 Human: agent: NodeJS v15.7.0
08:15:35.127 Human: setting backend: tensorflow
08:15:35.127 Human: cached model: file://models/blazeface-back.json
08:15:35.127 Human: cached model: file://models/facemesh.json
08:15:35.127 Human: cached model: file://models/iris.json
08:15:35.127 Human: cached model: file://models/emotion.json
08:15:35.127 Human: cached model: file://models/handdetect.json
08:15:35.127 Human: cached model: file://models/handskeleton.json
08:15:35.132 Human: cached model: file://models/posenet.json
08:15:35.132 Human: cached model: file://models/nanodet.json
08:15:35.132 Human: cached model: file://models/faceres.json
08:15:35.133 Human: tf engine state: 61861908 bytes 1167 tensors
2021-04-12 08:15:35 STATE:  passed: load models
2021-04-12 08:15:35 DATA:   result: defined models: 12 loaded models: 6
2021-04-12 08:15:36 STATE:  passed: warmup: body
2021-04-12 08:15:36 DATA:   result: face: 1 body: 1 hand: 0 gesture: 2 object: 3
2021-04-12 08:15:36 DATA:   result: performance: load: 6 total: 1272
2021-04-12 08:15:37 STATE:  passed: detect: random
2021-04-12 08:15:37 DATA:   result: face: 0 body: 0 hand: 0 gesture: 0 object: 0
2021-04-12 08:15:37 DATA:   result: performance: load: 6 total: 816

new version will be published later today

okeoke85 commented 3 years ago

Hi Vlad,

Thank you for your fast responses, baseImage and Image is HTMLImageElement, when i used the config as videoOptimized: false i can get some results indeed thank you for new version i can use type in relief, but about the results i opened other issue. lets close this one if u wish