3

I use @tensorflow/tfjs-node package for face-api.js package to speed up things (as they said) that is my code:

// import nodejs bindings to native tensorflow,
// not required, but will speed up things drastically (python required)

require('@tensorflow/tfjs-node');


// implements nodejs wrappers for HTMLCanvasElement, HTMLImageElement, ImageData
const { loadImage,Canvas, Image, ImageData } = require('canvas')

const faceapi = require('face-api.js');

// patch nodejs environment, we need to provide an implementation of
// HTMLCanvasElement and HTMLImageElement
faceapi.env.monkeyPatch({ Canvas, Image, ImageData })


// patch nodejs environment, we need to provide an implementation of
// HTMLCanvasElement and HTMLImageElement
faceapi.env.monkeyPatch({ Canvas, Image, ImageData })

Promise.all([
 faceapi.nets.ssdMobilenetv1.loadFromDisk('./models'),
 faceapi.nets.faceRecognitionNet.loadFromDisk('./models'),
 faceapi.nets.faceLandmark68Net.loadFromDisk('./models')
])
.then(async () => {
    const image1= await loadImage("https://enigmatic-waters-76106.herokuapp.com/1.jpeg")
    const image2= await loadImage("https://enigmatic-waters-76106.herokuapp.com/8.jpeg")
    const result = await faceapi.detectSingleFace(image1).withFaceLandmarks()
   .withFaceDescriptor()

    const singleResult = await faceapi
    .detectSingleFace(image2)
    .withFaceLandmarks()
    .withFaceDescriptor()
       const labeledDescriptors = [
          new faceapi.LabeledFaceDescriptors(
                'saied',
            [result.descriptor]
          )
        ]
            const faceMatcher = new faceapi.FaceMatcher(labeledDescriptors)
    const bestMatch = faceMatcher.findBestMatch(singleResult.descriptor)
    console.log(labeledDescriptors[0].descriptors)

})

and when I run the code I get this error

TypeError: forwardFunc_1 is not a function at G:\test\node_modules@tensorflow\tfjs-core\dist\tf-core.node.js:3166:55 at G:\test\node_modules@tensorflow\tfjs-core\dist\tf-core.node.js:2989:22 at Engine.scopedRun (G:\test\node_modules@tensorflow\tfjs-core\dist\tf-core.node.js:2999:23) at Engine.tidy (G:\test\node_modules@tensorflow\tfjs-core\dist\tf-core.node.js:2988:21) at kernelFunc (G:\test\node_modules@tensorflow\tfjs-core\dist\tf-core.node.js:3166:29) at G:\test\node_modules@tensorflow\tfjs-core\dist\tf-core.node.js:3187:27 at Engine.scopedRun (G:\test\node_modules@tensorflow\tfjs-core\dist\tf-core.node.js:2999:23) at Engine.runKernelFunc (G:\test\node_modules@tensorflow\tfjs-core\dist\tf-core.node.js:3183:14) at mul_ (G:\test\node_modules\face-api.js\node_modules@tensorflow\tfjs-core\dist\ops\binary_ops.js:327:28) at Object.mul (G:\test\node_modules\face-api.js\node_modules@tensorflow\tfjs-core\dist\ops\operation.js:46: 29) (Use node --trace-warnings ... to show where the warning was created) (node:3496) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throw ing inside of an async function without a catch block, or by rejecting a promise which was not handled with .cat ch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:3496) [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

When I delete require('@tensorflow/tfjs-node'); the code runs perfectly, but I need to import @tensorflow/tfjs-node to make the process faster.

Below are my current setup versions: node: v14.15.4

npm: 6.14.10

@tensorflow/tfjs-node: v3.0.0 Python 2.7.15 (required for @tensorflow/tfjs-node)

face-api.js: v0.22.2

7
  • so the error is not coming from your code ? Commented Jan 29, 2021 at 15:44
  • as i said if deleted this (require('@tensorflow/tfjs-node');) the code will work but giving me a hint tha i should import @tensorflow/tfjs-node' in my code to make the proccess faster Commented Jan 29, 2021 at 15:51
  • i implicitly meant : "how can we debug just a simple 'import' ? ", is the same error presents i you only import @tensorflow/tfjs-node ? Commented Jan 29, 2021 at 15:53
  • @SimonDehaut that is what makes me so confused that simple line require('@tensorflow/tfjs-node') what makes the error Commented Jan 29, 2021 at 15:57
  • and sorry for my bad english :) Commented Jan 29, 2021 at 15:59

2 Answers 2

2

As explained in this github issue

The version of face-api.js you are using is not compatible with tfjs 2.0+ or 3.0+, only obsolete 1.x. Why it worked before you added tfjs-node? because face-api.js actually includes bundled version of tfjs-core 1.x. Once you added tfjs-node, it overrode global tf namespace, but its a much newer version and not compatible.

You must install obsolete tfjs-node 1.x OR follow the pointers they give to use a newer port of face-api.js that supports TF 2.0.

Sign up to request clarification or add additional context in comments.

Comments

0

If you're using face-api.js version 0.22.2, it requires TensorFlow.js version 1.x. Recent versions of TensorFlow.js (3.x or higher) are not compatible with face-api.js.

To resolve this, you need to install TensorFlow.js version 1.7.4 by running the following command:

npm install @tensorflow/[email protected]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.