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.

@tensorflow/tfjs-node is not correctly recognised when running examples

See original GitHub issue

I am trying to run the NodeJS examples. The examples run, but seem to not properly utilize the TensorFlow C++ binding.

Steps to reproduce

cd face-api.js/examples/examples-nodejs
npm i

tsc faceDetection.ts
node faceDetection.js

Expected outcome:

Examples runs without warnings.

Actual outcome:

============================
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.
============================

Environment

Node: v11.14.0 face-api.js: 0.19.0 @tensorflow/tfjs-node: 1.0.2

Additional Informations

I tried running the examples with older versions to exclude the possibility of a problem with my setup. I managed to run the examples for face-api.js versions 0.17.0 and 0.17.1 with face-api.js picking up the TensorFlow bindings correctly.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
dmohnscommented, May 9, 2019

face-api.js does not use tfjs-node at all. face-api.js is depending on tfjs-core. So in order to run face-api.js with the tfjs-node backend, you have to install a tfjs-node version, which is compatible with the tfjs-core version that face-api.js uses.

Ok, I think I got it now. However, this is valuable information and might be important for newcomers that try to get started with face-api.js in a Node.js environment.

Suggestion

Should we …

  1. pin the tfjs-node version in the Node.js example, such that the example will run correctly on a freshly cloned repo and
  2. add a small comment somewhere in the Node.js example explaining that a compatible tfjs-node version is needed?

If no objections, I am happy to send PR for the above mentioned.

0reactions
dmohnscommented, May 8, 2019

Sorry for the confusion.

I Time Machine restored my repo to the state I had when I opened this issue. Now, I get

{ 'tfjs-core': '1.1.0',
  'tfjs-data': '1.1.0',
  'tfjs-layers': '1.1.0',
  'tfjs-converter': '1.1.0',
  tfjs: '1.1.0',
  'tfjs-node': '1.1.0' }

============================
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.
============================

done, saved results to out/faceDetection.jpg

Aha, so I actually used @tensorflow/tfjs-node@1.1.0, not @tensorflow/tfjs-node@1.0.2 as said in OP. Apologies! So, it looks like the problem arises when using @tensorflow/tfjs-node>=1.1.0.

Indeed after

@@ -2,7 +2,7 @@
   "author": "justadudewhohacks",
   "license": "MIT",
   "dependencies": {
-    "@tensorflow/tfjs-node": "^1.0.2",
+    "@tensorflow/tfjs-node": "~1.0.2",
     "canvas": "^2.0.1",
     "face-api.js": "../../"
   }

and

npm install

It now runs correctly 🎉

{ 'tfjs-core': '1.0.4',
  'tfjs-data': '1.0.4',
  'tfjs-layers': '1.0.4',
  'tfjs-converter': '1.0.4',
  tfjs: '1.0.4',
  'tfjs-node': '1.0.3' }
cpu backend was already registered. Reusing existing backend
done, saved results to out/faceDetection.jpg
Read more comments on GitHub >

github_iconTop Results From Across the Web

@tensorflow/tfjs-node - npm
Start using @tensorflow/tfjs-node in your project by running `npm i ... Machines with Python 3.x will not install the bindings properly.
Read more >
node.js - Tensorflow tfjs not working on my OS setup anymore
When I try running this simple tfjs-node image recognition example (https://github.com/tejas77/node-image-classification), it does not work.
Read more >
TensorFlow.js in Node
TensorFlow on the CPU uses hardware acceleration to accelerate the linear algebra computation under the hood. This package will work on Linux, ...
Read more >
Tensorflow.js Crash-Course - Gilbert Tanner
Use TensorFlow.js to define, train, and run models entirely in the browser using ... yarn add @tensorflow/tfjs-node or npm install @tensorflow/tfjs-node.
Read more >
Simple Image Recognition Backend with Express + TF - Medium
The Step-by-Step Guide to Apply TensorFlow model built in Python to Node. ... You can check whether those are ready or not by...
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