face-api.js
face-api.js copied to clipboard
node-js examples not compiling
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?
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)
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.
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 (
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.
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": "../../"
}
}
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';
Same scenario, and same results as @sbocconi.
node --version: 12.4.0 tsc --version: 3.7.4
@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?
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
The solution was to first run
npm i && npm run-script build
in the root directory before trying to run the examples.
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
when I do "npm i" in console.
The solution was to first run
npm i && npm run-script buildin 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.
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 I am also that add '--skipLibCheck' , but is fine?
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.
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.
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
same here
The solution was to first run
npm i && npm run-script buildin 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