face-api.js icon indicating copy to clipboard operation
face-api.js copied to clipboard

node-js examples not compiling

Open kerloom opened this issue 5 years ago • 20 comments

To try and run the examples I do the following with a freshly cloned repo:

cd examples/examples-nodejs
npm i
tsc faceDetection.ts

I get the following error:

node_modules/@types/webgl2/index.d.ts:582:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'WebGL2RenderingContext' must be of type '{ new (): WebGL2RenderingContext; prototype: WebGL2RenderingContext; readonly ACTIVE_ATTRIBUTES: number; readonly ACTIVE_TEXTURE: number; ... 556 more ...; readonly WAIT_FAILED: number; }', but here has type '{ new (): WebGL2RenderingContext; prototype: WebGL2RenderingContext; readonly ACTIVE_ATTRIBUTES: number; readonly ACTIVE_TEXTURE: number; ... 557 more ...; readonly MAX_CLIENT_WAIT_TIMEOUT_WEBGL: number; }'.

582 declare var WebGL2RenderingContext: {
                ~~~~~~~~~~~~~~~~~~~~~~

  ../../../../../../usr/lib/node_modules/typescript/lib/lib.dom.d.ts:16485:13
    16485 declare var WebGL2RenderingContext: {
                      ~~~~~~~~~~~~~~~~~~~~~~
    'WebGL2RenderingContext' was also declared here.


Found 1 error.

I have the following: tsc --version: 3.7.2 node --version: 12.13.0

I have tried adding skipLibCheck: true to tsconfig.json but it did not do any difference.

Do you have any idea why it is not working for node?

kerloom avatar Dec 02 '19 23:12 kerloom

This command compile. tsc --skipLibCheck faceDetection.ts But then it doesn't work

error:

UnhandledPromiseRejectionWarning: TypeError: this.backend.register is not a function
    at Engine.registerTensor (/home/ff/nodejs/face-api.js/node_modules/@tensorflow/tfjs-core/dist/engine.js:468:30)

FerX avatar Dec 04 '19 14:12 FerX

Please check out @russellwmy's answer in this issue #376. Make sure you are using the same typescript (take a look at the package.json of the examples folder) and tfjs-core version as face-api.js.

justadudewhohacks avatar Dec 06 '19 09:12 justadudewhohacks

same error, I tried #376, seems different errors. not work. I just used the default package.json. tsc --version Version 3.7.3 node --version v12.13.1

tsc --skipLibCheck faceDetection.ts there is no error. but when I run node faceDetection.js (node:25928) UnhandledPromiseRejectionWarning: TypeError: this.backend.register is not a function at Engine.registerTensor (E:\face\face-api.js\node_modules@tensorflow\tfjs-core\dist\engine.js:468:30) at new Tensor (E:\face\face-api.js\node_modules@tensorflow\tfjs-core\dist\tensor.js:246:21) at Function.Tensor.make (E:\face\face-api.js\node_modules@tensorflow\tfjs-core\dist\tensor.js:261:16) at makeTensor (E:\face\face-api.js\node_modules@tensorflow\tfjs-core\dist\ops\tensor_ops.js:98:28) at Object.tensor (E:\face\face-api.js\node_modules@tensorflow\tfjs-core\dist\ops\tensor_ops.js:55:12) at _loop_2 (E:\face\face-api.js\node_modules@tensorflow\tfjs-core\dist\io\io_utils.js:219:36) at Object.decodeWeights (E:\face\face-api.js\node_modules@tensorflow\tfjs-core\dist\io\io_utils.js:223:9) at E:\face\face-api.js\node_modules@tensorflow\tfjs-core\dist\io\weights_loader.js:255:66 at Array.forEach () at E:\face\face-api.js\node_modules@tensorflow\tfjs-core\dist\io\weights_loader.js:253:44 (node:25928) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:25928) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

willfu avatar Dec 10 '19 05:12 willfu

got the reason. it seems the "npm i" in examples will get the tfjs 1.4.0 version, which is not compatible with face-api.js.

willfu avatar Dec 10 '19 10:12 willfu

Thanks! Just to make this clear for anyone else, you can fix by removng the caret (^) in the package.json for @tensorflow/tfjs-node and getting version 1.2.3 specifically. For example in the examples folder changing package.json to:

{
  "author": "justadudewhohacks",
  "license": "MIT",
  "dependencies": {
    "@tensorflow/tfjs-node": "1.2.3",
    "canvas": "^2.5.0",
    "face-api.js": "../../"
  }
}

kerloom avatar Dec 13 '19 15:12 kerloom

just cloned the repository, with tsc --version: 3.7.3 node --version: v13.3.0

cd face-api.js/examples/examples-nodejs
npm i
ts-node  faceDetection.ts

gives:

faceDetection.ts:1:26 - error TS2307: Cannot find module 'face-api.js'.

1 import * as faceapi from 'face-api.js';

sbocconi avatar Dec 18 '19 15:12 sbocconi

Same scenario, and same results as @sbocconi.

node --version: 12.4.0 tsc --version: 3.7.4

imgh1010 avatar Dec 24 '19 20:12 imgh1010

@sbocconi @imgh1010 What version of tfjs-node are you using? Did you change the version in package.json before installing with npm install as per my previous comment?

kerloom avatar Dec 26 '19 19:12 kerloom

My package.json is as currently available in the repository:

{
  "author": "justadudewhohacks",
  "license": "MIT",
  "dependencies": {
    "@tensorflow/tfjs-node": "1.4.0",
    "canvas": "^2.6.0",
    "face-api.js": "../../"
  }
}

and the error does not depend on the version of tensorflow, but on the fact that face-api.js cannot be found. I also tried with:

{
  "author": "justadudewhohacks",
  "license": "MIT",
  "dependencies": {
    "@tensorflow/tfjs-node": "1.4.0",
    "canvas": "^2.6.0",
    "face-api.js": "git+https://github.com/justadudewhohacks/face-api.js.git#master"
  }
}

but I get the same error, even after a npm install face-api.js

sbocconi avatar Dec 30 '19 11:12 sbocconi

The solution was to first run

npm i && npm run-script build

in the root directory before trying to run the examples.

sbocconi avatar Dec 30 '19 15:12 sbocconi

however,I found : examples/examples-nodejs/package.json { "author": "justadudewhohacks", "license": "MIT", "dependencies": { "face-api.js": "../../" # this will happen circulate create } } will circulate create face-api.js fold, is usually or not? @justadudewhohacks

homedawn avatar Apr 22 '20 07:04 homedawn

when I do "npm i" in console.

homedawn avatar Apr 22 '20 07:04 homedawn

The solution was to first run

npm i && npm run-script build

in the root directory before trying to run the examples.

when I do “npm i && npm run-script build”,and I get:

@tensorflow/[email protected] install /home/dzy/Project/face-api.js/node_modules/@tensorflow/tfjs-node node scripts/install.js

CPU-linux-1.7.0.tar.gz

  • Downloading libtensorflow [==============================] 15944787/bps 100% 0.0s
  • Building TensorFlow Node.js bindings

[email protected] install /home/dzy/Project/face-api.js/node_modules/canvas node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using needle for node-pre-gyp https download [canvas] Success: "/home/dzy/Project/face-api.js/node_modules/canvas/build/Release/canvas.node" is installed via remote npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 442 packages from 783 contributors and audited 1741 packages in 170.919s

10 packages are looking for funding run npm fund for details

found 8 low severity vulnerabilities run npm audit fix to fix them, or npm audit for details

[email protected] build /home/dzy/Project/face-api.js rm -rf ./build && rm -rf ./dist && npm run rollup && npm run rollup-min && npm run tsc && npm run tsc-es6

[email protected] rollup /home/dzy/Project/face-api.js rollup -c rollup.config.js

loaded rollup.config.js with warnings (!) Unused external imports default imported from external module 'path' but never used

src/index.ts → dist/face-api.js... created dist/face-api.js in 10.3s

[email protected] rollup-min /home/dzy/Project/face-api.js rollup -c rollup.config.js --environment minify:true

loaded rollup.config.js with warnings (!) Unused external imports default imported from external module 'path' but never used

src/index.ts → dist/face-api.min.js... created dist/face-api.min.js in 14.5s

[email protected] tsc /home/dzy/Project/face-api.js tsc

[email protected] tsc-es6 /home/dzy/Project/face-api.js tsc --p tsconfig.es6.json And tsc faceDetection.ts, get same error.

homedawn avatar Apr 29 '20 01:04 homedawn

Worked fine for me:

  • npm install & npm run-script build (the remove commands for the directories fail on windows, remove them from package.json in the face-api.js\package.json file)
  • run npm install in examples-nodejs
  • running tsc faceDetection.ts fails with an error (duplicate librarydefinition WebGL2 or something)
  • instead tsc --skipLibCheck faceDetection.ts and things run fine.

ronaldkuip avatar May 05 '20 15:05 ronaldkuip

@ronaldkuip I am also that add '--skipLibCheck' , but is fine?

homedawn avatar May 06 '20 00:05 homedawn

ts-node faceDetection.ts should run in examples-nodejs directory.

Tsc -skipLibCheck.ts creates faceDetection.js

node faceDetection.js then runs fine too.

Van: homedawn [email protected] Verzonden: woensdag 6 mei 2020 02:52 Aan: justadudewhohacks/face-api.js [email protected] CC: ronaldkuip [email protected]; Mention [email protected] Onderwerp: Re: [justadudewhohacks/face-api.js] node-js examples not compiling (#491)

@ronaldkuiphttps://github.com/ronaldkuip I am also that add '--skipLibCheck' , but is fine?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/justadudewhohacks/face-api.js/issues/491#issuecomment-624383634, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACV4DRCPYR5R362D6IYE3JDRQCYDJANCNFSM4JUN6MOA.

ronaldkuip avatar May 06 '20 06:05 ronaldkuip

Hi everyone getting this error while running examples-nodejs using command => tsc faceDetection.ts

commons/env.ts:5:26** - error TS2307: Cannot find module 'face-api.js' or its corresponding type declarations.

5 import * as faceapi from 'face-api.js'; ~~~~~~~~~~~~~

commons/faceDetection.ts:1:26 - error TS2307: Cannot find module 'face-api.js' or its corresponding type declarations.

1 import * as faceapi from 'face-api.js'; ~~~~~~~~~~~~~

faceDetection.ts:1:26 - error TS2307: Cannot find module 'face-api.js' or its corresponding type declarations.

1 import * as faceapi from 'face-api.js'; ~~~~~~~~~~~~~

node_modules/@tensorflow/tfjs-node/dist/nodejs_kernel_backend.d.ts:61:5 - error TS2416: Property 'stridedSlice' in type 'NodeJSKernelBackend' is not assignable to the same property in base type 'KernelBackend'. Type '<T extends Tensor<Rank>>(x: T, begin: number[], end: number[], strides: number[], beginMask: number, endMask: number, ellipsisMask: number, newAxisMask: number, shrinkAxisMask: number) => T' is not assignable to type '<T extends Tensor<Rank>>(x: T, begin: number[], end: number[], strides: number[]) => T'.

61 stridedSlice<T extends Tensor>(x: T, begin: number[], end: number[], strides: number[], beginMask: number, endMask: number, ellipsisMask: number, newAxisMask: number, shrinkAxisMask: number): T; ~~~~~~~~~~~~

node_modules/@tensorflow/tfjs-node/dist/nodejs_kernel_backend.d.ts:64:5 - error TS2416: Property 'fusedBatchMatMul' in type 'NodeJSKernelBackend' is not assignable to the same property in base type 'KernelBackend'. Type '(a: Tensor3D, b: Tensor3D, transposeA: boolean, transposeB: boolean, bias?: Tensor<Rank>, activation?: Activation) => Tensor3D' is not assignable to type '({ a, b, transposeA, transposeB, bias, activation, preluActivationWeights }: FusedBatchMatMulConfig) => Tensor3D'.

64 fusedBatchMatMul(a: Tensor3D, b: Tensor3D, transposeA: boolean, transposeB: boolean, bias?: Tensor, activation?: Activation): Tensor3D; ~~~~~~~~~~~~~~~~

node_modules/@types/webgl2/index.d.ts:582:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'WebGL2RenderingContext' must be of type '{ new (): WebGL2RenderingContext; prototype: WebGL2RenderingContext; readonly ACTIVE_ATTRIBUTES: number; readonly ACTIVE_TEXTURE: number; ... 556 more ...; readonly WAIT_FAILED: number; }', but here has type '{ new (): WebGL2RenderingContext; prototype: WebGL2RenderingContext; readonly ACTIVE_ATTRIBUTES: number; readonly ACTIVE_TEXTURE: number; ... 557 more ...; readonly MAX_CLIENT_WAIT_TIMEOUT_WEBGL: number; }'.

582 declare var WebGL2RenderingContext: { ~~~~~~~~~~~~~~~~~~~~~~

../../../../../AppData/Roaming/npm/node_modules/typescript/lib/lib.dom.d.ts:16394:13 16394 declare var WebGL2RenderingContext: { ~~~~~~~~~~~~~~~~~~~~~~ 'WebGL2RenderingContext' was also declared here.

Found 6 errors.

shahzeb61518 avatar Feb 26 '21 14:02 shahzeb61518

Is there a way to implement face-api with webRTC where webRTC is running on browser and face-api on server I am trying it but couldn't find a way to do so because my nodejs server cannot access DOM elements which is a requirement to implement face-api

AadiRana911 avatar Jan 24 '22 12:01 AadiRana911

same here

PeterPanTheGenius avatar Apr 08 '23 05:04 PeterPanTheGenius

The solution was to first run

npm i && npm run-script build

in the root directory before trying to run the examples.

sl3@luciano-GrIA:~/face-api.js/examples/examples-nodejs$ npm i && npm run-script build

up to date, audited 3 packages in 1s

found 0 vulnerabilities npm ERR! Missing script: "build" npm ERR! npm ERR! To see a list of scripts, run: npm ERR! npm run

npm ERR! A complete log of this run can be found in: npm ERR! /home/sl3/.npm/_logs/2023-08-30T18_16_50_833Z-debug-0.log

LouisSiuLungLau avatar Aug 30 '23 18:08 LouisSiuLungLau