question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: forwardFunc_1 is not a function

See original GitHub issue

I am new to face-api.js/Tensorflow.js so I might be overlooking something very obvious.

I installed face-api.js and Tensorflow using:

npm i face-api.js canvas @tensorflow/tfjs-node

Everything worked fine until I added require('@tensorflow/tfjs-node'); at the top of the code.

Here’s the full code:

require('@tensorflow/tfjs-node');
const { loadImage,Canvas, Image, ImageData,createCanvas } = require('canvas')
const fs= require('fs');
const faceapi = require('face-api.js');
faceapi.env.monkeyPatch({ Canvas, Image, ImageData,createCanvas });
Promise.all([
   faceapi.nets.ssdMobilenetv1.loadFromDisk('models'),
   faceapi.nets.faceRecognitionNet.loadFromDisk('models'),
   faceapi.nets.faceLandmark68Net.loadFromDisk('models')
   ])
.then(async () => {
    data={};
    const image1= await loadImage("test.png");
    const result = await faceapi.detectSingleFace(image1).withFaceLandmarks().withFaceDescriptor();
    data["test.png"]={};
    let left=result.landmarks.getLeftEye();
    data["test.png"].left=left;
    let right=result.landmarks.getRightEye();
    data["test.png"].right=right;
    console.log(data);
});

The code would have worked perfectly fine, had require('@tensorflow/tfjs-node'); not been added. The error I get when I run the full code is:

2021-03-13 09:27:30.500937: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
cpu backend was already registered. Reusing existing backend factory.
Platform node has already been set. Overwriting the platform with [object Object].
(node:1428) UnhandledPromiseRejectionWarning: TypeError: forwardFunc_1 is not a function
    at FolderName\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:3179:55
    at FolderName\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:3002:22
    at Engine.scopedRun (FolderName\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:3012:23)
    at Engine.tidy (FolderName\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:3001:21)
    at kernelFunc (FolderName\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:3179:29)
    at FolderName\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:3200:27
    at Engine.scopedRun (FolderName\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:3012:23)
    at Engine.runKernelFunc (FolderName\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:3196:14)
    at mul_ (FolderName\node_modules\face-api.js\node_modules\@tensorflow\tfjs-core\dist\ops\binary_ops.js:327:28)
    at Object.mul (FolderName\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:1428) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a prom
ise which was not handled with .catch(). 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:1428) [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-z
ero exit code.

Here’s the list of packages installed: list.txt.

I have uninstalled/re-installed the node modules multiple times. Tried using the previous versions of “@tensorflow/tfjs-node”.

I am using Node.js v14.16.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

12reactions
vladmandiccommented, Mar 14, 2021

this version of face-api.js 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.

now, you can either install obsolete tfjs-node 1.x or use newer port of face-api.js (changes to make it compatible are pretty significant):
https://github.com/vladmandic/face-api
https://www.npmjs.com/package/@vladmandic/face-api

4reactions
vladmandiccommented, Mar 25, 2021

Thanks for the fast reply. I think the docs need to be updated.

Yes, but if the author is no longer maintaining the package, how can they be updated?

is this the fork you are referring to https://github.com/vladmandic/face-api it doesn’t say forked from this repo. So i am little confused.

It says that explicitly in the readme:

Note

This is updated face-api.js with latest available TensorFlow/JS as the original is not compatible with tfjs 2.0+.
Forked from face-api.js version 0.22.2 which was released on March 22nd, 2020

Currently based on TensorFlow/JS 3.3.0

Why? I needed Face-API that does not cause version conflict with newer versions of TensorFlow
And since original Face-API was open-source, I’ve released this version as well

Changes ended up being too large for a simple pull request
and it ended up being a full-fledged version on its own

Plus many features were added since original inception


Differences

Compared to face-api.js version 0.22.2:

  • Compatible with TensorFlow/JS 2.0+ & 3.0+
  • Compatible with WebGL, CPU and WASM TFJS Browser backends
  • Compatible with both tfjs-node and tfjs-node-gpu TFJS NodeJS backends
  • Updated all type castings for TypeScript type checking to TypeScript 4.2
  • Switched bundling from UMD to ESM + CommonJS with fallback to IIFE Resulting code is optimized per-platform instead of being universal Fully tree shakable when imported as an ESM module Browser bundle process uses ESBuild instead of Rollup
  • Typescript build process now targets ES2018 and instead of dual ES5/ES6 Resulting code is clean ES2018 JavaScript without polyfills
  • Removed old tests, docs, examples
  • Removed old package dependencies (karma, jasmine, babel, etc.)
  • Updated all package dependencies
  • Updated TensorFlow/JS dependencies since backends were removed from @tensorflow/tfjs-core
  • Updated mobileNetv1 model due to batchNorm() dependency
  • Added version class that returns JSON object with version of FaceAPI as well as linked TFJS
  • Added test/dev built-in HTTP & HTTPS Web server
  • Removed mtcnn and tinyYolov2 models as they were non-functional in latest public version of Face-API Which means valid models are tinyFaceDetector and mobileNetv1 If there is a demand, I can re-implement them back.
  • Added face angle calculations that returns roll, yaw and pitch
  • Added typdoc automatic API specification generation during build
  • Added changelog automatic generation during build

Credits

Read more comments on GitHub >

github_iconTop Results From Across the Web

forwardFunc_1 is not a function - TensorFlow Forum
Hey all, starting off this is my first time on the forum and I have no clue if this is the correct place...
Read more >
TypeError: forwardFunc is not a function · Issue #2329 - GitHub
Hi! I dont know does this problem apply to you, but it seems to be. If it is not, im sorry. So here...
Read more >
TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >
TypeError: $(...). is not a function - Stack Overflow
I'm trying to track down an error TypeError: $(...).clientSideCaptcha is not a function ...
Read more >
Uncaught TypeError | Is Not A Function | Solution - YouTube
Have you encountered an error like:- Uncaught TypeError - Some selector is not a function - jQuery is not a function - owlCarousel...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found