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.16k stars 308 forks source link

Cant run nodejs demo from commandline - browser is always true #403

Closed augchan42 closed 7 months ago

augchan42 commented 7 months ago

I've tried setting browser: false in the Human config, but that's not an option. I've specified backend as tensorflow which should restrict to mean there's no browser and to use nodejs backend, but that didn't get picked up either.

Issue Description (.env) hosermage@hosermage-x1:~/projects/human$ node demo/nodejs/node.js 2023-12-06 14:52:23.144305: I tensorflow/core/util/util.cc:169] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0. 2023-12-06 14:52:23.190094: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 AVX_VNNI FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2023-12-06 14:52:23 INFO: @vladmandic/human version 3.1.2 2023-12-06 14:52:23 INFO: User: hosermage Platform: linux Arch: x64 Node: v21.3.0 2023-12-06 14:52:23 INFO: Current folder: /home/hosermage/projects/human 14:52:23.271 Human: version: 3.1.2 14:52:23.272 Human: tfjs version: 4.14.0 14:52:23.272 Human: environment: { browser: true, node: true, platform: '', agent: '', backends: [], tfjs: { version: '4.14.0' }, offscreen: false, tensorflow: {}, wasm: {}, webgl: {}, webgpu: {}, cpu: { flags: [] } } 2023-12-06 14:52:23 INFO: human: 3.1.2 tf: 4.14.0 2023-12-06 14:52:23 INFO: Human: 3.1.2 14:52:23.279 Human: available backends: [ 'cpu', 'tensorflow' ] 14:52:23.280 Human: setting backend: [ 'tensorflow' ]

/home/hosermage/projects/human/src/image/image.ts:52 throw new Error('canvas error: attempted to run in browser but DOM is not defined'); ^ Error: canvas error: attempted to run in browser but DOM is not defined at canvas (/home/hosermage/projects/human/src/image/image.ts:52:15) at E2.updateBackend (/home/hosermage/projects/human/src/util/env.ts:142:21) at I2 (/home/hosermage/projects/human/src/tfjs/backend.ts:221:15) at processTicksAndRejections (node:internal/process/task_queues:95:5) at w1.load (/home/hosermage/projects/human/src/human.ts:292:12) at init (/home/hosermage/projects/human/demo/nodejs/node.js:52:3) at main (/home/hosermage/projects/human/demo/nodejs/node.js:192:3)

augchan42 commented 7 months ago

Ok, it turns out the Navigator {} object is merely empty, and not undefined. I'll change the logic in env.ts to account for this.

vladmandic commented 7 months ago

i've merged your pr as-is, but i'd be curious which environment sets navigator object to empty?

augchan42 commented 7 months ago

Thanks. Here's the beginning portion of a run after my fix (otherwise it doesn't work)

(.env) hosermage@hosermage-x1:~/project-forks/human$ node demo/nodejs/node.js ~/photos/
2023-12-06 18:56:57.450623: I tensorflow/core/util/util.cc:169] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2023-12-06 18:56:57.468043: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 AVX_VNNI FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-12-06 18:56:57 INFO:  @vladmandic/human version 3.1.2
2023-12-06 18:56:57 INFO:  User: hosermage Platform: linux Arch: x64 Node: v21.3.0
2023-12-06 18:56:57 INFO:  Current folder: /home/hosermage/project-forks/human
18:56:57.505 Human: version: 3.1.2
18:56:57.505 Human: tfjs version: 4.14.0
18:56:57.505 Human: environment: {
  browser: false,
  node: true,
  platform: '',
  agent: '',
  backends: [],
  tfjs: { version: '4.14.0' },
  offscreen: false,
  tensorflow: {},
  wasm: {},
  webgl: {},
  webgpu: {},
  cpu: { flags: [] }
}
2023-12-06 18:56:57 INFO:  human: 3.1.2 tf: 4.14.0
2023-12-06 18:56:57 INFO:  Human: 3.1.2
18:56:57.508 Human: available backends: [ 'cpu', 'tensorflow' ]
18:56:57.508 Human: setting backend: [ 'tensorflow' ]
18:56:57.510 Human: registered kernels: [ 'floormod' ]
18:56:57.534 Human: load: {
  model: 'blazeface',
  url: 'file://models/blazeface.json',
  bytes: 538928
}
18:56:57.536 Human: load: { model: 'emotion', url: 'file://models/emotion.json', bytes: 820516 }
18:56:57.545 Human: load: {
  model: 'facemesh',
  url: 'file://models/facemesh.json',
  bytes: 1477958
}
18:56:57.551 Human: load: {
  model: 'handlandmark-lite',
  url: 'file://models/handlandmark-lite.json',
  bytes: 2023432
}
18:56:57.555 Human: load: { model: 'iris', url: 'file://models/iris.json', bytes: 2599092 }
18:56:57.586 Human: load: {
  model: 'handtrack',
  url: 'file://models/handtrack.json',
  bytes: 2964837
}
18:56:57.606 Human: load: {
  model: 'centernet',
  url: 'file://models/centernet.json',
  bytes: 4030290
}
18:56:57.623 Human: load: {
  model: 'movenet-lightning',
  url: 'file://models/movenet-lightning.json',
  bytes: 4650216
}
18:56:57.642 Human: load: { model: 'faceres', url: 'file://models/faceres.json', bytes: 6978814 }
18:56:57.643 Human: tf engine state: 54132296 bytes 1751 tensors
2023-12-06 18:56:57 INFO:  Loaded: [ 'blazeface', 'emotion', 'facemesh', 'handskeleton', 'iris', 'handtrack', 'centernet', 'movenet', 'faceres' ]
2023-12-06 18:56:57 DATA:  2.9.1
vladmandic commented 7 months ago

perhaps its new in node v21, i'll check.

augchan42 commented 7 months ago

yes according to chatgpt4 navigator should be undefined, but I added log statements to show that it was set to an empty Navigator object right from the first reference in env.ts

vladmandic commented 7 months ago

it should be undefined and i still don't know why its empty, but additional check you've added doesn't hurt so no issues including it.