我试图让一个节点服务器在树莓派上运行TensorFlow模型我在Ubuntu上做了一个简单的测试,它有效,但它给了我一个错误的树莓
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: /home/pi/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.<anonymous> (/home/pi/node_modules/@tensorflow/tfjs-node/dist/index.js:49:11)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29)
at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)
at async handleMainPromise (internal/modules/run_main.js:59:12)
这是我要运行的代码
path='file:///home/sa2/work/models/js_model/model.json';
const model = await tf.loadLayersModel(path);
const sum=model.summary();
const test=[]
const prediction = tf.tidy(()=>{
// create a tensor from an input
const ty = tf.tensor(test).expandDims();
;
// insert a dimension into the tensor's shape
//const inputTensor = tensor.expandDims();
//execute the infernce for the input tensors
const tensor = model.predict(ty) ;
return tensor.dataSync();
})
export const per = prediction;
console.log(sum);
console.log(per) ;
我试过使用
npm rebuild @tensorflow/tfjs-node --build-addon-from-source
但是不工作
这可能是在树莓派的ARM芯片上运行tfjs时出现的问题。尝试使用引用的命令为RPi重新构建库。
npm rebuild @tensorflow/tfjs-node --build-addon-from-source