Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with running the project #8490

Open
GaUrAv001001 opened this issue Jan 11, 2025 · 12 comments
Open

issue with running the project #8490

GaUrAv001001 opened this issue Jan 11, 2025 · 12 comments
Assignees

Comments

@GaUrAv001001
Copy link

System information
System: windows
"@tensorflow/tfjs": "^4.22.0",
"@tensorflow/tfjs-node": "^4.22.0",


when i try to run the project i am getting this error:

node index.js
node:internal/modules/cjs/loader:1460
return process.dlopen(module, path.toNamespacedPath(filename));
^

Error: The specified module could not be found.
\?\C:\Users\Admin\OneDrive\Documents\ReactJS\tensorflow model\node_modules@tensorflow\tfjs-node\lib\napi-v8\tfjs_binding.node
at Module._extensions..node (node:internal/modules/cjs/loader:1460:18)
at Module.load (node:internal/modules/cjs/loader:1203:32)
at Module._load (node:internal/modules/cjs/loader:1019:12)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:177:18)
at Object. (C:\Users\Admin\OneDrive\Documents\ReactJS\tensorflow model\node_modules@tensorflow\tfjs-node\dist\index.js:72:16)
at Module._compile (node:internal/modules/cjs/loader:1364:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
at Module.load (node:internal/modules/cjs/loader:1203:32)
at Module._load (node:internal/modules/cjs/loader:1019:12) {
code: 'ERR_DLOPEN_FAILED'
}
Node.js v18.20.5


I Tried to change the version of node js and python still not working.
node js : v18.20.5
Python : 3.11.3

here is the code:

index.js: import express from 'express'
import cors from 'cors'
import ImageClassifier from './ImageClassifier.js';

(async () => {
const classifier = new ImageClassifier();

// Train the model
const datasetPath = path.join(process.cwd(), './dataset');
await classifier.train(datasetPath, 5); // Adjust epochs if needed

// Save the trained model
const modelPath = path.join(process.cwd(), './model');
await classifier.saveModel(modelPath);
                                                        
// Load the saved model and classify an image
await classifier.loadModel(modelPath);
const testImagePath = path.join(process.cwd(), './testimage/testimg.png');
const result = await classifier.classify(testImagePath);

console.log('Prediction:', result);

})();
ImageClassification.js:

import express from 'express'
import cors from 'cors'
import ImageClassifier from './ImageClassifier.js';

(async () => {
const classifier = new ImageClassifier();

// Train the model
const datasetPath = path.join(process.cwd(), './dataset');
await classifier.train(datasetPath, 5); // Adjust epochs if needed

// Save the trained model
const modelPath = path.join(process.cwd(), './model');
await classifier.saveModel(modelPath);
                                                        
// Load the saved model and classify an image
await classifier.loadModel(modelPath);
const testImagePath = path.join(process.cwd(), './testimage/testimg.png');
const result = await classifier.classify(testImagePath);

console.log('Prediction:', result);

})();

@GaUrAv001001
Copy link
Author

@shmishra99

@shmishra99 shmishra99 self-assigned this Jan 13, 2025
@shmishra99
Copy link
Contributor

Hi @GaUrAv001001 ,

I noticed you are using nodejs v18.20.5. Could you please try using Python version 3.11.x and Node.js v19.9.x or 20.15.x? After making these changes, please delete the node_modules folder from your project and run npm install again.

Please let me know if this resolves the issue. Thank you!"

@Roman233
Copy link

I was getting the same error and after doing what you said the error still exists so it didn't work.

@shmishra99
Copy link
Contributor

Hi @Roman233,

It must resolve your issue. However, if you are still facing the issue even after installing the compatible dependencies, you can manually copy the file from node_modules/@tensorflow/tfjs-node/deps/lib/tensorflow.dll to node_modules/@tensorflow/tfjs-node/lib/napi-v8/. This should resolve your issue.

Let me know if it helps. Thank you!!

@Igor5005
Copy link

YES! I have exactly the same error! I haven’t been able to do anything with her for a week now! Installed, reinstalled everything, node versions, visual studio, python, copied files, NOTHING! I currently have node v18.20.5, [email protected]
@tensorflow/[email protected]

@shmishra99
Copy link
Contributor

@Igor5005 , Please try installing the latest @tensorflow/[email protected] and applying the configuration mentioned in my previous comment. If still you encounter an error related to the missing tensorflow.dll file, manually copy the file to the node_modules/@tensorflow/tfjs-node/lib/napi-v8/ directory.

@Igor5005
Copy link

I tried to do as you recommended. Currently:G:\TensorFlow>node -v v18.20.5. G:\TensorFlow>python --version Python 3.11.0 G:\TensorFlow>node-gyp --version v11.0.0
G:\TensorFlow>cl Microsoft (R) C/C++ optimizing compiler version 19.42.34436 для x86. G:\TensorFlow>npm list @tensorflow/tfjs
[email protected] G:\TensorFlow -- @tensorflow/[email protected] -- @tensorflow/[email protected] . My Windows: Windows10 PRO, I copied the tensorflow.dll file from the G:\TensorFlow\node_modules@tensorflow\tfjs-node\deps\lib folder to the G:\TensorFlow\node_modules@tensorflow\tfjs-node folder \lib\napi-v8

The file I tried to run:
const tf = require('@tensorflow/tfjs-node');
console.log(tf.version.tfjs);
const tensor = tf.tensor([1, 2, 3, 4]);
console.log('Tensor:', tensor.toString());

Result: [Running] node "g:\TensorFlow\index.js"
g:\TensorFlow\node_modules@tensorflow\tfjs-node\dist\index.js:61
throw new Error("The Node.js native addon module (tfjs_binding.node) can not " +
^

Error: The Node.js native addon module (tfjs_binding.node) can not be found at path: g:\TensorFlow\node_modules@tensorflow\tfjs-node\lib\napi-v8\tfjs_binding.node.
Please run command 'npm rebuild @tensorflow/tfjs-node --build-addon-from-source' to rebuild the native addon module.
If you have problem with building the addon module, please check https://github.com/tensorflow/tfjs/blob/master/tfjs-node/WINDOWS_TROUBLESHOOTING.md or file an issue.
at Object. (g:\TensorFlow\node_modules@tensorflow\tfjs-node\dist\index.js:61:11)
at Module._compile (node:internal/modules/cjs/loader:1364:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
at Module.load (node:internal/modules/cjs/loader:1203:32)
at Module._load (node:internal/modules/cjs/loader:1019:12)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:177:18)
at Object. (g:\TensorFlow\index.js:1:12)
at Module._compile (node:internal/modules/cjs/loader:1364:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)

Node.js v18.20.5

[Done] exited with code=1 in 2.191 seconds

@Igor5005
Copy link

I forgot to indicate the video card, it's quite old, nvidia geforce 8600GT

@shmishra99
Copy link
Contributor

@Igor5005 Run command npm rebuild @tensorflow/tfjs-node --build-from-source. It must work.

@shmishra99
Copy link
Contributor

@GaUrAv001001, Please also verify if this workaround is also working in your case.

@Igor5005
Copy link

I did it. same error...

@atellmer
Copy link

you can manually copy the file from node_modules/@tensorflow/tfjs-node/deps/lib/tensorflow.dll to node_modules/@tensorflow/tfjs-node/lib/napi-v8/.

worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants