导入“@tensorflow/tfjs-node”模块时出现错误。我的问题类似于Cannot import @tensorflow/tfjs-node in nodejs中提到的问题
TensorFlow.js 版本 - 1.7.3
平台信息:Windows 8.1 Python 2.7.12 npm 6.14.4 节点 10.20.1
Package.json is as follows:
{
"name": "tf",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@tensorflow/tfjs": "^1.7.3",
"@tensorflow/tfjs-node": "^1.7.3"
}
}
脚本很简单,如下所示:
console.log("HI");
const tf= require('@tensorflow/tfjs');
require('@tensorflow/tfjs-node');
// Train a simple model:
const model = tf.sequential();
model.add(tf.layers.dense({units: 100, activation: 'relu', inputShape: [10]}));
model.add(tf.layers.dense({units: 1, activation: 'linear'}));
model.compile({optimizer: 'sgd', loss: 'meanSquaredError'});
const xs = tf.randomNormal([100, 10]);
const ys = tf.randomNormal([100, 1]);
model.fit(xs, ys, {
epochs: 100,
callbacks: {
onEpochEnd: (epoch, log) => console.log(`Epoch ${epoch}: loss = ${log.loss}`),
}
});
尽管该文件已经存在于路径 C:\Program Files\nodejs\tf\node_modules@tensorflow\tfjs-node\lib\napi-v5\tf js_binding.node 中,但请参阅下图以供参考。