justadudewhohacks / face-api.js

JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js
MIT License
16.7k stars 3.71k forks source link

Slow in nodejs project #312

Closed galinkyuchukov closed 5 years ago

galinkyuchukov commented 5 years ago

Hello!

I am trying to setup simple face detection in nodejs env. Out of the box everything run fine with the exception of speed. It takes 12+ seconds for a single face detection.

require('@tensorflow/tfjs-node')

is included!

On execution i see:

cpu backend was already registered. Reusing existing backend

then

Hi there šŸ‘‹. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.

When i install older versions of the two packages:

npm install @tensorflow/tfjs-node@0.3.0 face-api.js@0.14.3

there is significant speed improvement, BUT i need age and gender detection , which is not present below face-api.js < 0.20.0

I also tryed: @tensorflow/tfjs-node version 1.0.2

but then i get:

(node:29723) UnhandledPromiseRejectionWarning: TypeError: tfc.ENV.findBackend is not a function at nodeBackend (/home/pi/testproject/node_modules/@tensorflow/tfjs- node/dist/ops/op_utils.js:25:28)

How can i use age and gender recognition and get faster speed under nodejs?

Environment Raspberry Pi Node: v8.10.0 face-api.js: 0.20.0 / 0.14.3 @tensorflow/tfjs-node: 1.1.2 / 1.0.2 / 0.3.0

justadudewhohacks commented 5 years ago

@tensorflow/tfjs-node 1.0.2 + @tensorflow/tfjs-core 1.0.3 should work with face-api.js 0.20.0. This is the setup that the nodejs examples use. The error message you posted might indicate, that you are not using tfjs-core 1.0.3.

singhania1408 commented 5 years ago

Hi @justadudewhohacks, I am also facing the same issue. I have run the face-api.js on browser for facial expression and landmark detection, which was comparatively very fast, but in nodejs, it was damn too slow, (i.e approx 1 frame in 5-6sec). Please help me out how I can do to fix this issue.

justadudewhohacks commented 5 years ago

As I answered above, make sure the package versions line up correctly.

billdai998 commented 5 years ago

I also had the problem of agreeing and spent about 17 seconds in nodejs. Please see if my reference package is correct. image

galinkyuchukov commented 5 years ago

Thank you for the help @justadudewhohacks! More than 10 times faster when

@tensorflow/tfjs-node 1.0.2 + @tensorflow/tfjs-core 1.0.3

ramesh586 commented 5 years ago

I'm getting following error, please help to resolve

cpu backend was already registered. Reusing existing backend factory. Platform node has already been set. Overwriting the platform with [object Object]. node-pre-gyp info This Node instance does not support builds for N-API version 4 node-pre-gyp info This Node instance does not support builds for N-API version 4 module.js:549 throw err; ^

Error: Cannot find module 'D:\bench_work_space\GCH\face-expressions\face-expressions\facetest\node_modules\@tensorflow\tfjs-node\lib\napi-v3\tfjs_binding.node' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object. (D:\bench_work_space\GCH\face-expressions\face-expressions\facetest\node_modules\@tensorflow\tfjs-node\dist\index.js:44:16) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3)

0x6c23 commented 5 years ago

I'm getting following error, please help to resolve

cpu backend was already registered. Reusing existing backend factory. Platform node has already been set. Overwriting the platform with [object Object]. node-pre-gyp info This Node instance does not support builds for N-API version 4 node-pre-gyp info This Node instance does not support builds for N-API version 4 module.js:549 throw err; ^

Error: Cannot find module 'D:\bench_work_space\GCH\face-expressions\face-expressions\facetest\node_modules@tensorflow\tfjs-node\lib\napi-v3\tfjs_binding.node' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object. (D:\bench_work_space\GCH\face-expressions\face-expressions\facetest\node_modules@tensorflow\tfjs-node\dist\index.js:44:16) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3)

Same issue here. Impossible to include @tensorflow. It installs without errors. Tried many versions. Still not able to include.

bamwani commented 4 years ago

@0x6c23 Did you find any solution for this error?