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.38k stars 325 forks source link

having issue using tenserflow version below 1.6.0 #258

Closed AshishAvesta closed 2 years ago

AshishAvesta commented 2 years ago

Not bug just a question for help. I am using the face comparison feature in my electron app. If I use the TensorFlow version above 1.6.0, which uses AVX instruction which may not run on older CPUs. Can this library work without tfjs-node or we can use the tfjs-node version lower than 1.6.0?

Environment Human library version: 2.4.1 NodeJS and version : 14.17.6 OS : Window10 Electron version : 12.0.18

Below is my configuration for Human.

humanConfig: { async: true, warmup: 'face', backend: 'webgl', modelBasePath: process.env.NODE_ENV === 'development' ? modelPath : ${app.getAppPath()}${modelPath}, filter: { enabled: true, flip: true } }

Got error while using tfjs-node version: 1.4.0

image

vladmandic commented 2 years ago

Since your intention is to run in a client app, lets eliminate tfjs-node completely and not talk about version requirements.

Human can run in browser (for client side deployments) and in node (for server-side deployments). The issue with ElectronJS is that its both, so depending HOW you load Human, it will detect it runs in node and attempt to use tfjs-node. If you load Human correctly so that it detects browser instead of node, you should have no issues.

But...I'm not an ElectronJS expert - its been on my list to do a quick how-to for Electron for a while now, just haven't gotten to it just yet. So you'll need to go through Electron's docs to see how that is done for some other libraries?

However, I don't think this issue is limited to Electron - it happens with any platform that includes server-side rendering, for example NextJS. You can take a look at quick prototype https://github.com/vladmandic/human-next - there human is lazy-loaded in the client so it skips any server-side steps and is available in browser only - something like that should also work for 'ElectronJS`

Related code is in https://github.com/vladmandic/human-next/blob/main/components/RunHuman.tsx, you can see that it statically imports types only (so type checks are still available), but library itself is loaded via dynamic import during component load which happens in browser.

Now, if there is any issues with platform detection in Human, I'd be happy to look at it and if necessary patch it.

AshishAvesta commented 2 years ago

Started working on it as you suggest. Tried to load human as you did in human-next but get an error human_error

Did same as you did in RunHuman.tsx

vladmandic commented 2 years ago

you can see from the backtrace that electron is still trying to use nodejs (cjs loader is for node only).
need to find a way to tell electron not to do that and that import is browser-only.
but like i said, i don't use electron (it is on my todo list, but havent done it yet).

vladmandic commented 2 years ago

any updates?

AshishAvesta commented 2 years ago

Sorry, I'm coming into this so late. I follow your browser example: https://github.com/vladmandic/human/tree/main/demo/typescript So I just copy human.esm.js to my render code (frontend code that is Reactjs) and load Human from that.

Is this the correct way?

vladmandic commented 2 years ago

just created a quick demo app using human and electronjs, follow that template. https://github.com/vladmandic/human-electron