Running tensorflow-core in node js

  1. To avoid the large size of tfjs (140MB),
  2. since we do not need the layers api,
  3. we want to install tfjs-core which is just 30MB and then get the cpu-backend.

However, would this run at the same speed than tfjs-node ? If not I presume it’s because of the C bindings, but can these be imported separately ?

Hi @Mah_Neh ,

No, it would not run at the same speed as tfjs-node. There are a few reasons for this:

  1. tfjs-node uses native C++ bindings to the TensorFlow C library, which provides significant performance benefits.
  2. The CPU backend that comes with tfjs-core is implemented in JavaScript, which is generally slower for numerical computations compared to native C++ code.

Yes, the C bindings can be imported separately, but it’s not as straightforward as just importing another JavaScript module. The C bindings are part of what makes tfjs-node fast.

Use @tensorflow/tfjs-node-gpu or @tensorflow/tfjs-node: These packages include the C++ bindings and will give you the best performance .

Hope this helps ,

Thank You .