tfjs
tfjs copied to clipboard
Cannot import TFJS-Node
Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): I am using the default install of Tfjs-Node
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 11 Pro
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: No
- TensorFlow.js installed from (npm or script link): NPM
- TensorFlow.js version (use command below): @tensorflow/[email protected]
- Browser version: Not browser.
- Tensorflow.js Converter Version: Not using.
Describe the current behavior Whenever I require("@tensorflow/tfjs-node") in any javascript script I get this error. I can successfully build tfjs-node, but I cannot run it.
Describe the expected behavior For it to successfully require tensorflow and nothing to happen.
Standalone code to reproduce the issue
const tf = require('@tensorflow/tfjs-node');
Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/CodePen/any notebook. I'm not sure, its definitely something related to my system, but I have all of the dependencies, other things from other problems such as AVX enabled with Intel CPU, I have all Cuda SDKs, I have python 3.8.1.
Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full
PS C:\Users\jwwww\programming\NodeAI\AI> node .\index.js
node:internal/modules/cjs/loader:1473
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: The specified module could not be found.
\\?\C:\Users\jwwww\programming\NodeAI\AI\node_modules\@tensorflow\tfjs-node\lib\napi-v8\tfjs_binding.node
at Module._extensions..node (node:internal/modules/cjs/loader:1473:18)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (C:\Users\jwwww\programming\NodeAI\AI\node_modules\@tensorflow\tfjs-node\dist\index.js:72:16)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12) {
code: 'ERR_DLOPEN_FAILED'
}
Node.js v20.11.0
This is the entire error.
Hi, @DevInsilicon
I apologize for the delay in responding, following the instructions mentioned in my https://github.com/tensorflow/tfjs/issues/8081#issuecomment-1827814656 with these Node.js versions Node.js v19.9.0 and Node.js v18.16.1 it should work with Python version 3.x and less than Python version 3.12.x (e.g 3.11.x,3.10.x or 3.9.x) and at the moment it's not working as expected with Node.js v20.11.0
I believe you're following these official documentation Ref-1, Ref-2 and node-gyp - Node.js native addon build tool for Windows
In general you'll have to follow below steps to install @tensorflow/tfjs-node on Windows system:
- Edit the path user or system variable, ensure that the path to python is added to the path variable.
- Install Visual Studio community edition with desktop development with C++ Link
- Install visual studio build tools with the help of Visual Studio Installer
- Ensure that node-gyp is available:
npm install -g node-gyp - Install tfjs-node:
npm install @tensorflow/tfjs-node
tfjs-node requires AVX processors and tfjs-node library uses AVX instructions to improve the performance of its operations. If your CPU does not support AVX, as far I know you will not be able to use tfjs-node if I'm not wrong so to check AVX support please follow below steps
- Right-click on the Start button and select "System Information."
- Expand the "Processor" category in the left-hand pane.
- Look for "Instruction Set" or "Extended Instructions" in the right-hand pane. If AVX is supported, you should see it listed there (e.g., "AVX2").
NOTE : If the above workaround does not work please try using your mobile phone's hotspot to connect your computer to the internet. This alternative connection might fix the installation issue.
Please let us know after trying the above steps is it resolving your issue or not ? if not please help us with the error log to investigate this issue further
Thank you for your cooperation and patience.
Sorry for my late response, Thank you very much. This indeed fixed the issue. But when looking in my System Informations program I don't have a category called Processor. I'll link an image, but I have AVX everything enabled in my bios, and TF is working so I guess it is enabled successfully. Thanks a lot!
Edit: 10 minutes later I am getting this when running my Tensorflow
2024-05-25 19:43:37.878911: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Hi, @DevInsilicon
Good to hear that you're able to install tfjs-node successfully on your system and above message is just suggestion If your code is running well without issues, you can likely ignore that message. AVX2 might already be sufficient for your needs.
If you're comfortable with compiling from source and want to potentially squeeze out more performance, you can rebuild TensorFlow with compiler flags that enable more CPU instructions. This process can be complex and requires specific knowledge of your system and compiler. Refer to TensorFlow's build instructions for details on enabling specific CPU instructions from here which is optional to get the most optimal TensorFlow build that can take advantage of your specific hardware (AVX512, MKL-DNN), you can build the libtensorflow library from source.
If this issue is resolved, you may close this issue at your convenience. For further assistance, please feel free to create new issue and we'll be happy to help you further.
Thank you for your cooperation and patience.
Hi, @DevInsilicon
We've not got any confirmation from your end so I'm closing this issue now from my end and if you need any further assistance please feel free to create new issue and we're happy to help further
Thank you for your cooperation and patience.